Format code using php-cs-fixer

This commit is contained in:
jo 2021-10-11 16:10:47 +02:00
parent 43d7dc92cd
commit d52c6184b9
352 changed files with 17473 additions and 17041 deletions

View file

@ -1,17 +1,18 @@
<?php
class Application_Service_SchedulerService
{
private $con;
private $fileInfo = array(
"id" => "",
"cliplength" => "",
"cuein" => "00:00:00",
"cueout" => "00:00:00",
"fadein" => "00:00:00",
"fadeout" => "00:00:00",
"sched_id" => null,
"type" => 0 //default type of '0' to represent files. type '1' represents a webstream
);
private $fileInfo = [
'id' => '',
'cliplength' => '',
'cuein' => '00:00:00',
'cueout' => '00:00:00',
'fadein' => '00:00:00',
'fadeout' => '00:00:00',
'sched_id' => null,
'type' => 0, //default type of '0' to represent files. type '1' represents a webstream
];
private $epochNow;
private $nowDT;
@ -26,13 +27,13 @@ class Application_Service_SchedulerService
//to epochNow and then send the new schedule to pypo. Sometimes the currently cancelled
//track can still be included in the new schedule because it may have a few ms left to play.
//subtracting 1 second from epochNow resolves this issue.
$this->epochNow = microtime(true)-1;
$this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC"));
$this->epochNow = microtime(true) - 1;
$this->nowDT = DateTime::createFromFormat('U.u', $this->epochNow, new DateTimeZone('UTC'));
if ($this->nowDT === false) {
// DateTime::createFromFormat does not support millisecond string formatting in PHP 5.3.2 (Ubuntu 10.04).
// In PHP 5.3.3 (Ubuntu 10.10), this has been fixed.
$this->nowDT = DateTime::createFromFormat("U", time(), new DateTimeZone("UTC"));
$this->nowDT = DateTime::createFromFormat('U', time(), new DateTimeZone('UTC'));
}
$user_service = new Application_Service_UserService();
@ -40,9 +41,8 @@ class Application_Service_SchedulerService
}
/**
*
* Applies the show start difference to any scheduled items
*
* Applies the show start difference to any scheduled items.
*
* @param $instanceIds
* @param $diff (integer, difference between unix epoch in seconds)
*/
@ -50,13 +50,14 @@ class Application_Service_SchedulerService
{
$con = Propel::getConnection();
if (count($instanceIds) > 0) {
$showIdList = implode(",", $instanceIds);
$showIdList = implode(',', $instanceIds);
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN)
->find($con);
->find($con)
;
$interval = new DateInterval("PT".abs($diff)."S");
$interval = new DateInterval('PT' . abs($diff) . 'S');
if ($diff < 0) {
$interval->invert = 1;
}
@ -68,23 +69,24 @@ class Application_Service_SchedulerService
$ccSchedule
->setDbStarts($newStart)
->setDbEnds($newEnd)
->save($con);
->save($con)
;
}
}
}
/**
*
* Removes any time gaps in shows
*
* Removes any time gaps in shows.
*
* @param array $schedIds schedule ids to exclude
* @param mixed $showId
*/
public function removeGaps($showId, $schedIds=null)
public function removeGaps($showId, $schedIds = null)
{
$ccShowInstances = CcShowInstancesQuery::create()->filterByDbShowId($showId)->find();
foreach ($ccShowInstances as $instance) {
Logging::info("Removing gaps from show instance #".$instance->getDbId());
Logging::info('Removing gaps from show instance #' . $instance->getDbId());
//DateTime object
$itemStart = $instance->getDbStarts(null);
@ -92,14 +94,16 @@ class Application_Service_SchedulerService
->filterByDbInstanceId($instance->getDbId())
->filterByDbId($schedIds, Criteria::NOT_IN)
->orderByDbStarts()
->find();
->find()
;
foreach ($ccScheduleItems as $ccSchedule) {
//DateTime object
$itemEnd = $this->findEndTime($itemStart, $ccSchedule->getDbClipLength());
$ccSchedule->setDbStarts($itemStart)
->setDbEnds($itemEnd);
->setDbEnds($itemEnd)
;
$itemStart = $itemEnd;
}
@ -108,25 +112,25 @@ class Application_Service_SchedulerService
}
/**
*
* Enter description here ...
*
* @param DateTime $instanceStart
* @param string $clipLength
* @param string $clipLength
*/
private static function findEndTime($instanceStart, $clipLength)
{
$startEpoch = $instanceStart->format("U.u");
$startEpoch = $instanceStart->format('U.u');
$durationSeconds = Application_Common_DateHelper::playlistTimeToSeconds($clipLength);
//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.
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
$endEpoch = bcadd($startEpoch, (string) $durationSeconds, 6);
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
$dt = DateTime::createFromFormat('U.u', $endEpoch, new DateTimeZone('UTC'));
if ($dt === false) {
//PHP 5.3.2 problem
$dt = DateTime::createFromFormat("U", intval($endEpoch), new DateTimeZone("UTC"));
$dt = DateTime::createFromFormat('U', intval($endEpoch), new DateTimeZone('UTC'));
}
return $dt;
@ -134,44 +138,43 @@ class Application_Service_SchedulerService
private static function findTimeDifference($p_startDT, $p_seconds)
{
$startEpoch = $p_startDT->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($startEpoch , (string) $p_seconds, 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;
$startEpoch = $p_startDT->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($startEpoch, (string) $p_seconds, 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;
}
/**
*
* Gets a copy of the linked show's schedule from cc_schedule table
*
* Gets a copy of the linked show's schedule from cc_schedule table.
*
* If $instanceId is not null, we use that variable to grab the linked
* show's schedule from cc_schedule table. (This is likely to be the case
* if a user has edited a show and changed it from un-linked to linked, in
* which case we copy the show content from the show instance that was clicked
* on to edit the show in the calendar.) Otherwise the schedule is taken
* from the most recent show instance that existed before new show
* instances were created. (This is likely to be the case when a user edits a
* instances were created. (This is likely to be the case when a user edits a
* show and a new repeat show day is added (i.e. mondays), or moves forward in the
* calendar triggering show creation)
*
* @param integer $showId
*
* @param int $showId
* @param array $instancsIdsToFill
* @param integer $instanceId
* @param int $instanceId
*/
private static function getLinkedShowSchedule($showId, $instancsIdsToFill, $instanceId)
{
$con = Propel::getConnection();
if (is_null($instanceId)) {
$showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil();
@ -181,7 +184,8 @@ class Application_Service_SchedulerService
->filterByDbId($instancsIdsToFill, Criteria::NOT_IN)
->orderByDbStarts(Criteria::DESC)
->limit(1)
->findOne();
->findOne()
;
if (is_null($showInstanceWithMostRecentSchedule)) {
return null;
@ -190,46 +194,50 @@ class Application_Service_SchedulerService
}
$linkedShowSchedule_sql = $con->prepare(
"select * from cc_schedule where instance_id = :instance_id ".
"order by starts");
'select * from cc_schedule where instance_id = :instance_id ' .
'order by starts'
);
$linkedShowSchedule_sql->bindParam(':instance_id', $instanceId);
$linkedShowSchedule_sql->execute();
return $linkedShowSchedule_sql->fetchAll();
}
/**
*
* This function gets called after new linked show_instances are created, or after
* a show has been edited and went from being un-linked to linked.
* It fills the new show instances' schedules.
*
*
* @param CcShow_type $ccShow
* @param array $instanceIdsToFill ids of the new linked cc_show_instances that
* need their schedules filled
* @param array $instanceIdsToFill ids of the new linked cc_show_instances that
* need their schedules filled
* @param null|mixed $instanceId
*/
public static function fillLinkedInstances($ccShow, $instanceIdsToFill, $instanceId=null)
public static function fillLinkedInstances($ccShow, $instanceIdsToFill, $instanceId = null)
{
//Get the "template" schedule for the linked show (contents of the linked show) that will be
//Get the "template" schedule for the linked show (contents of the linked show) that will be
//copied into to all the new show instances.
$linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill, $instanceId);
//get time_filled so we can update cc_show_instances
if (!empty($linkedShowSchedule)) {
$timeFilled_sql = "SELECT time_filled FROM cc_show_instances ".
"WHERE id = {$linkedShowSchedule[0]["instance_id"]}";
$timeFilled_sql = 'SELECT time_filled FROM cc_show_instances ' .
"WHERE id = {$linkedShowSchedule[0]['instance_id']}";
$timeFilled = Application_Common_Database::prepareAndExecute(
$timeFilled_sql, array(), Application_Common_Database::COLUMN);
$timeFilled_sql,
[],
Application_Common_Database::COLUMN
);
} else {
//We probably shouldn't return here because the code below will
//set this on each empty show instance...
$timeFilled = "00:00:00";
$timeFilled = '00:00:00';
}
$values = array();
$values = [];
$con = Propel::getConnection();
//Here we begin to fill the new show instances (as specified by $instanceIdsToFill)
//with content from $linkedShowSchedule.
try {
@ -242,50 +250,60 @@ class Application_Service_SchedulerService
self::clearShowInstanceContents($id);
// Now fill the show instance with the same content that $linkedShowSchedule has.
$instanceStart_sql = "SELECT starts FROM cc_show_instances " .
"WHERE id = {$id} " . "ORDER BY starts";
$instanceStart_sql = 'SELECT starts FROM cc_show_instances ' .
"WHERE id = {$id} " . 'ORDER BY starts';
//What's tricky here is that when we copy the content, we have to adjust
//the start and end times of each track so they're inside the new show instance's time slot.
$nextStartDT = new DateTime(
Application_Common_Database::prepareAndExecute(
$instanceStart_sql, array(),
Application_Common_Database::COLUMN),
new DateTimeZone("UTC"));
$instanceStart_sql,
[],
Application_Common_Database::COLUMN
),
new DateTimeZone('UTC')
);
$defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
unset($values);
$values = array();
$values = [];
foreach ($linkedShowSchedule as $item) {
$endTimeDT = self::findEndTime($nextStartDT,
$item["clip_length"]);
$endTimeDT = self::findEndTime(
$nextStartDT,
$item['clip_length']
);
if (is_null($item["file_id"])) {
$item["file_id"] = "null";
if (is_null($item['file_id'])) {
$item['file_id'] = 'null';
}
if (is_null($item["stream_id"])) {
$item["stream_id"] = "null";
if (is_null($item['stream_id'])) {
$item['stream_id'] = 'null';
}
$values[] = "(" . "'{$nextStartDT->format(DEFAULT_TIMESTAMP_FORMAT)}', " .
$values[] = '(' . "'{$nextStartDT->format(DEFAULT_TIMESTAMP_FORMAT)}', " .
"'{$endTimeDT->format(DEFAULT_TIMESTAMP_FORMAT)}', " .
"'{$item["clip_length"]}', " .
"'{$item["fade_in"]}', " . "'{$item["fade_out"]}', " .
"'{$item["cue_in"]}', " . "'{$item["cue_out"]}', " .
"{$item["file_id"]}, " . "{$item["stream_id"]}, " .
"{$id}, " . "{$item["position"]})";
"'{$item['clip_length']}', " .
"'{$item['fade_in']}', " . "'{$item['fade_out']}', " .
"'{$item['cue_in']}', " . "'{$item['cue_out']}', " .
"{$item['file_id']}, " . "{$item['stream_id']}, " .
"{$id}, " . "{$item['position']})";
$nextStartDT = self::findTimeDifference($endTimeDT,
$defaultCrossfadeDuration);
$nextStartDT = self::findTimeDifference(
$endTimeDT,
$defaultCrossfadeDuration
);
} //foreach show item
if (!empty($values)) {
$insert_sql = "INSERT INTO cc_schedule (starts, ends, " .
"clip_length, fade_in, fade_out, cue_in, cue_out, " .
"file_id, stream_id, instance_id, position) VALUES " .
implode($values, ",");
$insert_sql = 'INSERT INTO cc_schedule (starts, ends, ' .
'clip_length, fade_in, fade_out, cue_in, cue_out, ' .
'file_id, stream_id, instance_id, position) VALUES ' .
implode($values, ',');
Application_Common_Database::prepareAndExecute(
$insert_sql, array(), Application_Common_Database::EXECUTE);
$insert_sql,
[],
Application_Common_Database::EXECUTE
);
}
//update cc_schedule status column
@ -298,18 +316,19 @@ class Application_Service_SchedulerService
$now = gmdate(DEFAULT_TIMESTAMP_FORMAT);
$whereClause = new Criteria();
$whereClause->add(CcShowInstancesPeer::ID, $instanceIdsToFill, Criteria::IN);
$updateClause = new Criteria();
$updateClause->add(CcShowInstancesPeer::TIME_FILLED, $timeFilled);
$updateClause->add(CcShowInstancesPeer::LAST_SCHEDULED, $now);
BasePeer::doUpdate($whereClause, $updateClause, $con);
$con->commit();
Logging::info("finished fill");
$con->commit();
Logging::info('finished fill');
} catch (Exception $e) {
$con->rollback();
Logging::info("Error filling linked shows: ".$e->getMessage());
Logging::info('Error filling linked shows: ' . $e->getMessage());
exit();
}
}
@ -322,10 +341,10 @@ class Application_Service_SchedulerService
foreach ($ccShow->getCcShowInstancess() as $ccShowInstance) {
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($ccShowInstance->getDbId())
->find();
->find()
;
if ($ccSchedules->isEmpty()) {
$nextStartDT = $ccShowInstance->getDbStarts(null);
foreach ($showStamp as $item) {
@ -344,16 +363,20 @@ class Application_Service_SchedulerService
->setDbCueOut($item->getDbCueOut())
->setDbInstanceId($ccShowInstance->getDbId())
->setDbPosition($item->getDbPosition())
->save();
->save()
;
$nextStartDT = self::findTimeDifference($endTimeDT,
Application_Model_Preference::GetDefaultCrossfadeDuration());
$nextStartDT = self::findTimeDifference(
$endTimeDT,
Application_Model_Preference::GetDefaultCrossfadeDuration()
);
} //foreach show item
$ccShowInstance
->setDbTimeFilled($timeFilled)
->setDbLastScheduled(gmdate(DEFAULT_TIMESTAMP_FORMAT))
->save();
->save()
;
}
}
}
@ -363,11 +386,11 @@ class Application_Service_SchedulerService
{
//Application_Common_Database::prepareAndExecute($delete_sql, array(), Application_Common_Database::EXECUTE);
$con = Propel::getConnection();
$query = $con->prepare("DELETE FROM cc_schedule WHERE instance_id = :instance_id");
$query = $con->prepare('DELETE FROM cc_schedule WHERE instance_id = :instance_id');
$query->bindParam(':instance_id', $instanceId);
$query->execute();
}
/*
private static function replaceInstanceContentCheck($currentShowStamp, $showStamp, $instance_id)
{
@ -398,7 +421,7 @@ class Application_Service_SchedulerService
//If we get here, the content in the show instance is the same
// as what we want to replace it with, so we can leave as is
return false;
}*/
@ -407,8 +430,8 @@ class Application_Service_SchedulerService
try {
$ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
$instances = array();
$instanceIds = array();
$instances = [];
$instanceIds = [];
if ($ccShowInstance->getCcShow()->isLinked()) {
foreach ($ccShowInstance->getCcShow()->getFutureCcShowInstancess() as $instance) {
@ -427,16 +450,18 @@ class Application_Service_SchedulerService
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN)
->setDistinct(CcSchedulePeer::FILE_ID)
->find();
$fileIds = array();
->find()
;
$fileIds = [];
foreach ($ccSchedules as $ccSchedule) {
$fileIds[] = $ccSchedule->getDbFileId();
}
/* Clear out the schedule */
// Clear out the schedule
CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN)
->delete();
->delete()
;
/* Now that the schedule has been cleared we need to make
* sure we do not update the is_scheduled flag for tracks
@ -464,27 +489,25 @@ class Application_Service_SchedulerService
return true;
} catch (Exception $e) {
Logging::info($e->getMessage());
return false;
}
}
/*
* TODO in the future this should probably support webstreams.
*/
public function updateFutureIsScheduled($scheduleId, $status)
// TODO in the future this should probably support webstreams.
public function updateFutureIsScheduled($scheduleId, $status)
{
$sched = CcScheduleQuery::create()->findPk($scheduleId);
$redraw = false;
if (isset($sched)) {
$fileId = $sched->getDbFileId();
if (isset($fileId)) {
$redraw = Application_Model_StoredFile::setIsScheduled($fileId, $status);
}
}
return $redraw;
$sched = CcScheduleQuery::create()->findPk($scheduleId);
$redraw = false;
if (isset($sched)) {
$fileId = $sched->getDbFileId();
if (isset($fileId)) {
$redraw = Application_Model_StoredFile::setIsScheduled($fileId, $status);
}
}
return $redraw;
}
}