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 PlaylistNotFoundException extends Exception {}
class OutDatedException extends Exception {}
class PlaylistOutDatedException extends Exception {}

View file

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

View file

@ -1028,3 +1028,4 @@ class Application_Model_StoredFile {
}
class DeleteScheduledFileException extends Exception {}
class FileDoesNotExistException extends Exception {}

View file

@ -59,7 +59,7 @@ var AIRTIME = (function(AIRTIME){
for (item in aData) {
temp = aData[item];
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});
}
}