Skip to content

Commit 95eec14

Browse files
committed
fixed playlist slicing
fixes #519
1 parent 77539db commit 95eec14

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

engine/impl/PlaylistImpl.php

+29-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Zookeeper Online
44
*
55
* @author Jim Mason <jmason@ibinx.com>
6-
* @copyright Copyright (C) 1997-2024 Jim Mason <jmason@ibinx.com>
6+
* @copyright Copyright (C) 1997-2025 Jim Mason <jmason@ibinx.com>
77
* @link https://zookeeper.ibinx.com/
88
* @license GPL-3.0
99
*
@@ -200,6 +200,8 @@ public function insertPlaylist($user, $date, $time, $description, $airname, $aut
200200
}
201201

202202
public function updatePlaylist($playlist, $date, $time, $description, $airname, $deleteTracksPastEnd=0) {
203+
$this->adviseLock($playlist);
204+
203205
$query = "SELECT showdate, showtime FROM lists WHERE id = ?";
204206
$stmt = $this->prepare($query);
205207
$stmt->bindValue(1, $playlist);
@@ -275,6 +277,28 @@ public function updatePlaylist($playlist, $date, $time, $description, $airname,
275277
$stmt->bindValue(2, $seq);
276278
$stmt->execute();
277279
}
280+
281+
// delete tracks that preceed new time range
282+
$query = "SELECT id FROM tracks " .
283+
"WHERE list = ? AND created < ? " .
284+
"ORDER BY seq DESC, id DESC LIMIT 1";
285+
$stmt = $this->prepare($query);
286+
$stmt->bindValue(1, $playlist);
287+
$stmt->bindValue(2, $fromStamp->format(self::TIME_FORMAT_SQL));
288+
$start = $stmt->executeAndFetch();
289+
if($start && ($seq = $this->getSeq($playlist, $start['id']))) {
290+
$query = "DELETE FROM tracks WHERE list = ? AND seq <= ?";
291+
$stmt = $this->prepare($query);
292+
$stmt->bindValue(1, $playlist);
293+
$stmt->bindValue(2, $seq);
294+
$stmt->execute();
295+
296+
$query = "UPDATE tracks SET seq = seq - ? WHERE list = ?";
297+
$stmt = $this->prepare($query);
298+
$stmt->bindValue(1, $seq);
299+
$stmt->bindValue(2, $playlist);
300+
$stmt->execute();
301+
}
278302
} else {
279303
// allow spin timestamps within the grace period
280304
$fromStamp->modify(self::GRACE_START);
@@ -308,7 +332,10 @@ public function updatePlaylist($playlist, $date, $time, $description, $airname,
308332
$stmt->bindValue(5, $playlist);
309333
} else
310334
$stmt->bindValue(4, $playlist);
311-
return $stmt->execute();
335+
$result = $stmt->execute();
336+
337+
$this->adviseUnlock($playlist);
338+
return $result;
312339
}
313340

314341
protected function slicePlaylist($playlist, $time) {

js/playlists.pick.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ $().ready(function(){
622622
var oldTime = row.data('orig').attributes.time;
623623

624624
if(duration(newTime) < duration(oldTime)
625-
&& !confirm("Show has been shortened. Tracks past the end will be deleted.\n\nAre you sure you want to do this?"))
625+
&& !confirm("Show has been shortened. Tracks outside the new time will be deleted.\n\nAre you sure you want to do this?"))
626626
return;
627627

628628
var postData = {

0 commit comments

Comments
 (0)