CC-3551 : Change Cue Out for currently deleted track

This commit is contained in:
Naomi Aro 2012-03-29 19:20:02 +02:00
parent 6135cbc79f
commit cea37774ca
6 changed files with 41 additions and 43 deletions

View file

@ -772,8 +772,7 @@ class ScheduleController extends Zend_Controller_Action
public function cancelShowAction() public function cancelShowAction()
{ {
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = Application_Model_User::GetCurrentUser();
$user = new Application_Model_User($userInfo->id);
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
$showInstanceId = $this->_getParam('id'); $showInstanceId = $this->_getParam('id');

View file

@ -254,9 +254,6 @@ class ShowbuilderController extends Zend_Controller_Action
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
Logging::log("showbuilder starts {$startsDT->format("Y-m-d H:i:s")}");
Logging::log("showbuilder ends {$endsDT->format("Y-m-d H:i:s")}");
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);

View file

@ -76,12 +76,10 @@ class Application_Model_Datatables {
try { try {
$r = $con->query($sqlTotalRows); $r = $con->query($sqlTotalRows);
Logging::log($sqlTotalRows);
$totalRows = $r->fetchColumn(0); $totalRows = $r->fetchColumn(0);
if (isset($sqlTotalDisplayRows)) { if (isset($sqlTotalDisplayRows)) {
$r = $con->query($sqlTotalDisplayRows); $r = $con->query($sqlTotalDisplayRows);
Logging::log($sqlTotalDisplayRows);
$totalDisplayRows = $r->fetchColumn(0); $totalDisplayRows = $r->fetchColumn(0);
} }
else { else {
@ -93,11 +91,11 @@ class Application_Model_Datatables {
$results = $r->fetchAll(); $results = $r->fetchAll();
} }
catch (Exception $e) { catch (Exception $e) {
Logging::log($e->getMessage()); Logging::debug($e->getMessage());
} }
//display sql executed in airtime log for testing //display sql executed in airtime log for testing
Logging::log($sql); //Logging::log($sql);
return array( return array(
"sEcho" => intval($data["sEcho"]), "sEcho" => intval($data["sEcho"]),

View file

@ -261,8 +261,6 @@ class Application_Model_Schedule {
$sql .= " ORDER BY si.starts, sched.starts;"; $sql .= " ORDER BY si.starts, sched.starts;";
Logging::log($sql);
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;
} }

View file

@ -13,13 +13,17 @@ class Application_Model_Scheduler {
"sched_id" => null, "sched_id" => null,
); );
private $epochNow;
private $nowDT; private $nowDT;
private $user; private $user;
public function __construct($id = null) { public function __construct($id = null) {
$this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$this->nowDT = new DateTime("now", new DateTimeZone("UTC"));
$this->epochNow = floatval(microtime(true));
$this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC"));
$this->user = Application_Model_User::GetCurrentUser(); $this->user = Application_Model_User::GetCurrentUser();
} }
@ -30,7 +34,7 @@ class Application_Model_Scheduler {
*/ */
private function validateRequest($items) { private function validateRequest($items) {
$nowEpoch = intval($this->nowDT->format("U")); $nowEpoch = floatval($this->nowDT->format("U.u"));
for ($i = 0; $i < count($items); $i++) { for ($i = 0; $i < count($items); $i++) {
$id = $items[$i]["id"]; $id = $items[$i]["id"];
@ -83,7 +87,7 @@ class Application_Model_Scheduler {
throw new Exception("You are not allowed to schedule show {$show->getDbName()}."); throw new Exception("You are not allowed to schedule show {$show->getDbName()}.");
} }
$showEndEpoch = intval($instance->getDbEnds("U")); $showEndEpoch = floatval($instance->getDbEnds("U.u"));
if ($showEndEpoch < $nowEpoch) { if ($showEndEpoch < $nowEpoch) {
throw new OutDatedScheduleException("The show {$show->getDbName()} is over and cannot be scheduled."); throw new OutDatedScheduleException("The show {$show->getDbName()} is over and cannot be scheduled.");
@ -169,7 +173,7 @@ class Application_Model_Scheduler {
* *
* @return DateTime endDT in UTC * @return DateTime endDT in UTC
*/ */
private static function findEndTime($p_startDT, $p_duration) { private function findEndTime($p_startDT, $p_duration) {
$startEpoch = $p_startDT->format("U.u"); $startEpoch = $p_startDT->format("U.u");
$durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration); $durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration);
@ -178,22 +182,14 @@ class Application_Model_Scheduler {
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number. //DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6); $endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
Logging::log("start DateTime created {$p_startDT->format("Y-m-d H:i:s.u")}");
Logging::log("start epoch is {$startEpoch}");
Logging::log("duration in seconds is {$durationSeconds}");
Logging::log("end epoch is {$endEpoch}");
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC")); $dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
Logging::log("end DateTime created {$dt->format("Y-m-d H:i:s.u")}");
return $dt; return $dt;
} }
private function findNextStartTime($DT, $instance) { private function findNextStartTime($DT, $instance) {
$sEpoch = intval($DT->format("U")); $sEpoch = floatval($DT->format("U.u"));
$nowEpoch = intval($this->nowDT->format("U")); $nowEpoch = $this->epochNow;
//check for if the show has started. //check for if the show has started.
if ($nowEpoch > $sEpoch) { if ($nowEpoch > $sEpoch) {
@ -273,7 +269,7 @@ class Application_Model_Scheduler {
foreach($schedFiles as $file) { foreach($schedFiles as $file) {
$endTimeDT = self::findEndTime($nextStartDT, $file['cliplength']); $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']);
//item existed previously and is being moved. //item existed previously and is being moved.
//need to keep same id for resources if we want REST. //need to keep same id for resources if we want REST.
@ -303,7 +299,7 @@ class Application_Model_Scheduler {
//recalculate the start/end times after the inserted items. //recalculate the start/end times after the inserted items.
foreach ($followingSchedItems as $item) { foreach ($followingSchedItems as $item) {
$endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength()); $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength());
$item->setDbStarts($nextStartDT); $item->setDbStarts($nextStartDT);
$item->setDbEnds($endTimeDT); $item->setDbEnds($endTimeDT);
@ -448,17 +444,26 @@ class Application_Model_Scheduler {
$instance = $removedItem->getCcShowInstances($this->con); $instance = $removedItem->getCcShowInstances($this->con);
//check to truncate the currently playing item instead of deleting it. //check to truncate the currently playing item instead of deleting it.
if ($removedItem->isCurrentItem()) { if ($removedItem->isCurrentItem($this->epochNow)) {
$now = new DateTime("now", new DateTimeZone("UTC"));
$nEpoch = floatval($now->format('U.u')); $nEpoch = $this->epochNow;
$sEpoch = floatval($removedItem->getDbStarts('U.u')); $sEpoch = floatval($removedItem->getDbStarts('U.u'));
$length = $nEpoch - $sEpoch; $length = $nEpoch - $sEpoch;
$cliplength = Application_Model_Playlist::secondsToPlaylistTime($length); $cliplength = Application_Model_Playlist::secondsToPlaylistTime($length);
$removedItem->setDbClipLength($cliplength); $cueinSec = Application_Model_Playlist::playlistTimeToSeconds($removedItem->getDbCueIn());
$removedItem->setDbEnds($now); $cueOutSec = $cueinSec + $length;
$removedItem->save($this->con); $cueout = Application_Model_Playlist::secondsToPlaylistTime($length);
Logging::log('$nEpoch: '. $nEpoch);
Logging::log('$sEpoch: '. $sEpoch);
Logging::log('$length: '. $length);
Logging::log('$cliplength: '. $cliplength);
$removedItem->setDbCueOut($cueout)
->setDbClipLength($cliplength)
->setDbEnds($now)
->save($this->con);
} }
else { else {
$removedItem->delete($this->con); $removedItem->delete($this->con);
@ -529,9 +534,7 @@ class Application_Model_Scheduler {
foreach ($schedule as $item) { foreach ($schedule as $item) {
Logging::log("adjusting item #".$item->getDbId()); $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
$itemEndDT = self::findEndTime($itemStartDT, $item->getDbClipLength());
$item->setDbStarts($itemStartDT); $item->setDbStarts($itemStartDT);
$item->setDbEnds($itemEndDT); $item->setDbEnds($itemEndDT);

View file

@ -224,11 +224,14 @@ class CcSchedule extends BaseCcSchedule {
return $this; return $this;
} // setDbEnds() } // setDbEnds()
public function isCurrentItem() { public function isCurrentItem($epochNow = null) {
$epochNow = time(); if (is_null($epochNow)) {
$epochStart = intval($this->getDbStarts('U')); $epochNow = microtime(true);
$epochEnd = intval($this->getDbEnds('U')); }
$epochStart = floatval($this->getDbStarts('U.u'));
$epochEnd = floatval($this->getDbEnds('U.u'));
if ($epochStart < $epochNow && $epochEnd > $epochNow) { if ($epochStart < $epochNow && $epochEnd > $epochNow) {
return true; return true;