XXXX-260 - Recalculate schedule API as part of bugfix
Conflicts: airtime_mvc/application/configs/constants.php airtime_mvc/application/controllers/ApiController.php airtime_mvc/application/models/Scheduler.php
This commit is contained in:
parent
1efd0b815b
commit
ee99a7304f
3 changed files with 99 additions and 1 deletions
|
@ -42,6 +42,7 @@ define('DEFAULT_MICROTIME_FORMAT', 'Y-m-d H:i:s.u');
|
|||
define('DEFAULT_ICECAST_PORT', 8000);
|
||||
define('DEFAULT_ICECAST_PASS', 'hackme');
|
||||
define('DEFAULT_SHOW_COLOR', '76aca5');
|
||||
define('DEFAULT_INTERVAL_FORMAT', 'H:i:s.u');
|
||||
|
||||
// Metadata Keys for files
|
||||
define('MDATA_KEY_FILEPATH' , 'filepath');
|
||||
|
|
|
@ -73,6 +73,7 @@ class ApiController extends Zend_Controller_Action
|
|||
->addActionContext('update-replay-gain-value' , 'json')
|
||||
->addActionContext('update-cue-values-by-silan' , 'json')
|
||||
->addActionContext('get-usability-hint' , 'json')
|
||||
->addActionContext('recalculate-schedule' , 'json') //RKTN-260
|
||||
->initContext();
|
||||
}
|
||||
|
||||
|
@ -1520,5 +1521,27 @@ class ApiController extends Zend_Controller_Action
|
|||
$m3uFile .= $stream['url'] . "\r\n\r\n";
|
||||
}
|
||||
echo $m3uFile;
|
||||
public function recalculateScheduleAction()
|
||||
{
|
||||
$scheduler = new Application_Model_Scheduler();
|
||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||
|
||||
$showInstances = CcShowInstancesQuery::create()
|
||||
->filterByDbStarts($now, Criteria::GREATER_THAN)
|
||||
//->filterByDbModifiedInstance(false)
|
||||
->orderByDbStarts()
|
||||
->find();
|
||||
//->find($this->con);
|
||||
$total = $showInstances->count();
|
||||
$progress = 0;
|
||||
foreach ($showInstances as $instance) {
|
||||
echo(round(floatval($progress / $total)*100) . "% - " . $instance->getDbId() . "\n<br>");
|
||||
flush();
|
||||
ob_flush();
|
||||
//while(@ob_end_clean());
|
||||
$scheduler->removeGaps2($instance->getDbId());
|
||||
$progress += 1;
|
||||
}
|
||||
echo("Recalculated $total shows.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,6 +384,24 @@ class Application_Model_Scheduler
|
|||
return $dt;
|
||||
}
|
||||
|
||||
private function findTimeDifference2($p_startDT, $p_endDT) {
|
||||
$startEpoch = $p_startDT->format("U.u");
|
||||
$endEpoch = $p_endDT->format("U.u");
|
||||
|
||||
//add two float numbers to 6 subsecond precision
|
||||
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
|
||||
$newEpoch = bcsub($endEpoch, (string)$startEpoch, 6);
|
||||
|
||||
$dt = DateTime::createFromFormat("U.u", $newEpoch, new DateTimeZone("UTC"));
|
||||
|
||||
if ($dt === false) {
|
||||
//PHP 5.3.2 problem
|
||||
$dt = DateTime::createFromFormat("U", intval($newEpoch), new DateTimeZone("UTC"));
|
||||
}
|
||||
|
||||
return $dt;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param DateTime startDT in UTC
|
||||
* @param string duration
|
||||
|
@ -498,12 +516,68 @@ class Application_Model_Scheduler
|
|||
|
||||
$itemStartDT = $instance->getDbStarts(null);
|
||||
foreach ($schedule as $item) {
|
||||
|
||||
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
|
||||
|
||||
$item->setDbStarts($itemStartDT)
|
||||
->setDbEnds($itemEndDT);
|
||||
|
||||
$itemStartDT = $itemEndDT;
|
||||
}
|
||||
|
||||
$schedule->save($this->con);
|
||||
}
|
||||
|
||||
/** Temporary hack to copy the track cue in, out, and length from the cc_files table to fix
|
||||
* incorrect track lengths (RKTN-260)
|
||||
*/
|
||||
public function removeGaps2($showInstance, $exclude = null) {
|
||||
Logging::info("removing gaps from show instance #" . $showInstance);
|
||||
|
||||
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
|
||||
if (is_null($instance)) {
|
||||
throw new OutDatedScheduleException(_("The schedule you're viewing is out of date!"));
|
||||
}
|
||||
|
||||
$itemStartDT = $instance->getDbStarts(null);
|
||||
|
||||
$schedule = CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($showInstance)
|
||||
->filterByDbId($exclude, Criteria::NOT_IN)
|
||||
->orderByDbStarts()
|
||||
->find($this->con);
|
||||
|
||||
foreach ($schedule as $item) {
|
||||
|
||||
//START OF TIME RECALC HACK
|
||||
|
||||
//TODO: Copy the cue in, cue out, and track length from the cc_files table
|
||||
$file = $item->getCcFiles($this->con);
|
||||
$item->setDbCueIn($file->getDbCueIn());
|
||||
$item->setDbCueOut($file->getDbCueOut());
|
||||
|
||||
$cueOut = new DateTime($file->getDbCueOut());
|
||||
$cueIn = new DateTime($file->getDbCueIn());
|
||||
$clipLength = $this->findTimeDifference2($cueIn, $cueOut);
|
||||
|
||||
//The clip length is supposed to be cue out - cue in:
|
||||
//FIXME: How do we correctly do time arithmetic in PHP without losing the millseconds?
|
||||
$item->setDbClipLength($clipLength->format(DEFAULT_INTERVAL_FORMAT));
|
||||
$item->save($this->con);
|
||||
//Ensure we don't get cached results
|
||||
CcSchedulePeer::clearInstancePool();
|
||||
//END OF TIME RECALC HACK
|
||||
|
||||
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
|
||||
$item->setDbStarts($itemStartDT)
|
||||
->setDbEnds($itemEndDT)
|
||||
->save($this->con);
|
||||
$itemStartDT = $this->findTimeDifference($itemEndDT, $this->crossfadeDuration);
|
||||
}
|
||||
|
||||
$instance->updateDbTimeFilled($this->con); //FIXME: TIME RECALC HACK (Albert)
|
||||
|
||||
$schedule->save($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue