CC-3174 : showbuilder

checking to make sure UI is up to date with db
This commit is contained in:
Naomi Aro 2012-02-16 19:46:14 +01:00
parent e1d5d6de73
commit b2d0565ec4
4 changed files with 103 additions and 57 deletions

View file

@ -768,4 +768,4 @@ class Application_Model_Playlist {
} // class Playlist } // class Playlist
class PlaylistNotFoundException extends Exception {} class PlaylistNotFoundException extends Exception {}
class OutDatedException extends Exception {} class PlaylistOutDatedException extends Exception {}

View file

@ -31,11 +31,16 @@ class Application_Model_Scheduler {
if ($type === "audioclip") { if ($type === "audioclip") {
$file = CcFilesQuery::create()->findPK($id, $this->con); $file = CcFilesQuery::create()->findPK($id, $this->con);
$data = $this->fileInfo; if (is_null($file) || !$file->getDbFileExists()) {
$data["id"] = $id; throw new Exception("A selected File does not exist!");
$data["cliplength"] = $file->getDbLength(); }
else {
$data = $this->fileInfo;
$data["id"] = $id;
$data["cliplength"] = $file->getDbLength();
$files[] = $data; $files[] = $data;
}
} }
else if ($type === "playlist") { else if ($type === "playlist") {
@ -44,17 +49,25 @@ class Application_Model_Scheduler {
->filterByDbPlaylistId($id) ->filterByDbPlaylistId($id)
->find($this->con); ->find($this->con);
if (is_null($contents)) {
throw new Exception("A selected Playlist does not exist!");
}
foreach ($contents as $plItem) { foreach ($contents as $plItem) {
$data = $this->fileInfo; $file = $plItem->getCcFiles($this->con);
$data["id"] = $plItem->getDbFileId(); if (isset($file) && $file->getDbFileExists()) {
$data["cliplength"] = $plItem->getDbCliplength();
$data["cuein"] = $plItem->getDbCuein();
$data["cueout"] = $plItem->getDbCueout();
$data["fadein"] = $plItem->getDbFadein();
$data["fadeout"] = $plItem->getDbFadeout();
$files[] = $data; $data = $this->fileInfo;
$data["id"] = $plItem->getDbFileId();
$data["cliplength"] = $plItem->getDbCliplength();
$data["cuein"] = $plItem->getDbCuein();
$data["cueout"] = $plItem->getDbCueout();
$data["fadein"] = $plItem->getDbFadein();
$data["fadeout"] = $plItem->getDbFadeout();
$files[] = $data;
}
} }
} }
@ -98,6 +111,8 @@ class Application_Model_Scheduler {
try { try {
$affectedShowInstances = array();
//dont want to recalculate times for moved items. //dont want to recalculate times for moved items.
$excludeIds = array(); $excludeIds = array();
foreach ($schedFiles as $file) { foreach ($schedFiles as $file) {
@ -108,34 +123,42 @@ class Application_Model_Scheduler {
foreach ($scheduleItems as $schedule) { foreach ($scheduleItems as $schedule) {
$id = intval($schedule["id"]); $id = intval($schedule["id"]);
$ts = intval($schedule["timestamp"]);
Logging::log("scheduling after scheduled item: ".$id); Logging::log("scheduling after scheduled item: ".$id);
Logging::log("in show: ".intval($schedule["instance"])); Logging::log("in show: ".intval($schedule["instance"]));
if ($id !== 0) { if ($id !== 0) {
$schedItem = CcScheduleQuery::create()->findPK($id, $this->con); $schedItem = CcScheduleQuery::create()->findPK($id, $this->con);
$instance = $schedItem->getDbInstanceId(); $instance = $schedItem->getCcShowInstances($this->con);
if (intval($schedule["instance"]) !== $instance->getDbId()) {
//user has an old copy of the time line opened. throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
if ($instance !== intval($schedule["instance"])) {
Logging::log("items have been since updated");
return;
} }
$nextStartDT = $schedItem->getDbEnds(null); $nextStartDT = $schedItem->getDbEnds(null);
} }
//selected empty row to add after //selected empty row to add after
else { else {
$showInstance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con); $instance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con);
$nextStartDT = $showInstance->getDbStarts(null); $nextStartDT = $showInstance->getDbStarts(null);
$instance = intval($schedule["instance"]); }
$currTs = intval($instance->getDbLastScheduled("U")) ? : 0;
//user has an old copy of the time line opened.
if ($ts !== $currTs) {
Logging::log("currTs {$currTs}, ts {$ts}");
$show = $instance->getCcShow($this->con);
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
}
if (!in_array($instance->getDbId(), $affectedShowInstances)) {
$affectedShowInstances[] = $instance->getDbId();
} }
Logging::log("finding items >= {$nextStartDT->format("Y-m-d H:i:s.u")}"); Logging::log("finding items >= {$nextStartDT->format("Y-m-d H:i:s.u")}");
if ($adjustSched === true) { if ($adjustSched === true) {
$followingSchedItems = CcScheduleQuery::create() $followingSchedItems = CcScheduleQuery::create()
->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL) ->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL)
->filterByDbInstanceId($instance) ->filterByDbInstanceId($instance->getDbId())
->filterByDbId($excludeIds, Criteria::NOT_IN) ->filterByDbId($excludeIds, Criteria::NOT_IN)
->orderByDbStarts() ->orderByDbStarts()
->find($this->con); ->find($this->con);
@ -171,7 +194,7 @@ class Application_Model_Scheduler {
$sched->setDbFadeIn($file['fadein']); $sched->setDbFadeIn($file['fadein']);
$sched->setDbFadeOut($file['fadeout']); $sched->setDbFadeOut($file['fadeout']);
$sched->setDbClipLength($file['cliplength']); $sched->setDbClipLength($file['cliplength']);
$sched->setDbInstanceId($instance); $sched->setDbInstanceId($instance->getDbId());
$sched->save($this->con); $sched->save($this->con);
$nextStartDT = $endTimeDT; $nextStartDT = $endTimeDT;
@ -195,6 +218,10 @@ class Application_Model_Scheduler {
} }
} }
//update the last scheduled timestamp.
CcShowInstancesQuery::create()
->filterByPrimaryKeys($showInstances)
->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
} }
catch (Exception $e) { catch (Exception $e) {
throw $e; throw $e;
@ -236,37 +263,46 @@ class Application_Model_Scheduler {
* @param array $selectedItem * @param array $selectedItem
* @param array $afterItem * @param array $afterItem
*/ */
public function moveItem($selectedItem, $afterItem, $adjustSched = true) { public function moveItem($selectedItems, $afterItems, $adjustSched = true) {
$this->con->beginTransaction(); $this->con->beginTransaction();
try { try {
$origSelIns = intval($selectedItem[0]["instance"]); $origSelTs = intval($selectedItems[0]["timestamp"]);
$origAfterIns = intval($afterItem[0]["instance"]); $origAfterTs = intval($afterItems[0]["timestamp"]);
Logging::log("Moving item {$selectedItem[0]["id"]}"); Logging::log("Moving item {$selectedItems[0]["id"]}");
Logging::log("After {$afterItem[0]["id"]}"); Logging::log("After {$afterItems[0]["id"]}");
$selected = CcScheduleQuery::create()->findPk($selectedItem[0]["id"]); $selected = CcScheduleQuery::create()->findPk($selectedItems[0]["id"], $this->con);
$after = CcScheduleQuery::create()->findPk($afterItem[0]["id"]); $after = CcScheduleQuery::create()->findPk($afterItems[0]["id"], $this->con);
/* if (is_null($selected) || is_null($after)) {
if (isset($after) && $origSelIns !== $selected->getDBInstanceId() throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|| $origAfterIns !== $after->getDBInstanceId()) {
Logging::log("items have been since updated");
return;
} }
*/
$this->removeGaps($origSelIns, $selected->getDbId()); $selectedInstance = $selected->getCcShowInstances($this->con);
$afterInstance = $after->getCcShowInstances($this->con);
//moved to another show, remove gaps from original show.
if ($adjustSched === true && $origSelIns !== $origAfterIns) {
if (is_null($selectedInstance) || is_null($afterInstance)) {
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
} }
$currTs = intval($selectedInstance->getDbLastScheduled("U")) ? : 0;
if ($origSelTs !== $currTs) {
$show = $selectedInstance->getCcShow($this->con);
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
}
$currTs = intval($afterInstance->getDbLastScheduled("U")) ? : 0;
if ($origAfterTs !== $currTs) {
$show = $afterInstance->getCcShow($this->con);
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
}
$this->removeGaps($selectedInstance->getDbId(), $selected->getDbId());
$data = $this->fileInfo; $data = $this->fileInfo;
$data["id"] = $selected->getDbFileId(); $data["id"] = $selected->getDbFileId();
$data["cliplength"] = $selected->getDbClipLength(); $data["cliplength"] = $selected->getDbClipLength();
@ -276,7 +312,7 @@ class Application_Model_Scheduler {
$data["fadeout"] = $selected->getDbFadeOut(); $data["fadeout"] = $selected->getDbFadeOut();
$data["sched_id"] = $selected->getDbId(); $data["sched_id"] = $selected->getDbId();
$this->insertAfter($afterItem, array($data), $adjustSched); $this->insertAfter($afterItems, array($data), $adjustSched);
$this->con->commit(); $this->con->commit();
@ -297,7 +333,7 @@ class Application_Model_Scheduler {
$scheduledIds = array(); $scheduledIds = array();
foreach ($scheduledItems as $item) { foreach ($scheduledItems as $item) {
$scheduledIds[$item["id"]] = $item["timestamp"]; $scheduledIds[$item["id"]] = intval($item["timestamp"]);
} }
$removedItems = CcScheduleQuery::create()->findPks(array_keys($scheduledIds)); $removedItems = CcScheduleQuery::create()->findPks(array_keys($scheduledIds));
@ -306,11 +342,14 @@ class Application_Model_Scheduler {
foreach ($removedItems as $removedItem) { foreach ($removedItems as $removedItem) {
$ts = $scheduledIds[$removedItem->getDbId()]; $ts = $scheduledIds[$removedItem->getDbId()];
$instance = $removedItem->getCcShowInstances($this->con); $instance = $removedItem->getCcShowInstances($this->con);
if (is_null($instance)) {
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
}
$currTs = intval($instance->getDbLastScheduled("U")) ? : 0; $currTs = intval($instance->getDbLastScheduled("U")) ? : 0;
if ($ts !== $currTs) { if ($ts !== $currTs) {
$show = $instance->getCcShow($this->con); $show = $instance->getCcShow($this->con);
throw new OutDatedScheduleException("The show {$show->getDbName()} is outdated!"); throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
} }
} }
@ -331,6 +370,11 @@ class Application_Model_Scheduler {
} }
} }
//update the last scheduled timestamp.
CcShowInstancesQuery::create()
->filterByPrimaryKeys($showInstances)
->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
$this->con->commit(); $this->con->commit();
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::PushSchedule();
@ -346,13 +390,14 @@ class Application_Model_Scheduler {
* @param array $exclude * @param array $exclude
* ids of sched items to remove from the calulation. * ids of sched items to remove from the calulation.
*/ */
public function removeGaps($showInstance, $exclude=null) { private function removeGaps($showInstance, $exclude=null) {
Logging::log("removing gaps from show instance #".$showInstance); Logging::log("removing gaps from show instance #".$showInstance);
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con); $instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
$instance->setDbLastScheduled(new DateTime("now", new DateTimeZone("UTC"))); if (is_null($instance)) {
$instance->save($this->con); throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
}
$itemStartDT = $instance->getDbStarts(null); $itemStartDT = $instance->getDbStarts(null);

View file

@ -850,14 +850,14 @@ class Application_Model_StoredFile {
//check to see if we have enough space in the /organize directory to copy the file //check to see if we have enough space in the /organize directory to copy the file
$freeSpace = disk_free_space($destination_folder); $freeSpace = disk_free_space($destination_folder);
$fileSize = filesize($audio_file); $fileSize = filesize($audio_file);
if ( $freeSpace < $fileSize ){ if ( $freeSpace < $fileSize ){
$freeSpace = floor($freeSpace/1024/1024); $freeSpace = floor($freeSpace/1024/1024);
$fileSize = floor($fileSize/1024/1024); $fileSize = floor($fileSize/1024/1024);
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, there was '.$freeSpace.'MB disk space left the file you are uploadings size is '.$fileSize.'MB."}}'); die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, there was '.$freeSpace.'MB disk space left the file you are uploadings size is '.$fileSize.'MB."}}');
} }
} }
public static function copyFileToStor($p_targetDir, $fileName, $tempname){ public static function copyFileToStor($p_targetDir, $fileName, $tempname){
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname; $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
Logging::log('copyFileToStor: moving file '.$audio_file); Logging::log('copyFileToStor: moving file '.$audio_file);
@ -875,13 +875,13 @@ class Application_Model_StoredFile {
$storDir = Application_Model_MusicDir::getStorDir(); $storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory(); $stor = $storDir->getDirectory();
//check to see if there is enough space in $stor to continue. //check to see if there is enough space in $stor to continue.
Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file); Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
$stor .= "/organize"; $stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor"); Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation //Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
$r = @rename($audio_file, $audio_stor); $r = @rename($audio_file, $audio_stor);
@ -897,7 +897,7 @@ class Application_Model_StoredFile {
//$r = @unlink($audio_file); //$r = @unlink($audio_file);
} }
public static function getFileCount() public static function getFileCount()
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
@ -1028,3 +1028,4 @@ class Application_Model_StoredFile {
} }
class DeleteScheduledFileException extends Exception {} class DeleteScheduledFileException extends Exception {}
class FileDoesNotExistException extends Exception {}

View file

@ -59,7 +59,7 @@ var AIRTIME = (function(AIRTIME){
for (item in aData) { for (item in aData) {
temp = aData[item]; temp = aData[item];
if (temp !== null && temp.hasOwnProperty('id')) { if (temp !== null && temp.hasOwnProperty('id')) {
aSchedIds.push({"id": temp.id, "instance": temp.instance}); aSchedIds.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp});
} }
} }