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

@ -11,7 +11,7 @@ class Application_Service_CalendarService
if (!is_null($instanceId)) {
$this->ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
if (is_null($this->ccShowInstance)) {
throw new Exception("Instance does not exist");
throw new Exception('Instance does not exist');
}
$this->ccShow = $this->ccShowInstance->getCcShow();
}
@ -21,12 +21,11 @@ class Application_Service_CalendarService
}
/**
*
* Enter description here ...
*/
public function makeContextMenu()
{
$menu = array();
$menu = [];
$now = time();
$baseUrl = Application_Common_OsPath::getBaseDir();
$isAdminOrPM = $this->currentUser->isAdminOrPM();
@ -43,87 +42,83 @@ class Application_Service_CalendarService
//show has ended
if ($now > $end) {
if ($this->ccShowInstance->isRecorded()) {
$ccFile = $this->ccShowInstance->getCcFiles();
if (!isset($ccFile)) {
$menu["error when recording"] = array (
"name" => _("Record file doesn't exist"),
"icon" => "error");
}else {
$menu["view_recorded"] = array(
"name" => _("View Recorded File Metadata"),
"icon" => "overview",
"url" => $baseUrl."library/edit-file-md/id/".$ccFile->getDbId());
$menu['error when recording'] = [
'name' => _("Record file doesn't exist"),
'icon' => 'error', ];
} else {
$menu['view_recorded'] = [
'name' => _('View Recorded File Metadata'),
'icon' => 'overview',
'url' => $baseUrl . 'library/edit-file-md/id/' . $ccFile->getDbId(), ];
}
} else {
$menu["content"] = array(
$menu['content'] = [
// "name"=> _("Show Content"),
"name"=> _("View"),
"icon" => "overview",
"url" => $baseUrl."schedule/show-content-dialog");
'name' => _('View'),
'icon' => 'overview',
'url' => $baseUrl . 'schedule/show-content-dialog', ];
}
} else {
// Show content can be modified from the calendar if:
// the user is admin or hosting the show,
// the show is not recorded
$currentShow = Application_Model_Show::getCurrentShow();
$currentShowId = count($currentShow) == 1 ? $currentShow[0]["id"] : null;
$currentShowId = count($currentShow) == 1 ? $currentShow[0]['id'] : null;
$showIsLinked = $this->ccShow->isLinked();
//user can add/remove content if the show has not ended
if ($now < $end && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded()) {
//if the show is not linked OR if the show is linked AND not the current playing show
//the user can add/remove content
if (!$showIsLinked || ($showIsLinked && $currentShowId != $this->ccShow->getDbId())) {
$menu["schedule"] = array(
if (!$showIsLinked || ($showIsLinked && $currentShowId != $this->ccShow->getDbId())) {
$menu['schedule'] = [
// "name"=> _("Add / Remove Content"),
"name" => _("Schedule Tracks"),
"icon" => "add-remove-content",
"url" => $baseUrl."showbuilder/builder-dialog/");
'name' => _('Schedule Tracks'),
'icon' => 'add-remove-content',
'url' => $baseUrl . 'showbuilder/builder-dialog/', ];
}
}
//"Show Content" should be a menu item at all times except when
//the show is recorded
if (!$this->ccShowInstance->isRecorded()) {
$menu["content"] = array(
$menu['content'] = [
// "name"=> _("Show Content"),
"name"=> _("View"),
"icon" => "overview",
"url" => $baseUrl."schedule/show-content-dialog");
'name' => _('View'),
'icon' => 'overview',
'url' => $baseUrl . 'schedule/show-content-dialog', ];
}
//user can remove all content if the show has not started
if ($now < $start && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded() ) {
if ($now < $start && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded()) {
//if the show is not linked OR if the show is linked AND not the current playing show
//the user can remove all content
if (!$showIsLinked || ($showIsLinked && $currentShowId != $this->ccShow->getDbId())) {
$menu["clear"] = array(
// "name"=> _("Remove All Content"),
"name"=> _("Clear Show"),
"icon" => "remove-all-content",
"url" => $baseUrl."schedule/clear-show");
if (!$showIsLinked || ($showIsLinked && $currentShowId != $this->ccShow->getDbId())) {
$menu['clear'] = [
// "name"=> _("Remove All Content"),
'name' => _('Clear Show'),
'icon' => 'remove-all-content',
'url' => $baseUrl . 'schedule/clear-show', ];
}
}
//show is currently playing and user is admin
if ($start <= $now && $now < $end && $isAdminOrPM) {
// Menu separator
$menu["sep1"] = "-----------";
$menu['sep1'] = '-----------';
if ($this->ccShowInstance->isRecorded()) {
$menu["cancel_recorded"] = array(
$menu['cancel_recorded'] = [
// "name"=> _("Cancel Current Show"),
"name"=> _("Cancel Show"),
"icon" => "delete");
'name' => _('Cancel Show'),
'icon' => 'delete', ];
} else {
$menu["cancel"] = array(
$menu['cancel'] = [
// "name"=> _("Cancel Current Show"),
"name"=> _("Cancel Show"),
"icon" => "delete");
'name' => _('Cancel Show'),
'icon' => 'delete', ];
}
}
@ -137,91 +132,92 @@ class Application_Service_CalendarService
if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) {
// Menu separator
$menu["sep2"] = "-----------";
$menu['sep2'] = '-----------';
if ($isRepeating) {
if ($populateInstance) {
$menu["edit"] = array(
$menu['edit'] = [
// "name" => _("Edit This Instance"),
"name" => _("Edit Instance"),
"icon" => "edit",
"url" => $baseUrl . "Schedule/populate-repeating-show-instance-form"
);
'name' => _('Edit Instance'),
'icon' => 'edit',
'url' => $baseUrl . 'Schedule/populate-repeating-show-instance-form',
];
} else {
$menu["edit"] = array(
"name" => _("Edit"),
"icon" => "edit",
"items" => array()
);
$menu['edit'] = [
'name' => _('Edit'),
'icon' => 'edit',
'items' => [],
];
$menu["edit"]["items"]["all"] = array(
"name" => _("Edit Show"),
"icon" => "edit",
"url" => $baseUrl . "Schedule/populate-show-form"
);
$menu['edit']['items']['all'] = [
'name' => _('Edit Show'),
'icon' => 'edit',
'url' => $baseUrl . 'Schedule/populate-show-form',
];
$menu["edit"]["items"]["instance"] = array(
$menu['edit']['items']['instance'] = [
// "name" => _("Edit This Instance"),
"name" => _("Edit Instance"),
"icon" => "edit",
"url" => $baseUrl . "Schedule/populate-repeating-show-instance-form"
);
'name' => _('Edit Instance'),
'icon' => 'edit',
'url' => $baseUrl . 'Schedule/populate-repeating-show-instance-form',
];
}
} else {
$menu["edit"] = array(
"name"=> _("Edit Show"),
"icon" => "edit",
"_type"=>"all",
"url" => $baseUrl."Schedule/populate-show-form");
$menu['edit'] = [
'name' => _('Edit Show'),
'icon' => 'edit',
'_type' => 'all',
'url' => $baseUrl . 'Schedule/populate-show-form', ];
}
}
//show hasn't started yet and user is admin
if ($now < $start && $isAdminOrPM) {
// Menu separator
$menu["sep3"] = "-----------";
$menu['sep3'] = '-----------';
//show is repeating so give user the option to delete all
//repeating instances or just the one
if ($isRepeating) {
$menu["del"] = array(
"name"=> _("Delete"),
"icon" => "delete",
"items" => array());
$menu['del'] = [
'name' => _('Delete'),
'icon' => 'delete',
'items' => [], ];
$menu["del"]["items"]["single"] = array(
$menu['del']['items']['single'] = [
// "name"=> _("Delete This Instance"),
"name"=> _("Delete Instance"),
"icon" => "delete",
"url" => $baseUrl."schedule/delete-show-instance");
'name' => _('Delete Instance'),
'icon' => 'delete',
'url' => $baseUrl . 'schedule/delete-show-instance', ];
$menu["del"]["items"]["following"] = array(
$menu['del']['items']['following'] = [
// "name"=> _("Delete This Instance and All Following"),
"name"=> _("Delete Instance and All Following"),
"icon" => "delete",
"url" => $baseUrl."schedule/delete-show");
'name' => _('Delete Instance and All Following'),
'icon' => 'delete',
'url' => $baseUrl . 'schedule/delete-show', ];
} elseif ($populateInstance) {
$menu["del"] = array(
"name"=> _("Delete"),
"icon" => "delete",
"url" => $baseUrl."schedule/delete-show-instance");
$menu['del'] = [
'name' => _('Delete'),
'icon' => 'delete',
'url' => $baseUrl . 'schedule/delete-show-instance', ];
} else {
$menu["del"] = array(
"name"=> _("Delete"),
"icon" => "delete",
"url" => $baseUrl."schedule/delete-show");
$menu['del'] = [
'name' => _('Delete'),
'icon' => 'delete',
'url' => $baseUrl . 'schedule/delete-show', ];
}
}
}
return $menu;
}
/**
*
* Enter description here ...
*
* @param DateTime $dateTime object to add deltas to
* @param int $deltaDay delta days show moved
* @param int $deltaMin delta minutes show moved
* @param int $deltaDay delta days show moved
* @param int $deltaMin delta minutes show moved
*/
public static function addDeltas($dateTime, $deltaDay, $deltaMin)
{
@ -251,7 +247,7 @@ class Application_Service_CalendarService
private function validateShowMove($deltaDay, $deltaMin)
{
if (!$this->currentUser->isAdminOrPM()) {
throw new Exception(_("Permission denied"));
throw new Exception(_('Permission denied'));
}
if ($this->ccShow->isRepeating()) {
@ -275,7 +271,7 @@ class Application_Service_CalendarService
$endsDateTime->setTimezone(new DateTimeZone($showTimezone));
$duration = $startsDateTime->diff($endsDateTime);
$newStartsDateTime = self::addDeltas($startsDateTime, $deltaDay, $deltaMin);
/* WARNING: Do not separately add a time delta to the start and end times because
that does not preserve the duration across a DST time change.
@ -283,9 +279,9 @@ class Application_Service_CalendarService
BUT, 6am - 3 hours = 3am also!
So when a DST change occurs, adding the deltas like this
separately does not conserve the duration of a show.
Since that's what we want (otherwise we'll get a zero length show),
Since that's what we want (otherwise we'll get a zero length show),
we calculate the show duration FIRST, then we just add that on
to the start time to calculate the end time.
to the start time to calculate the end time.
This is a safer approach.
The key lesson here is that in general: duration != end - start
... so be careful!
@ -293,10 +289,10 @@ class Application_Service_CalendarService
//$newEndsDateTime = self::addDeltas($endsDateTime, $deltaDay, $deltaMin); <--- Wrong, don't do it.
$newEndsDateTime = clone $newStartsDateTime;
$newEndsDateTime = $newEndsDateTime->add($duration);
//convert our new starts/ends to UTC.
$newStartsDateTime->setTimezone(new DateTimeZone("UTC"));
$newEndsDateTime->setTimezone(new DateTimeZone("UTC"));
$newStartsDateTime->setTimezone(new DateTimeZone('UTC'));
$newEndsDateTime->setTimezone(new DateTimeZone('UTC'));
if ($today_timestamp > $newStartsDateTime->getTimestamp()) {
throw new Exception(_("Can't move show into past"));
@ -304,9 +300,13 @@ class Application_Service_CalendarService
//check if show is overlapping
$overlapping = Application_Model_Schedule::checkOverlappingShows(
$newStartsDateTime, $newEndsDateTime, true, $this->ccShowInstance->getDbId());
$newStartsDateTime,
$newEndsDateTime,
true,
$this->ccShowInstance->getDbId()
);
if ($overlapping) {
throw new Exception(_("Cannot schedule overlapping shows"));
throw new Exception(_('Cannot schedule overlapping shows'));
}
if ($this->ccShow->isRecorded()) {
@ -316,7 +316,8 @@ class Application_Service_CalendarService
$rebroadcasts = CcShowInstancesQuery::create()
->filterByDbOriginalShow($this->ccShow->getDbId())
->filterByDbStarts($minRebroadcastStart->format(DEFAULT_TIMESTAMP_FORMAT), Criteria::LESS_THAN)
->find();
->find()
;
if (count($rebroadcasts) > 0) {
throw new Exception(_("Can't move a recorded show less than 1 hour before its rebroadcasts."));
@ -326,20 +327,23 @@ class Application_Service_CalendarService
if ($this->ccShow->isRebroadcast()) {
$recordedShow = CcShowInstancesQuery::create()
->filterByCcShow($this->ccShowInstance->getDbOriginalShow())
->findOne();
->findOne()
;
if (is_null($recordedShow)) {
$this->ccShowInstance->delete();
throw new Exception(_("Show was deleted because recorded show does not exist!"));
throw new Exception(_('Show was deleted because recorded show does not exist!'));
}
$recordEndDateTime = new DateTime($recordedShow->getDbEnds(), new DateTimeZone("UTC"));
$recordEndDateTime = new DateTime($recordedShow->getDbEnds(), new DateTimeZone('UTC'));
$newRecordEndDateTime = self::addDeltas($recordEndDateTime, 0, 60);
if ($newStartsDateTime->getTimestamp() < $newRecordEndDateTime->getTimestamp()) {
throw new Exception(_("Must wait 1 hour to rebroadcast."));
throw new Exception(_('Must wait 1 hour to rebroadcast.'));
}
}
return array($newStartsDateTime, $newEndsDateTime);
return [$newStartsDateTime, $newEndsDateTime];
}
public function moveShow($deltaDay, $deltaMin)
@ -350,14 +354,17 @@ class Application_Service_CalendarService
//new starts,ends are in UTC
list($newStartsDateTime, $newEndsDateTime) = $this->validateShowMove(
$deltaDay, $deltaMin);
$deltaDay,
$deltaMin
);
$oldStartDateTime = $this->ccShowInstance->getDbStarts(null);
$this->ccShowInstance
->setDbStarts($newStartsDateTime)
->setDbEnds($newEndsDateTime)
->save($con);
->save($con)
;
if (!$this->ccShowInstance->getCcShow()->isRebroadcast()) {
//we can get the first show day because we know the show is
@ -365,20 +372,24 @@ class Application_Service_CalendarService
$ccShowDay = $this->ccShow->getFirstCcShowDay();
$showTimezone = new DateTimeZone($ccShowDay->getDbTimezone());
$ccShowDay
->setDbFirstShow($newStartsDateTime->setTimezone($showTimezone)->format("Y-m-d"))
->setDbStartTime($newStartsDateTime->format("H:i"))
->save($con);
->setDbFirstShow($newStartsDateTime->setTimezone($showTimezone)->format('Y-m-d'))
->setDbStartTime($newStartsDateTime->format('H:i'))
->save($con)
;
}
$diff = $newStartsDateTime->getTimestamp() - $oldStartDateTime->getTimestamp();
Application_Service_SchedulerService::updateScheduleStartTime(
array($this->ccShowInstance->getDbId()), $diff);
[$this->ccShowInstance->getDbId()],
$diff
);
$con->commit();
Application_Model_RabbitMq::PushSchedule();
} catch (Exception $e) {
$con->rollback();
return $e->getMessage();
}
}
@ -396,5 +407,4 @@ class Application_Service_CalendarService
return $e->getMessage();
}
}
}

View file

@ -1,21 +1,22 @@
<?php
class CeleryServiceFactory {
class CeleryServiceFactory
{
/**
* Given an identifying string, get a ThirdPartyCeleryService object of that type
* Given an identifying string, get a ThirdPartyCeleryService object of that type.
*
* @param $serviceName string the name of the service to create
*
* @return Application_Service_ThirdPartyCeleryService|null
* @return null|Application_Service_ThirdPartyCeleryService
*/
public static function getService($serviceName) {
switch($serviceName) {
public static function getService($serviceName)
{
switch ($serviceName) {
case PODCAST_SERVICE_NAME:
return new Application_Service_PodcastEpisodeService();
default:
return null;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -2,8 +2,7 @@
class Application_Service_MediaService
{
const PENDING_FILE_TIMEOUT_SECONDS = 3600;
public const PENDING_FILE_TIMEOUT_SECONDS = 3600;
/**
* @var array store an internal array of the pending files so we don't have
@ -12,24 +11,27 @@ class Application_Service_MediaService
private static $_pendingFiles;
/** Move (or copy) a file to the stor/organize directory and send it off to the
analyzer to be processed.
* analyzer to be processed.
*
* @param $callbackUrl
* @param $filePath string Path to the local file to import to the library
* @param $originalFilename string The original filename, if you want it to be preserved after import.
* @param $ownerId string The ID of the user that will own the file inside Airtime.
* @param $originalFilename string The original filename, if you want it to be preserved after import
* @param $ownerId string The ID of the user that will own the file inside Airtime
* @param $copyFile bool True if you want to copy the file to the "organize" directory, false if you want to move it (default)
* @return Ambigous
*
* @throws Exception
*
* @return Ambigous
*/
public static function importFileToLibrary($callbackUrl, $filePath, $originalFilename, $ownerId, $copyFile)
{
$CC_CONFIG = Config::getConfig();
$apiKey = $CC_CONFIG["apiKey"][0];
$apiKey = $CC_CONFIG['apiKey'][0];
$importedStorageDirectory = "";
if ($CC_CONFIG["current_backend"] == "file") {
$importedStorageDirectory = '';
if ($CC_CONFIG['current_backend'] == 'file') {
$storDir = Application_Model_MusicDir::getStorDir();
$importedStorageDirectory = $storDir->getDirectory() . "/imported/" . $ownerId;
$importedStorageDirectory = $storDir->getDirectory() . '/imported/' . $ownerId;
}
//Copy the temporary file over to the "organize" folder so that it's off our webserver
@ -38,24 +40,28 @@ class Application_Service_MediaService
//Dispatch a message to libretime-analyzer through RabbitMQ,
//notifying it that there's a new upload to process!
$storageBackend = new ProxyStorageBackend($CC_CONFIG["current_backend"]);
Application_Model_RabbitMq::SendMessageToAnalyzer($newTempFilePath,
$importedStorageDirectory, basename($originalFilename),
$callbackUrl, $apiKey,
$CC_CONFIG["current_backend"],
$storageBackend->getFilePrefix());
$storageBackend = new ProxyStorageBackend($CC_CONFIG['current_backend']);
Application_Model_RabbitMq::SendMessageToAnalyzer(
$newTempFilePath,
$importedStorageDirectory,
basename($originalFilename),
$callbackUrl,
$apiKey,
$CC_CONFIG['current_backend'],
$storageBackend->getFilePrefix()
);
return $newTempFilePath;
}
/**
* @param $fileId
* @param bool $inline Set the Content-Disposition header to inline to prevent a download dialog from popping up (or attachment if false)
*
* @throws Exception
* @throws LibreTimeFileNotFoundException
*/
public static function streamFileDownload($fileId, $inline=false)
public static function streamFileDownload($fileId, $inline = false)
{
$media = Application_Model_StoredFile::RecallById($fileId);
if ($media == null) {
@ -64,7 +70,7 @@ class Application_Service_MediaService
// Make sure we don't have some wrong result because of caching
clearstatcache();
$filePath = "";
$filePath = '';
if ($media->getPropelOrm()->isValidPhysicalFile()) {
$filename = $media->getPropelOrm()->getFilename();
@ -96,10 +102,12 @@ class Application_Service_MediaService
do {
//Read from $filePath and stream it to the browser.
$filePath = array_shift($filePaths);
try {
$size= $media->getFileSize();
$size = $media->getFileSize();
$mimeType = $media->getPropelOrm()->getDbMime();
Application_Common_FileIO::smartReadFile($filePath, $size, $mimeType);
break; //Break out of the loop if we successfully read the file!
} catch (LibreTimeFileNotFoundException $e) {
//If we have no alternate filepaths left, then let the exception bubble up.
@ -111,43 +119,44 @@ class Application_Service_MediaService
} while (sizeof($filePaths) > 0);
exit;
} else {
throw new LibreTimeFileNotFoundException($filePath);
}
throw new LibreTimeFileNotFoundException($filePath);
}
/**
* Check if there are any files that have been stuck
* in Pending status for over an hour
* in Pending status for over an hour.
*
* @return bool true if there are any files stuck pending,
* otherwise false
*/
public static function areFilesStuckInPending() {
public static function areFilesStuckInPending()
{
$oneHourAgo = gmdate(DEFAULT_TIMESTAMP_FORMAT, (microtime(true) - self::PENDING_FILE_TIMEOUT_SECONDS));
self::$_pendingFiles = CcFilesQuery::create()
->filterByDbImportStatus(CcFiles::IMPORT_STATUS_PENDING)
->filterByDbUtime($oneHourAgo, Criteria::LESS_EQUAL)
->find();
->find()
;
$pendingEpisodes = Application_Service_PodcastEpisodeService::getStuckPendingImports();
return !self::$_pendingFiles->isEmpty() || !empty($pendingEpisodes);
}
/**
* Clean up stuck imports by changing their import status to Failed
* Clean up stuck imports by changing their import status to Failed.
*/
public static function clearStuckPendingImports() {
public static function clearStuckPendingImports()
{
$pendingEpisodes = Application_Service_PodcastEpisodeService::getStuckPendingImports();
foreach (self::$_pendingFiles as $file) {
/** @var $file CcFiles */
// @var $file CcFiles
$file->setDbImportStatus(CcFiles::IMPORT_STATUS_FAILED)->save();
}
foreach ($pendingEpisodes as $episode) {
/** @var $episode PodcastEpisodes */
// @var $episode PodcastEpisodes
$episode->delete();
}
}
}

View file

@ -1,18 +1,21 @@
<?php
class PodcastEpisodeNotFoundException extends Exception {}
class PodcastEpisodeNotFoundException extends Exception
{
}
class DuplicatePodcastEpisodeException extends Exception {}
class DuplicatePodcastEpisodeException extends Exception
{
}
class Application_Service_PodcastEpisodeService extends Application_Service_ThirdPartyCeleryService implements Publish
{
/**
* Arbitrary constant identifiers for the internal tasks array
* Arbitrary constant identifiers for the internal tasks array.
*/
public const DOWNLOAD = 'download';
const DOWNLOAD = 'download';
const PENDING_EPISODE_TIMEOUT_SECONDS = 900;
public const PENDING_EPISODE_TIMEOUT_SECONDS = 900;
/**
* @var string service name to store in ThirdPartyTrackReferences database
@ -28,90 +31,98 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
* @var array map of constant identifiers to Celery task names
*/
protected static $_CELERY_TASKS = [
self::DOWNLOAD => 'podcast-download'
self::DOWNLOAD => 'podcast-download',
];
private static $privateFields = array(
"id"
);
private static $privateFields = [
'id',
];
/**
* Utility function to import and download a single episode
* Utility function to import and download a single episode.
*
* @param int $podcastId ID of the podcast the episode should belong to
* @param array $episode array of episode data to store
* @param int $podcastId ID of the podcast the episode should belong to
* @param array $episode array of episode data to store
*
* @return PodcastEpisodes the stored PodcastEpisodes object
*/
public function importEpisode($podcastId, $episode) {
public function importEpisode($podcastId, $episode)
{
$e = $this->addPlaceholder($podcastId, $episode);
$p = $e->getPodcast();
$this->_download($e->getDbId(), $e->getDbDownloadUrl(), $p->getDbTitle(), $this->_getAlbumOverride($p), $episode["title"]);
$this->_download($e->getDbId(), $e->getDbDownloadUrl(), $p->getDbTitle(), $this->_getAlbumOverride($p), $episode['title']);
return $e;
}
/**
* Given an array of episodes, store them in the database as placeholder objects until
* they can be processed by Celery
* they can be processed by Celery.
*
* @param int $podcastId Podcast object identifier
* @param array $episodes array of podcast episodes
* @param int $podcastId Podcast object identifier
* @param array $episodes array of podcast episodes
*
* @return array the stored PodcastEpisodes objects
*/
public function addPodcastEpisodePlaceholders($podcastId, $episodes) {
$storedEpisodes = array();
public function addPodcastEpisodePlaceholders($podcastId, $episodes)
{
$storedEpisodes = [];
foreach ($episodes as $episode) {
try {
$e = $this->addPlaceholder($podcastId, $episode);
} catch(DuplicatePodcastEpisodeException $ex) {
} catch (DuplicatePodcastEpisodeException $ex) {
Logging::warn($ex->getMessage());
continue;
}
array_push($storedEpisodes, $e);
}
return $storedEpisodes;
}
/**
* Given an episode, store it in the database as a placeholder object until
* it can be processed by Celery
* it can be processed by Celery.
*
* @param int $podcastId Podcast object identifier
* @param array $episode array of podcast episode data
*
* @return PodcastEpisodes the stored PodcastEpisodes object
* @param int $podcastId Podcast object identifier
* @param array $episode array of podcast episode data
*
* @throws DuplicatePodcastEpisodeException
*
* @return PodcastEpisodes the stored PodcastEpisodes object
*/
public function addPlaceholder($podcastId, $episode) {
$existingEpisode = PodcastEpisodesQuery::create()->findOneByDbEpisodeGuid($episode["guid"]);
public function addPlaceholder($podcastId, $episode)
{
$existingEpisode = PodcastEpisodesQuery::create()->findOneByDbEpisodeGuid($episode['guid']);
if (!empty($existingEpisode)) {
throw new DuplicatePodcastEpisodeException(sprintf("Episode already exists for podcast: %s, guid: %s\n", $episode['podcast_id'], $episode['guid']));
}
// We need to check whether the array is parsed directly from the SimplePie
// feed object, or whether it's passed in as json
$enclosure = $episode["enclosure"];
$url = $enclosure instanceof SimplePie_Enclosure ? $enclosure->get_link() : $enclosure["link"];
return $this->_buildEpisode($podcastId, $url, $episode["guid"], $episode["pub_date"], $episode["title"], $episode["description"]);
$enclosure = $episode['enclosure'];
$url = $enclosure instanceof SimplePie_Enclosure ? $enclosure->get_link() : $enclosure['link'];
return $this->_buildEpisode($podcastId, $url, $episode['guid'], $episode['pub_date'], $episode['title'], $episode['description']);
}
/**
* Given episode parameters, construct and store a basic PodcastEpisodes object
* Given episode parameters, construct and store a basic PodcastEpisodes object.
*
* @param int $podcastId the podcast the episode belongs to
* @param string $url the download URL for the episode
* @param string $guid the unique id for the episode. Often the same as the download URL
* @param string $publicationDate the publication date of the episode
* @param string $title the title of the episode
* @param string $description the description of the epsiode
*
* @return PodcastEpisodes the newly created PodcastEpisodes object
* @param int $podcastId the podcast the episode belongs to
* @param string $url the download URL for the episode
* @param string $guid the unique id for the episode. Often the same as the download URL
* @param string $publicationDate the publication date of the episode
* @param string $title the title of the episode
* @param string $description the description of the epsiode
*
* @throws Exception
* @throws PropelException
*
* @return PodcastEpisodes the newly created PodcastEpisodes object
*/
private function _buildEpisode($podcastId, $url, $guid, $publicationDate, $title = NULL, $description = NULL) {
private function _buildEpisode($podcastId, $url, $guid, $publicationDate, $title = null, $description = null)
{
$e = new PodcastEpisodes();
$e->setDbPodcastId($podcastId);
$e->setDbDownloadUrl($url);
@ -120,60 +131,66 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
$e->setDbEpisodeTitle($title);
$e->setDbEpisodeDescription($description);
$e->save();
return $e;
}
/**
* Given an array of episodes, extract the IDs and download URLs and send them to Celery
* Given an array of episodes, extract the IDs and download URLs and send them to Celery.
*
* @param array $episodes array of podcast episodes
*/
public function downloadEpisodes($episodes) {
public function downloadEpisodes($episodes)
{
/** @var PodcastEpisodes $episode */
foreach($episodes as $episode) {
foreach ($episodes as $episode) {
$podcast = $episode->getPodcast();
$this->_download($episode->getDbId(), $episode->getDbDownloadUrl(), $podcast->getDbTitle(), $this->_getAlbumOverride($podcast), $episode->getDbEpisodeTitle());
}
}
/**
* check if there is a podcast specific album override
* check if there is a podcast specific album override.
*
* @param object $podcast podcast object
*
* @return boolean
* @return bool
*/
private function _getAlbumOverride($podcast) {
private function _getAlbumOverride($podcast)
{
$override = Application_Model_Preference::GetPodcastAlbumOverride();
$podcast_override = $podcast->toArray();
$podcast_override = $podcast_override['DbAlbumOverride'];
if ($podcast_override) {
$override = $podcast_override;
}
return $override;
}
/**
* Given an episode ID and a download URL, send a Celery task
* to download an RSS feed track
* to download an RSS feed track.
*
* @param int $id episode unique ID
* @param string $url download url for the episode
* @param string $title title of podcast to be downloaded - added as album to track metadata
* @param boolean $album_override should we override the album name when downloading
* @param int $id episode unique ID
* @param string $url download url for the episode
* @param string $title title of podcast to be downloaded - added as album to track metadata
* @param bool $album_override should we override the album name when downloading
* @param null|mixed $track_title
*/
private function _download($id, $url, $title, $album_override, $track_title = null) {
private function _download($id, $url, $title, $album_override, $track_title = null)
{
$CC_CONFIG = Config::getConfig();
$stationUrl = Application_Common_HTTPHelper::getStationUrl();
$stationUrl .= substr($stationUrl, -1) == '/' ? '' : '/';
$data = array(
'id' => $id,
'url' => $url,
'callback_url' => $stationUrl . 'rest/media',
'api_key' => $CC_CONFIG["apiKey"][0],
'podcast_name' => $title,
$data = [
'id' => $id,
'url' => $url,
'callback_url' => $stationUrl . 'rest/media',
'api_key' => $CC_CONFIG['apiKey'][0],
'podcast_name' => $title,
'album_override' => $album_override,
'track_title' => $track_title);
'track_title' => $track_title, ];
$task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
// Get the created ThirdPartyTaskReference and set the episode ID so
// we can remove the placeholder if the import ends up stuck in a pending state
@ -182,19 +199,20 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
}
/**
* Update a ThirdPartyTrackReferences object for a completed upload
* Update a ThirdPartyTrackReferences object for a completed upload.
*
* @param $task CeleryTasks the completed CeleryTasks object
* @param $episodeId int PodcastEpisodes identifier
* @param $episode stdClass simple object containing Podcast episode information
* @param $status string Celery task status
*
* @return ThirdPartyTrackReferences the updated ThirdPartyTrackReferences object
*
* @throws Exception
* @throws PropelException
*
* @return ThirdPartyTrackReferences the updated ThirdPartyTrackReferences object
*/
public function updateTrackReference($task, $episodeId, $episode, $status) {
public function updateTrackReference($task, $episodeId, $episode, $status)
{
$ref = parent::updateTrackReference($task, $episodeId, $episode, $status);
$ref->setDbForeignId($episode->episodeid)->save();
$dbEpisode = PodcastEpisodesQuery::create()->findOneByDbId($episode->episodeid);
@ -202,7 +220,8 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
try {
// If the placeholder for the episode is somehow removed, return with a warning
if (!$dbEpisode) {
Logging::warn("Celery task $task episode $episode->episodeid unsuccessful: episode placeholder removed");
Logging::warn("Celery task {$task} episode {$episode->episodeid} unsuccessful: episode placeholder removed");
return $ref;
}
@ -210,12 +229,12 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
if ($status == CELERY_SUCCESS_STATUS && $episode->status == 1) {
$dbEpisode->setDbFileId($episode->fileid)->save();
} else {
Logging::warn("Celery task $task episode $episode->episodeid unsuccessful with message $episode->error");
Logging::warn("Celery task {$task} episode {$episode->episodeid} unsuccessful with message {$episode->error}");
$dbEpisode->delete();
}
} catch (Exception $e) {
$dbEpisode->delete();
Logging::warn("Catastrophic failure updating from task $task, recovering by deleting episode row.\n
Logging::warn("Catastrophic failure updating from task {$task}, recovering by deleting episode row.\n
This can occur if the episode's corresponding CcFile is deleted before being processed.");
}
@ -223,13 +242,14 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
}
/**
* Publish the file with the given file ID to the station podcast
* Publish the file with the given file ID to the station podcast.
*
* @param int $fileId ID of the file to be published
*/
public function publish($fileId) {
public function publish($fileId)
{
$id = Application_Model_Preference::getStationPodcastId();
$url = $guid = Application_Common_HTTPHelper::getStationUrl()."rest/media/$fileId/download";
$url = $guid = Application_Common_HTTPHelper::getStationUrl() . "rest/media/{$fileId}/download";
if (!PodcastEpisodesQuery::create()
->filterByDbPodcastId($id)
->findOneByDbFileId($fileId)) { // Don't allow duplicate episodes
@ -239,20 +259,22 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
}
/**
* Unpublish the file with the given file ID from the station podcast
* Unpublish the file with the given file ID from the station podcast.
*
* @param int $fileId ID of the file to be unpublished
*/
public function unpublish($fileId) {
public function unpublish($fileId)
{
$id = Application_Model_Preference::getStationPodcastId();
PodcastEpisodesQuery::create()
->filterByDbPodcastId($id)
->findOneByDbFileId($fileId)
->delete();
->delete()
;
}
/**
* Fetch the publication status for the file with the given ID
* Fetch the publication status for the file with the given ID.
*
* @param int $fileId the ID of the file to check
*
@ -261,45 +283,55 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
* -1 if the file is in a pending state,
* 2 if the source is unreachable (disconnected)
*/
public function getPublishStatus($fileId) {
public function getPublishStatus($fileId)
{
$stationPodcast = StationPodcastQuery::create()
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId());
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId())
;
return (int) $stationPodcast->hasEpisodeForFile($fileId);
}
/**
* Find any episode placeholders that have been stuck pending (empty file ID) for over
* PENDING_EPISODE_TIMEOUT_SECONDS
* PENDING_EPISODE_TIMEOUT_SECONDS.
*
* @see Application_Service_PodcastEpisodeService::PENDING_EPISODE_TIMEOUT_SECONDS
*
* @return array the episode imports stuck in pending
*/
public static function getStuckPendingImports() {
public static function getStuckPendingImports()
{
$timeout = gmdate(DEFAULT_TIMESTAMP_FORMAT, (microtime(true) - self::PENDING_EPISODE_TIMEOUT_SECONDS));
$episodes = PodcastEpisodesQuery::create()
->filterByDbFileId()
->find();
$stuckImports = array();
->find()
;
$stuckImports = [];
foreach ($episodes as $episode) {
$ref = ThirdPartyTrackReferencesQuery::create()
->findOneByDbForeignId(strval($episode->getDbId()));
->findOneByDbForeignId(strval($episode->getDbId()))
;
if (!empty($ref)) {
$task = CeleryTasksQuery::create()
->filterByDbDispatchTime($timeout, Criteria::LESS_EQUAL)
->findOneByDbTrackReference($ref->getDbId());
->findOneByDbTrackReference($ref->getDbId())
;
if (!empty($task)) {
array_push($stuckImports, $episode);
}
}
}
return $stuckImports;
}
/**
* @param $episodeId
* @return array
*
* @throws PodcastEpisodeNotFoundException
*
* @return array
*/
public static function getPodcastEpisodeById($episodeId)
{
@ -315,29 +347,33 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
* Returns an array of Podcast episodes, with the option to paginate the results.
*
* @param $podcastId
* @param int $offset
* @param int $limit
* @param int $offset
* @param int $limit
* @param string $sortColumn
* @param string $sortDir "ASC" || "DESC"
* @return array
* @param string $sortDir "ASC" || "DESC"
*
* @throws PodcastNotFoundException
*
* @return array
*/
public function getPodcastEpisodes($podcastId,
$offset=0,
$limit=10,
$sortColumn=PodcastEpisodesPeer::PUBLICATION_DATE,
$sortDir="ASC")
{
public function getPodcastEpisodes(
$podcastId,
$offset = 0,
$limit = 10,
$sortColumn = PodcastEpisodesPeer::PUBLICATION_DATE,
$sortDir = 'ASC'
) {
$podcast = PodcastQuery::create()->findPk($podcastId);
if (!$podcast) {
throw new PodcastNotFoundException();
}
$sortDir = ($sortDir === "DESC") ? $sortDir = Criteria::DESC : Criteria::ASC;
$sortDir = ($sortDir === 'DESC') ? $sortDir = Criteria::DESC : Criteria::ASC;
$isStationPodcast = $podcastId == Application_Model_Preference::getStationPodcastId();
$episodes = PodcastEpisodesQuery::create()
->filterByDbPodcastId($podcastId);
->filterByDbPodcastId($podcastId)
;
if ($isStationPodcast && $limit != 0) {
$episodes = $episodes->setLimit($limit);
}
@ -346,7 +382,8 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
$episodes = $episodes->joinWith('PodcastEpisodes.CcFiles', Criteria::LEFT_JOIN)
->setOffset($offset)
->orderBy($sortColumn, $sortDir)
->find();
->find()
;
return $isStationPodcast ? $this->_getStationPodcastEpisodeArray($episodes)
: $this->_getImportedPodcastEpisodeArray($podcast, $episodes);
@ -354,59 +391,63 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
/**
* Given an array of PodcastEpisodes objects from the Station Podcast,
* convert the episode data into array form
* convert the episode data into array form.
*
* @param array $episodes array of PodcastEpisodes to convert
*
* @return array
*/
private function _getStationPodcastEpisodeArray($episodes) {
$episodesArray = array();
private function _getStationPodcastEpisodeArray($episodes)
{
$episodesArray = [];
foreach ($episodes as $episode) {
/** @var PodcastEpisodes $episode */
$episodeArr = $episode->toArray(BasePeer::TYPE_FIELDNAME, true, [], true);
array_push($episodesArray, $episodeArr);
}
return $episodesArray;
}
/**
* Given an ImportedPodcast object and an array of stored PodcastEpisodes objects,
* fetch all episodes from the podcast RSS feed, and serialize them in a readable form
* fetch all episodes from the podcast RSS feed, and serialize them in a readable form.
*
* TODO: there's definitely a better approach than this... we should be trying to create
* PodcastEpisdoes objects instead of our own arrays
*
* @param ImportedPodcast $podcast Podcast object to fetch the episodes for
* @param array $episodes array of PodcastEpisodes objects to
*
* @return array array of episode data
* @param ImportedPodcast $podcast Podcast object to fetch the episodes for
* @param array $episodes array of PodcastEpisodes objects to
*
* @throws CcFiles/LibreTimeFileNotFoundException
*
* @return array array of episode data
*/
public function _getImportedPodcastEpisodeArray($podcast, $episodes) {
public function _getImportedPodcastEpisodeArray($podcast, $episodes)
{
$rss = Application_Service_PodcastService::getPodcastFeed($podcast->getDbUrl());
$episodeIds = array();
$episodeFiles = array();
$episodeIds = [];
$episodeFiles = [];
foreach ($episodes as $e) {
/** @var PodcastEpisodes $e */
// @var PodcastEpisodes $e
array_push($episodeIds, $e->getDbEpisodeGuid());
$episodeFiles[$e->getDbEpisodeGuid()] = $e->getDbFileId();
}
$episodesArray = array();
$episodesArray = [];
foreach ($rss->get_items() as $item) {
/** @var SimplePie_Item $item */
// If the enclosure is empty or has not URL, this isn't a podcast episode (there's no audio data)
// technically podcasts shouldn't have multiple enclosures but often CMS add non-audio files
$enclosure = $item->get_enclosure();
$url = $enclosure instanceof SimplePie_Enclosure ? $enclosure->get_link() : $enclosure["link"];
$url = $enclosure instanceof SimplePie_Enclosure ? $enclosure->get_link() : $enclosure['link'];
if (empty($url)) {
continue;
}
// next we check and see if the enclosure is not an audio file - this can happen from improperly
// formatted podcasts and we instead will search through the enclosures and see if there is an audio item
// then we pass that on, otherwise we just pass the first item since it is probably an audio file
elseif (!(substr($enclosure->get_type(), 0, 5) === 'audio')) {
if (!(substr($enclosure->get_type(), 0, 5) === 'audio')) {
// this is a rather hackish way of accessing the enclosures but get_enclosures() didnt detect multiple
// enclosures at certain points so we search through them and then manually create an enclosure object
// if we find an audio file in an enclosure and send it off
@ -417,11 +458,12 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
if (is_array($testenclosures)) {
$numenclosures = sizeof($testenclosures);
// now we loop through and look for a audio file and then stop the loop at the first one we find
for ($i = 0; $i < $numenclosures + 1; $i++) {
for ($i = 0; $i < $numenclosures + 1; ++$i) {
$enclosure_attribs = array_values($testenclosures[$i]['attribs'])[0];
if (stripos($enclosure_attribs['type'], 'audio') !== false) {
$url = $enclosure_attribs['url'];
$enclosure = new SimplePie_Enclosure($enclosure_attribs['url'], $enclosure_attribs['type'], $length = $enclosure_attribs['length']);
break;
}
// if we didn't find an audio file we need to continue because there were no audio item enclosures
@ -430,8 +472,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
continue;
}
}
}
else {
} else {
continue;
}
} else {
@ -441,38 +482,40 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
$itemId = $item->get_id();
$ingested = in_array($itemId, $episodeIds) ? (empty($episodeFiles[$itemId]) ? -1 : 1) : 0;
$file = $ingested > 0 && !empty($episodeFiles[$itemId]) ?
CcFiles::getSanitizedFileById($episodeFiles[$itemId]) : array();
CcFiles::getSanitizedFileById($episodeFiles[$itemId]) : [];
// If the analyzer hasn't finished with the file, leave it as pending
if (!empty($file) && $file["import_status"] == CcFiles::IMPORT_STATUS_PENDING) {
if (!empty($file) && $file['import_status'] == CcFiles::IMPORT_STATUS_PENDING) {
$ingested = -1;
}
array_push($episodesArray, array(
"podcast_id" => $podcast->getDbId(),
"guid" => $itemId,
"ingested" => $ingested,
"title" => $item->get_title(),
array_push($episodesArray, [
'podcast_id' => $podcast->getDbId(),
'guid' => $itemId,
'ingested' => $ingested,
'title' => $item->get_title(),
// From the RSS spec best practices:
// 'An item's author element provides the e-mail address of the person who wrote the item'
"author" => $this->_buildAuthorString($item),
"description" => htmlspecialchars($item->get_description()),
"pub_date" => $item->get_gmdate(),
"link" => $url,
"enclosure" => $enclosure,
"file" => $file
));
'author' => $this->_buildAuthorString($item),
'description' => htmlspecialchars($item->get_description()),
'pub_date' => $item->get_gmdate(),
'link' => $url,
'enclosure' => $enclosure,
'file' => $file,
]);
}
return $episodesArray;
}
/**
* Construct a string representation of the author fields of a SimplePie_Item object
* Construct a string representation of the author fields of a SimplePie_Item object.
*
* @param SimplePie_Item $item the SimplePie_Item to extract the author data from
*
* @return string the string representation of the author data
*/
private function _buildAuthorString(SimplePie_Item $item) {
private function _buildAuthorString(SimplePie_Item $item)
{
$authorString = $author = $item->get_author();
if (!empty($author)) {
$authorString = $author->get_email();
@ -499,5 +542,4 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
unset($data[$key]);
}
}
}

View file

@ -12,4 +12,4 @@ class PodcastFactory
return Application_Service_PodcastService::createFromFeedUrl($feedUrl);
}
}
}

View file

@ -1,24 +1,25 @@
<?php
class InvalidPodcastException extends Exception
{
}
class InvalidPodcastException extends Exception {}
class PodcastNotFoundException extends Exception {}
class PodcastNotFoundException extends Exception
{
}
class Application_Service_PodcastService
{
// These fields should never be modified with POST/PUT data
private static $privateFields = array(
"id",
"url",
"type",
"owner"
);
private static $privateFields = [
'id',
'url',
'type',
'owner',
];
/**
* Returns parsed rss feed, or false if the given URL cannot be downloaded
* Returns parsed rss feed, or false if the given URL cannot be downloaded.
*
* @param string $feedUrl String containing the podcast feed URL
*
@ -31,6 +32,7 @@ class Application_Service_PodcastService
$feed->set_feed_url($feedUrl);
$feed->enable_cache(false);
$feed->init();
return $feed;
} catch (Exception $e) {
return false;
@ -38,13 +40,14 @@ class Application_Service_PodcastService
}
/** Creates a Podcast object from the given podcast URL.
* This is used by our Podcast REST API
* This is used by our Podcast REST API.
*
* @param string $feedUrl Podcast RSS Feed Url
*
* @return array Podcast Array with a full list of episodes
* @throws Exception
* @throws InvalidPodcastException
*
* @return array Podcast Array with a full list of episodes
*/
public static function createFromFeedUrl($feedUrl)
{
@ -60,55 +63,55 @@ class Application_Service_PodcastService
// Ensure we are only creating Podcast with the given URL, and excluding
// any extra data fields that may have been POSTED
$podcastArray = array();
$podcastArray["url"] = $feedUrl;
$podcastArray = [];
$podcastArray['url'] = $feedUrl;
$podcastArray["title"] = htmlspecialchars($rss->get_title());
$podcastArray["description"] = htmlspecialchars($rss->get_description());
$podcastArray["link"] = htmlspecialchars($rss->get_link());
$podcastArray["language"] = htmlspecialchars($rss->get_language());
$podcastArray["copyright"] = htmlspecialchars($rss->get_copyright());
$podcastArray['title'] = htmlspecialchars($rss->get_title());
$podcastArray['description'] = htmlspecialchars($rss->get_description());
$podcastArray['link'] = htmlspecialchars($rss->get_link());
$podcastArray['language'] = htmlspecialchars($rss->get_language());
$podcastArray['copyright'] = htmlspecialchars($rss->get_copyright());
$author = $rss->get_author();
$name = empty($author) ? "" : $author->get_name();
$podcastArray["creator"] = htmlspecialchars($name);
$name = empty($author) ? '' : $author->get_name();
$podcastArray['creator'] = htmlspecialchars($name);
$categories = array();
$categories = [];
if (is_array($rss->get_categories())) {
foreach ($rss->get_categories() as $category) {
array_push($categories, $category->get_scheme() . ":" . $category->get_term());
array_push($categories, $category->get_scheme() . ':' . $category->get_term());
}
}
$podcastArray["category"] = htmlspecialchars(implode($categories));
$podcastArray['category'] = htmlspecialchars(implode($categories));
//TODO: put in constants
$itunesChannel = "http://www.itunes.com/dtds/podcast-1.0.dtd";
$itunesChannel = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
$itunesSubtitle = $rss->get_channel_tags($itunesChannel, 'subtitle');
$podcastArray["itunes_subtitle"] = isset($itunesSubtitle[0]["data"]) ? $itunesSubtitle[0]["data"] : "";
$podcastArray['itunes_subtitle'] = isset($itunesSubtitle[0]['data']) ? $itunesSubtitle[0]['data'] : '';
$itunesCategory = $rss->get_channel_tags($itunesChannel, 'category');
$categoryArray = array();
$categoryArray = [];
if (is_array($itunesCategory)) {
foreach ($itunesCategory as $c => $data) {
foreach ($data["attribs"] as $attrib) {
array_push($categoryArray, $attrib["text"]);
foreach ($data['attribs'] as $attrib) {
array_push($categoryArray, $attrib['text']);
}
}
}
$podcastArray["itunes_category"] = implode(",", $categoryArray);
$podcastArray['itunes_category'] = implode(',', $categoryArray);
$itunesAuthor = $rss->get_channel_tags($itunesChannel, 'author');
$podcastArray["itunes_author"] = isset($itunesAuthor[0]["data"]) ? $itunesAuthor[0]["data"] : "";
$podcastArray['itunes_author'] = isset($itunesAuthor[0]['data']) ? $itunesAuthor[0]['data'] : '';
$itunesSummary = $rss->get_channel_tags($itunesChannel, 'summary');
$podcastArray["itunes_summary"] = isset($itunesSummary[0]["data"]) ? $itunesSummary[0]["data"] : "";
$podcastArray['itunes_summary'] = isset($itunesSummary[0]['data']) ? $itunesSummary[0]['data'] : '';
$itunesKeywords = $rss->get_channel_tags($itunesChannel, 'keywords');
$podcastArray["itunes_keywords"] = isset($itunesKeywords[0]["data"]) ? $itunesKeywords[0]["data"] : "";
$podcastArray['itunes_keywords'] = isset($itunesKeywords[0]['data']) ? $itunesKeywords[0]['data'] : '';
$itunesExplicit = $rss->get_channel_tags($itunesChannel, 'explicit');
$podcastArray["itunes_explicit"] = isset($itunesExplicit[0]["data"]) ? $itunesExplicit[0]["data"] : "";
$podcastArray['itunes_explicit'] = isset($itunesExplicit[0]['data']) ? $itunesExplicit[0]['data'] : '';
self::validatePodcastMetadata($podcastArray);
@ -130,10 +133,10 @@ class Application_Service_PodcastService
self::createPodcastSmartblockAndPlaylist($podcast);
}
return $podcast->toArray(BasePeer::TYPE_FIELDNAME);
} catch(Exception $e) {
} catch (Exception $e) {
$podcast->delete();
throw $e;
}
}
@ -141,9 +144,8 @@ class Application_Service_PodcastService
/**
* @param $podcast
* @param $title passed in directly from web UI input
* This will automatically create a smartblock and playlist for this podcast.
* This will automatically create a smartblock and playlist for this podcast
*/
public static function createPodcastSmartblockAndPlaylist($podcast, $title = null)
{
if (is_array($podcast)) {
@ -158,7 +160,7 @@ class Application_Service_PodcastService
$newBl = new Application_Model_Block();
$newBl->setCreator(Application_Model_User::getCurrentUser()->getId());
$newBl->setName($title);
$newBl->setDescription(_("Auto-generated smartblock for podcast"));
$newBl->setDescription(_('Auto-generated smartblock for podcast'));
$newBl->saveType('dynamic');
// limit the smartblock to 1 item
$row = new CcBlockcriteria();
@ -194,11 +196,10 @@ class Application_Service_PodcastService
$row->save();
}
public static function createStationPodcast()
{
$podcast = new Podcast();
$podcast->setDbUrl(Application_Common_HTTPHelper::getStationUrl() . "feeds/station-rss");
$podcast->setDbUrl(Application_Common_HTTPHelper::getStationUrl() . 'feeds/station-rss');
$title = Application_Model_Preference::GetStationName();
$title = empty($title) ? "My Station's Podcast" : $title;
@ -219,6 +220,7 @@ class Application_Service_PodcastService
// Set the download key when we create the station podcast
// The value is randomly generated in the setter
Application_Model_Preference::setStationPodcastDownloadKey();
return $podcast->getDbId();
}
@ -228,26 +230,28 @@ class Application_Service_PodcastService
try {
if (Zend_Auth::getInstance()->hasIdentity()) {
$service_user = new Application_Service_UserService();
return $service_user->getCurrentUser()->getDbId();
} else {
$defaultOwner = CcSubjsQuery::create()
->filterByDbType('A')
->orderByDbId()
->findOne();
if (!$defaultOwner) {
// what to do if there is no admin user?
// should we handle this case?
return null;
}
return $defaultOwner->getDbId();
}
} catch(Exception $e) {
$defaultOwner = CcSubjsQuery::create()
->filterByDbType('A')
->orderByDbId()
->findOne()
;
if (!$defaultOwner) {
// what to do if there is no admin user?
// should we handle this case?
return null;
}
return $defaultOwner->getDbId();
} catch (Exception $e) {
Logging::info($e->getMessage());
}
}
/**
* Trims the podcast metadata to fit the table's column max size
* Trims the podcast metadata to fit the table's column max size.
*
* @param $podcastArray
*/
@ -271,12 +275,13 @@ class Application_Service_PodcastService
/**
* Fetches a Podcast's rss feed and returns all its episodes with
* the Podcast object
* the Podcast object.
*
* @param $podcastId
*
* @throws PodcastNotFoundException
* @throws InvalidPodcastException
*
* @return array - Podcast Array with a full list of episodes
*/
public static function getPodcastById($podcastId)
@ -287,14 +292,16 @@ class Application_Service_PodcastService
}
$podcast = $podcast->toArray(BasePeer::TYPE_FIELDNAME);
$podcast["itunes_explicit"] = ($podcast["itunes_explicit"] == "yes") ? true : false;
$podcast['itunes_explicit'] = ($podcast['itunes_explicit'] == 'yes') ? true : false;
return $podcast;
}
/**
* Deletes a Podcast and its podcast episodes
* Deletes a Podcast and its podcast episodes.
*
* @param $podcastId
*
* @throws Exception
* @throws PodcastNotFoundException
*/
@ -314,35 +321,39 @@ class Application_Service_PodcastService
}
/**
* Build a response with podcast data and embedded HTML to load on the frontend
* Build a response with podcast data and embedded HTML to load on the frontend.
*
* @param int $podcastId ID of the podcast to build a response for
* @param Zend_View_Interface $view Zend view object to render the response HTML
*
* @return array the response array containing the podcast data and editor HTML
* @param int $podcastId ID of the podcast to build a response for
* @param Zend_View_Interface $view Zend view object to render the response HTML
*
* @throws PodcastNotFoundException
*
* @return array the response array containing the podcast data and editor HTML
*/
public static function buildPodcastEditorResponse($podcastId, $view) {
public static function buildPodcastEditorResponse($podcastId, $view)
{
// Check the StationPodcast table rather than checking
// the station podcast ID key in preferences for extensibility
$podcast = StationPodcastQuery::create()->findOneByDbPodcastId($podcastId);
$path = $podcast ? 'podcast/station.phtml' : 'podcast/podcast.phtml';
$podcast = Application_Service_PodcastService::getPodcastById($podcastId);
return array(
"podcast" => json_encode($podcast),
"html" => $view->render($path),
);
return [
'podcast' => json_encode($podcast),
'html' => $view->render($path),
];
}
/**
* Updates a Podcast object with the given metadata
* Updates a Podcast object with the given metadata.
*
* @param $podcastId
* @param $data
* @return array
*
* @throws Exception
* @throws PodcastNotFoundException
*
* @return array
*/
public static function updatePodcastFromArray($podcastId, $data)
{
@ -351,31 +362,32 @@ class Application_Service_PodcastService
throw new PodcastNotFoundException();
}
self::removePrivateFields($data["podcast"]);
self::validatePodcastMetadata($data["podcast"]);
if (array_key_exists("auto_ingest", $data["podcast"])) {
self::removePrivateFields($data['podcast']);
self::validatePodcastMetadata($data['podcast']);
if (array_key_exists('auto_ingest', $data['podcast'])) {
self::_updateAutoIngestTimestamp($podcast, $data);
}
$data["podcast"]["itunes_explicit"] = $data["podcast"]["itunes_explicit"] ? "yes" : "clean";
$podcast->fromArray($data["podcast"], BasePeer::TYPE_FIELDNAME);
$data['podcast']['itunes_explicit'] = $data['podcast']['itunes_explicit'] ? 'yes' : 'clean';
$podcast->fromArray($data['podcast'], BasePeer::TYPE_FIELDNAME);
$podcast->save();
return $podcast->toArray(BasePeer::TYPE_FIELDNAME);
}
/**
* Update the automatic ingestion timestamp for the given Podcast
* Update the automatic ingestion timestamp for the given Podcast.
*
* @param Podcast $podcast Podcast object to update
* @param array $data Podcast update data array
* @param Podcast $podcast Podcast object to update
* @param array $data Podcast update data array
*/
private static function _updateAutoIngestTimestamp($podcast, $data) {
private static function _updateAutoIngestTimestamp($podcast, $data)
{
// Get podcast data with lazy loaded columns since we can't directly call getDbAutoIngest()
$currData = $podcast->toArray(BasePeer::TYPE_FIELDNAME, true);
// Add an auto-ingest timestamp when turning auto-ingest on
if ($data["podcast"]["auto_ingest"] == 1 && $currData["auto_ingest"] != 1) {
$data["podcast"]["auto_ingest_timestamp"] = gmdate('r');
if ($data['podcast']['auto_ingest'] == 1 && $currData['auto_ingest'] != 1) {
$data['podcast']['auto_ingest_timestamp'] = gmdate('r');
}
}
@ -386,19 +398,21 @@ class Application_Service_PodcastService
}
}
private static function addEscapedChild($node, $name, $value = null, $namespace = null) {
private static function addEscapedChild($node, $name, $value = null, $namespace = null)
{
if (empty($value)) {
return null;
}
$child = $node->addChild($name, null, $namespace);
$child[0] = $value;
return $child;
}
public static function createStationRssFeed()
{
$stationPodcastId = Application_Model_Preference::getStationPodcastId();
try {
$podcast = PodcastQuery::create()->findPk($stationPodcastId);
if (!$podcast) {
@ -407,107 +421,105 @@ class Application_Service_PodcastService
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"/>');
$channel = $xml->addChild("channel");
self::addEscapedChild($channel, "title", $podcast->getDbTitle());
self::addEscapedChild($channel, "link", $podcast->getDbLink());
self::addEscapedChild($channel, "description", $podcast->getDbDescription());
self::addEscapedChild($channel, "language", $podcast->getDbLanguage());
self::addEscapedChild($channel, "copyright", $podcast->getDbCopyright());
$channel = $xml->addChild('channel');
self::addEscapedChild($channel, 'title', $podcast->getDbTitle());
self::addEscapedChild($channel, 'link', $podcast->getDbLink());
self::addEscapedChild($channel, 'description', $podcast->getDbDescription());
self::addEscapedChild($channel, 'language', $podcast->getDbLanguage());
self::addEscapedChild($channel, 'copyright', $podcast->getDbCopyright());
$xml->addAttribute('xmlns:xmlns:atom', "http://www.w3.org/2005/Atom");
$xml->addAttribute('xmlns:xmlns:atom', 'http://www.w3.org/2005/Atom');
$atomLink = $channel->addChild("xmlns:atom:link");
$atomLink->addAttribute("href", Application_Common_HTTPHelper::getStationUrl() . "feeds/station-rss");
$atomLink->addAttribute("rel", "self");
$atomLink->addAttribute("type", "application/rss+xml");
$atomLink = $channel->addChild('xmlns:atom:link');
$atomLink->addAttribute('href', Application_Common_HTTPHelper::getStationUrl() . 'feeds/station-rss');
$atomLink->addAttribute('rel', 'self');
$atomLink->addAttribute('type', 'application/rss+xml');
$imageUrl = Application_Common_HTTPHelper::getStationUrl()."api/station-logo";
$image = $channel->addChild("image");
$image->addChild("title", htmlspecialchars($podcast->getDbTitle()));
self::addEscapedChild($image, "url", $imageUrl);
self::addEscapedChild($image, "link", Application_Common_HTTPHelper::getStationUrl());
$imageUrl = Application_Common_HTTPHelper::getStationUrl() . 'api/station-logo';
$image = $channel->addChild('image');
$image->addChild('title', htmlspecialchars($podcast->getDbTitle()));
self::addEscapedChild($image, 'url', $imageUrl);
self::addEscapedChild($image, 'link', Application_Common_HTTPHelper::getStationUrl());
$xml->addAttribute('xmlns:xmlns:itunes', ITUNES_XML_NAMESPACE_URL);
self::addEscapedChild($channel, "xmlns:itunes:author", $podcast->getDbItunesAuthor());
self::addEscapedChild($channel, "xmlns:itunes:keywords", $podcast->getDbItunesKeywords());
self::addEscapedChild($channel, "xmlns:itunes:summary", $podcast->getDbItunesSummary());
self::addEscapedChild($channel, "xmlns:itunes:subtitle", $podcast->getDbItunesSubtitle());
self::addEscapedChild($channel, "xmlns:itunes:explicit", $podcast->getDbItunesExplicit());
$owner = $channel->addChild("xmlns:itunes:owner");
self::addEscapedChild($owner, "xmlns:itunes:name", Application_Model_Preference::GetStationName());
self::addEscapedChild($owner, "xmlns:itunes:email", Application_Model_Preference::GetEmail());
self::addEscapedChild($channel, 'xmlns:itunes:author', $podcast->getDbItunesAuthor());
self::addEscapedChild($channel, 'xmlns:itunes:keywords', $podcast->getDbItunesKeywords());
self::addEscapedChild($channel, 'xmlns:itunes:summary', $podcast->getDbItunesSummary());
self::addEscapedChild($channel, 'xmlns:itunes:subtitle', $podcast->getDbItunesSubtitle());
self::addEscapedChild($channel, 'xmlns:itunes:explicit', $podcast->getDbItunesExplicit());
$owner = $channel->addChild('xmlns:itunes:owner');
self::addEscapedChild($owner, 'xmlns:itunes:name', Application_Model_Preference::GetStationName());
self::addEscapedChild($owner, 'xmlns:itunes:email', Application_Model_Preference::GetEmail());
$itunesImage = $channel->addChild("xmlns:itunes:image");
$itunesImage->addAttribute("href", $imageUrl);
$itunesImage = $channel->addChild('xmlns:itunes:image');
$itunesImage->addAttribute('href', $imageUrl);
// Need to split categories into separate tags
$itunesCategories = explode(",", $podcast->getDbItunesCategory());
$itunesCategories = explode(',', $podcast->getDbItunesCategory());
foreach ($itunesCategories as $c) {
if (!empty($c)) {
$category = $channel->addChild("xmlns:itunes:category");
$category->addAttribute("text", $c);
$category = $channel->addChild('xmlns:itunes:category');
$category->addAttribute('text', $c);
}
}
$episodes = PodcastEpisodesQuery::create()->filterByDbPodcastId($stationPodcastId)->find();
foreach ($episodes as $episode) {
$item = $channel->addChild("item");
$item = $channel->addChild('item');
$publishedFile = CcFilesQuery::create()->findPk($episode->getDbFileId());
//title
self::addEscapedChild($item, "title", $publishedFile->getDbTrackTitle());
self::addEscapedChild($item, 'title', $publishedFile->getDbTrackTitle());
//link - do we need this?
//pubDate
self::addEscapedChild($item, "pubDate", gmdate(DATE_RFC2822, strtotime($episode->getDbPublicationDate())));
self::addEscapedChild($item, 'pubDate', gmdate(DATE_RFC2822, strtotime($episode->getDbPublicationDate())));
//category
foreach($itunesCategories as $c) {
foreach ($itunesCategories as $c) {
if (!empty($c)) {
self::addEscapedChild($item, "category", $c);
self::addEscapedChild($item, 'category', $c);
}
}
//guid
$guid = self::addEscapedChild($item, "guid", $episode->getDbEpisodeGuid());
$guid->addAttribute("isPermaLink", "false");
$guid = self::addEscapedChild($item, 'guid', $episode->getDbEpisodeGuid());
$guid->addAttribute('isPermaLink', 'false');
//description
self::addEscapedChild($item, "description", $publishedFile->getDbDescription());
self::addEscapedChild($item, 'description', $publishedFile->getDbDescription());
//encolsure - url, length, type attribs
$enclosure = $item->addChild("enclosure");
$enclosure->addAttribute("url", $episode->getDbDownloadUrl());
$enclosure->addAttribute("length", $publishedFile->getDbFilesize());
$enclosure->addAttribute("type", $publishedFile->getDbMime());
$enclosure = $item->addChild('enclosure');
$enclosure->addAttribute('url', $episode->getDbDownloadUrl());
$enclosure->addAttribute('length', $publishedFile->getDbFilesize());
$enclosure->addAttribute('type', $publishedFile->getDbMime());
//itunes:subtitle
// From http://www.apple.com/ca/itunes/podcasts/specs.html#subtitle :
// 'The contents of the <itunes:subtitle> tag are displayed in the Description column in iTunes.'
// self::addEscapedChild($item, "xmlns:itunes:subtitle", $publishedFile->getDbTrackTitle());
self::addEscapedChild($item, "xmlns:itunes:subtitle", $publishedFile->getDbDescription());
self::addEscapedChild($item, 'xmlns:itunes:subtitle', $publishedFile->getDbDescription());
//itunes:summary
self::addEscapedChild($item, "xmlns:itunes:summary", $publishedFile->getDbDescription());
self::addEscapedChild($item, 'xmlns:itunes:summary', $publishedFile->getDbDescription());
//itunes:author
self::addEscapedChild($item, "xmlns:itunes:author", $publishedFile->getDbArtistName());
self::addEscapedChild($item, 'xmlns:itunes:author', $publishedFile->getDbArtistName());
//itunes:explicit - skip this?
//itunes:duration
self::addEscapedChild($item, "xmlns:itunes:duration", explode('.', $publishedFile->getDbLength())[0]);
self::addEscapedChild($item, 'xmlns:itunes:duration', explode('.', $publishedFile->getDbLength())[0]);
}
//Format it nicely with newlines...
$dom = new DOMDocument();
$dom->loadXML($xml->asXML());
$dom->formatOutput = true;
$formattedXML = $dom->saveXML();
return $formattedXML;
return $dom->saveXML();
} catch (FeedException $e) {
return false;
}

View file

@ -1,25 +1,26 @@
<?php
class Application_Service_PublishService {
class Application_Service_PublishService
{
/**
* @var array map of arbitrary source names to descriptive labels
*/
private static $SOURCES = array(
"station_podcast" => "My Podcast"
);
private static $SOURCES = [
'station_podcast' => 'My Podcast',
];
/**
* Publish or remove the file with the given file ID from the services
* specified in the request data (ie. the station podcast)
* specified in the request data (ie. the station podcast).
*
* @param int $fileId ID of the file to be published
* @param int $fileId ID of the file to be published
* @param array $data request data containing what services to publish to
*/
public static function publish($fileId, $data) {
public static function publish($fileId, $data)
{
foreach ($data as $k => $v) {
$service = PublishServiceFactory::getService($k);
$service->$v($fileId);
$service->{$v}($fileId);
}
}
@ -35,26 +36,27 @@ class Application_Service_PublishService {
*
* @return array array containing published and toPublish arrays. Has the form
* [
* "toPublish" => [
* "source" => "label",
* ...
* ]
* "published" => [
* "source" => "label",
* ...
* ]
* "toPublish" => [
* "source" => "label",
* ...
* ]
* "published" => [
* "source" => "label",
* ...
* ]
* ]
*/
public static function getSourceLists($fileId) {
$sources = array();
public static function getSourceLists($fileId)
{
$sources = [];
foreach (self::$SOURCES as $source => $label) {
$service = PublishServiceFactory::getService($source);
$status = $service->getPublishStatus($fileId);
array_push($sources, array(
"source" => $source,
"label" => _($label),
"status" => $status
));
array_push($sources, [
'source' => $source,
'label' => _($label),
'status' => $status,
]);
}
return $sources;
@ -69,7 +71,8 @@ class Application_Service_PublishService {
* @return bool true if the file has been published to any source,
* otherwise false
*/
public static function isPublished($fileId) {
public static function isPublished($fileId)
{
foreach (self::$SOURCES as $source => $label) {
$service = PublishServiceFactory::getService($source);
// 1: published or -1: pending
@ -77,7 +80,7 @@ class Application_Service_PublishService {
return true;
}
}
return false;
}
}

View file

@ -1,21 +1,22 @@
<?php
class PublishServiceFactory {
class PublishServiceFactory
{
/**
* Given an identifying string, get a PublishService object of that type
* Given an identifying string, get a PublishService object of that type.
*
* @param $serviceName string the name of the service to create
*
* @return Publish|null
* @return null|Publish
*/
public static function getService($serviceName) {
switch($serviceName) {
public static function getService($serviceName)
{
switch ($serviceName) {
case STATION_PODCAST_SERVICE_NAME:
return new Application_Service_PodcastEpisodeService();
default:
return null;
}
}
}
}

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;
}
}

View file

@ -1,4 +1,5 @@
<?php
class Application_Service_ShowFormService
{
private $ccShow;
@ -9,23 +10,22 @@ class Application_Service_ShowFormService
if (!is_null($showId)) {
$this->ccShow = CcShowQuery::create()->findPk($showId);
}
$this->instanceId = $instanceId;
}
/**
*
* @return array of show forms
*/
public function createShowForms()
{
$formWhat = new Application_Form_AddShowWhat();
$formWhat = new Application_Form_AddShowWhat();
$formAutoPlaylist = new Application_Form_AddShowAutoPlaylist();
$formWho = new Application_Form_AddShowWho();
$formWhen = new Application_Form_AddShowWhen();
$formWho = new Application_Form_AddShowWho();
$formWhen = new Application_Form_AddShowWhen();
$formRepeats = new Application_Form_AddShowRepeats();
$formStyle = new Application_Form_AddShowStyle();
$formLive = new Application_Form_AddShowLiveStream();
$formStyle = new Application_Form_AddShowStyle();
$formLive = new Application_Form_AddShowLiveStream();
$formRecord = new Application_Form_AddShowRR();
$formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
$formRebroadcast = new Application_Form_AddShowRebroadcastDates();
@ -41,101 +41,105 @@ class Application_Service_ShowFormService
$formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
$formRebroadcast->removeDecorator('DtDdWrapper');
$forms = array();
$forms["what"] = $formWhat;
$forms["autoplaylist"] = $formAutoPlaylist;
$forms["who"] = $formWho;
$forms["when"] = $formWhen;
$forms["repeats"] = $formRepeats;
$forms["style"] = $formStyle;
$forms["live"] = $formLive;
$forms["record"] = $formRecord;
$forms["abs_rebroadcast"] = $formAbsoluteRebroadcast;
$forms["rebroadcast"] = $formRebroadcast;
$forms = [];
$forms['what'] = $formWhat;
$forms['autoplaylist'] = $formAutoPlaylist;
$forms['who'] = $formWho;
$forms['when'] = $formWhen;
$forms['repeats'] = $formRepeats;
$forms['style'] = $formStyle;
$forms['live'] = $formLive;
$forms['record'] = $formRecord;
$forms['abs_rebroadcast'] = $formAbsoluteRebroadcast;
$forms['rebroadcast'] = $formRebroadcast;
return $forms;
}
/**
*
* Popluates the what, autoplaylist, when, and repeat forms
* with default values
* with default values.
*
* @param mixed $formWhat
* @param mixed $formWhen
* @param mixed $formRepeats
*/
public function populateNewShowForms($formWhat, $formWhen, $formRepeats)
{
$formWhat->populate(
array('add_show_id' => '-1',
'add_show_instance_id' => '-1'));
['add_show_id' => '-1',
'add_show_instance_id' => '-1', ]
);
$formWhen->populate(
array('add_show_start_date' => date("Y-m-d"),
'add_show_start_time' => '00:00',
'add_show_end_date_no_repeate' => date("Y-m-d"),
'add_show_end_time' => '01:00',
'add_show_duration' => '01h 00m'));
['add_show_start_date' => date('Y-m-d'),
'add_show_start_time' => '00:00',
'add_show_end_date_no_repeate' => date('Y-m-d'),
'add_show_end_time' => '01:00',
'add_show_duration' => '01h 00m', ]
);
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
$formRepeats->populate(['add_show_end_date' => date('Y-m-d')]);
}
public function delegateShowInstanceFormPopulation($forms)
{
$this->populateFormWhat($forms["what"]);
$this->populateInstanceFormWhen($forms["when"]);
$this->populateFormWho($forms["who"]);
$this->populateFormLive($forms["live"]);
$this->populateFormStyle($forms["style"]);
$this->populateFormWhat($forms['what']);
$this->populateInstanceFormWhen($forms['when']);
$this->populateFormWho($forms['who']);
$this->populateFormLive($forms['live']);
$this->populateFormStyle($forms['style']);
/* Only the field on the 'when' form will get updated so we should
* make all other forms disabled or readonly
*
*
* 'what' needs to be readonly because zendform will not validate
* if they are disabled
*
*
* All other forms can be disabled because we do not update those values
* when the user edits a repeating instance
*/
$forms["what"]->makeReadonly();
$forms["what"]->enableInstanceDesc();
$forms["autoplaylist"]->disable();
$forms["repeats"]->disable();
$forms["who"]->disable();
$forms["style"]->disable();
$forms['what']->makeReadonly();
$forms['what']->enableInstanceDesc();
$forms['autoplaylist']->disable();
$forms['repeats']->disable();
$forms['who']->disable();
$forms['style']->disable();
// Hide the show logo fields when users are editing a single instance
$forms["style"]->hideShowLogo();
$forms["live"]->disable();
$forms["record"]->disable();
$forms["rebroadcast"]->disable();
$forms["abs_rebroadcast"]->disable();
$forms['style']->hideShowLogo();
$forms['live']->disable();
$forms['record']->disable();
$forms['rebroadcast']->disable();
$forms['abs_rebroadcast']->disable();
}
/**
*
* Delegates populating each show form with the appropriate
* data of the current show being edited
*
* data of the current show being edited.
*
* @param $forms
*/
public function delegateShowFormPopulation($forms)
{
$this->populateFormWhat($forms["what"]);
$this->populateFormWhat($forms['what']);
//local show start DT
$this->populateFormAutoPlaylist($forms["autoplaylist"]);
$showStart = $this->populateFormWhen($forms["when"]);
$this->populateFormRepeats($forms["repeats"], $showStart);
$this->populateFormWho($forms["who"]);
$this->populateFormStyle($forms["style"]);
$this->populateFormLive($forms["live"]);
$this->populateFormRecord($forms["record"]);
$this->populateFormRebroadcastRelative($forms["rebroadcast"]);
$this->populateFormRebroadcastAbsolute($forms["abs_rebroadcast"]);
$this->populateFormAutoPlaylist($forms['autoplaylist']);
$showStart = $this->populateFormWhen($forms['when']);
$this->populateFormRepeats($forms['repeats'], $showStart);
$this->populateFormWho($forms['who']);
$this->populateFormStyle($forms['style']);
$this->populateFormLive($forms['live']);
$this->populateFormRecord($forms['record']);
$this->populateFormRebroadcastRelative($forms['rebroadcast']);
$this->populateFormRebroadcastAbsolute($forms['abs_rebroadcast']);
}
private function populateFormWhat($form)
{
$ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId);
$form->populate(
array(
[
'add_show_instance_id' => $this->instanceId,
'add_show_id' => $this->ccShow->getDbId(),
'add_show_name' => $this->ccShow->getDbName(),
@ -143,24 +147,24 @@ class Application_Service_ShowFormService
'add_show_genre' => $this->ccShow->getDbGenre(),
'add_show_description' => $this->ccShow->getDbDescription(),
'add_show_instance_description' => $ccShowInstance->getDbDescription(),
));
]
);
}
private function populateFormAutoPlaylist($form)
{
$ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId);
$form->populate(
array(
'add_show_has_autoplaylist' => $this->ccShow->getDbHasAutoPlaylist() ? 1 : 0,
'add_show_autoplaylist_id' => $this->ccShow->getDbAutoPlaylistId(),
'add_show_autoplaylist_repeat' => $this->ccShow->getDbAutoPlaylistRepeat()
));
[
'add_show_has_autoplaylist' => $this->ccShow->getDbHasAutoPlaylist() ? 1 : 0,
'add_show_autoplaylist_id' => $this->ccShow->getDbAutoPlaylistId(),
'add_show_autoplaylist_repeat' => $this->ccShow->getDbAutoPlaylistRepeat(),
]
);
}
private function populateFormWhen($form)
private function populateFormWhen($form)
{
if ($this->ccShow->isRepeating()) {
$ccShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
@ -180,8 +184,8 @@ class Application_Service_ShowFormService
} else {
$showStartAndEnd = $this->getNextFutureRepeatShowTime();
if (!is_null($showStartAndEnd)) {
$showStart = $showStartAndEnd["starts"];
$showEnd = $showStartAndEnd["ends"];
$showStart = $showStartAndEnd['starts'];
$showEnd = $showStartAndEnd['ends'];
}
if ($this->hasShowStarted($showStart)) {
$form->disableStartDateAndTime();
@ -190,17 +194,18 @@ class Application_Service_ShowFormService
}
//Disable starting a show 'now' when editing an existing show.
$form->getElement('add_show_start_now')->setAttrib('disable', array('now'));
$form->getElement('add_show_start_now')->setAttrib('disable', ['now']);
$form->populate(
array(
'add_show_start_date' => $showStart->format("Y-m-d"),
'add_show_start_time' => $showStart->format("H:i"),
'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"),
'add_show_end_time' => $showEnd->format("H:i"),
[
'add_show_start_date' => $showStart->format('Y-m-d'),
'add_show_start_time' => $showStart->format('H:i'),
'add_show_end_date_no_repeat' => $showEnd->format('Y-m-d'),
'add_show_end_time' => $showEnd->format('H:i'),
'add_show_duration' => $ccShowDay->formatDuration(true),
'add_show_timezone' => $ccShowDay->getDbTimezone(),
'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0));
'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0, ]
);
return $showStart;
}
@ -210,22 +215,23 @@ class Application_Service_ShowFormService
$ccShowInstance = CcShowInstancesQuery::create()
->filterByDbShowId($this->ccShow->getDbId())
->filterByDbModifiedInstance(false)
->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
->filterByDbStarts(gmdate('Y-m-d H:i:s'), Criteria::GREATER_THAN)
->orderByDbStarts()
->findOne();
->findOne()
;
if (!$ccShowInstance) {
return null;
}
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
$ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC"));
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone('UTC'));
$ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone('UTC'));
$showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
$starts->setTimezone(new DateTimeZone($showTimezone));
$ends->setTimezone(new DateTimeZone($showTimezone));
return array("starts" => $starts, "ends" => $ends);
return ['starts' => $starts, 'ends' => $ends];
}
private function populateInstanceFormWhen($form)
@ -249,26 +255,30 @@ class Application_Service_ShowFormService
}
//Disable starting a show 'now' when editing an existing show.
$form->getElement('add_show_start_now')->setAttrib('disable', array('now'));
$form->getElement('add_show_start_now')->setAttrib('disable', ['now']);
$form->populate(
array(
[
'add_show_start_now' => 'future',
'add_show_start_date' => $showStart->format("Y-m-d"),
'add_show_start_time' => $showStart->format("H:i"),
'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"),
'add_show_end_time' => $showEnd->format("H:i"),
'add_show_start_date' => $showStart->format('Y-m-d'),
'add_show_start_time' => $showStart->format('H:i'),
'add_show_end_date_no_repeat' => $showEnd->format('Y-m-d'),
'add_show_end_time' => $showEnd->format('H:i'),
'add_show_duration' => $this->calculateDuration(
$showStart->format(DEFAULT_TIMESTAMP_FORMAT), $showEnd->format(DEFAULT_TIMESTAMP_FORMAT), $timezone),
$showStart->format(DEFAULT_TIMESTAMP_FORMAT),
$showEnd->format(DEFAULT_TIMESTAMP_FORMAT),
$timezone
),
'add_show_timezone' => $timezone,
'add_show_repeats' => 0));
'add_show_repeats' => 0, ]
);
$form->getElement('add_show_repeats')->setOptions(array("disabled" => true));
$form->getElement('add_show_repeats')->setOptions(['disabled' => true]);
}
/**
*
* Enter description here ...
*
* @param $form
* @param DateTime $nextFutureShowStart user's local timezone
*/
@ -280,10 +290,10 @@ class Application_Service_ShowFormService
$ccShowDays = $this->ccShow->getCcShowDayss();
}
$days = array();
$days = [];
foreach ($ccShowDays as $ccShowDay) {
$showStart = $ccShowDay->getLocalStartDateAndTime();
array_push($days, $showStart->format("w"));
array_push($days, $showStart->format('w'));
}
$service_show = new Application_Service_ShowService($this->ccShow->getDbId());
@ -291,9 +301,9 @@ class Application_Service_ShowFormService
//end dates are stored non-inclusively so we need to
//subtract one day
if (!is_null($repeatEndDate)) {
$repeatEndDate->sub(new DateInterval("P1D"));
$repeatEndDate->sub(new DateInterval('P1D'));
}
//default monthly repeat type
$monthlyRepeatType = 2;
$repeatType = $ccShowDays[0]->getDbRepeatType();
@ -306,22 +316,23 @@ class Application_Service_ShowFormService
}
$form->populate(
array(
[
'add_show_linked' => $this->ccShow->getDbLinked(),
'add_show_repeat_type' => $repeatType,
'add_show_day_check' => $days,
'add_show_end_date' => (!is_null($repeatEndDate)) ? $repeatEndDate->format("Y-m-d"):null,
'add_show_end_date' => (!is_null($repeatEndDate)) ? $repeatEndDate->format('Y-m-d') : null,
'add_show_no_end' => (is_null($repeatEndDate)),
'add_show_monthly_repeat_type' => $monthlyRepeatType));
'add_show_monthly_repeat_type' => $monthlyRepeatType, ]
);
if (!$this->ccShow->isLinkable() || $this->ccShow->isRecorded()) {
$form->getElement('add_show_linked')->setOptions(array('disabled' => true));
$form->getElement('add_show_linked')->setOptions(['disabled' => true]);
}
/* Because live editing of a linked show is disabled, we will make
* the linking option readonly if the current show is being edited. We
* dont' want the user to suddenly not be able to edit the current show
*
*
* Readonly does not work with checkboxes but we can't disable it
* because the value won't get posted. In add-show.js we stop the
* onclick event from firing by returning false
@ -335,86 +346,93 @@ class Application_Service_ShowFormService
{
$ccShowHosts = $this->ccShow->getCcShowHostss();
$hosts = array();
$hosts = [];
foreach ($ccShowHosts as $ccShowHost) {
array_push($hosts, $ccShowHost->getDbHost());
}
$form->populate(array('add_show_hosts' => $hosts));
$form->populate(['add_show_hosts' => $hosts]);
}
private function populateFormStyle($form)
{
$src = $this->ccShow->getDbImagePath() ?
$src = $this->ccShow->getDbImagePath() ?
$this->imagePathToDataUri($this->ccShow->getDbImagePath()) : '';
$form->populate(
array(
[
'add_show_background_color' => $this->ccShow->getDbBackgroundColor(),
'add_show_color' => $this->ccShow->getDbColor(),
'add_show_logo_current' => $src));
'add_show_logo_current' => $src, ]
);
}
/**
* Convert a static image from disk to a base64 data URI
*
* Convert a static image from disk to a base64 data URI.
*
* @param unknown $path
* - the path to the image on the disk
* - the path to the image on the disk
*
* @return string
* - the data URI representation of the image
* - the data URI representation of the image
*/
private function imagePathToDataUri($path) {
private function imagePathToDataUri($path)
{
$imageData = null;
$bytesRead = 0;
try {
ob_start();
header("Content-type: image/*");
header('Content-type: image/*');
$bytesRead = @readfile($path);
$imageData = base64_encode(ob_get_contents());
ob_end_clean();
if ($bytesRead === FALSE) {
if ($bytesRead === false) {
$imageData = null;
}
} catch (Exception $e) {
Logging::error("Failed to read image: " . $path);
Logging::error('Failed to read image: ' . $path);
$imageData = null;
}
// return the data URI - data:{mime};base64,{data}
return ($imageData === null || $imageData === '') ?
'' : 'data: '.mime_content_type($path).';base64,'.$imageData;
return ($imageData === null || $imageData === '') ?
'' : 'data: ' . mime_content_type($path) . ';base64,' . $imageData;
}
private function populateFormLive($form)
{
$form->populate(
array(
"cb_airtime_auth" => $this->ccShow->getDbLiveStreamUsingAirtimeAuth(),
"cb_custom_auth" => $this->ccShow->getDbLiveStreamUsingCustomAuth(),
"custom_username" => $this->ccShow->getDbLiveStreamUser(),
"custom_password" => $this->ccShow->getDbLiveStreamPass()));
[
'cb_airtime_auth' => $this->ccShow->getDbLiveStreamUsingAirtimeAuth(),
'cb_custom_auth' => $this->ccShow->getDbLiveStreamUsingCustomAuth(),
'custom_username' => $this->ccShow->getDbLiveStreamUser(),
'custom_password' => $this->ccShow->getDbLiveStreamPass(), ]
);
}
private function populateFormRecord($form)
{
$form->populate(
array(
[
'add_show_record' => $this->ccShow->isRecorded(),
'add_show_rebroadcast' => $this->ccShow->isRebroadcast()));
'add_show_rebroadcast' => $this->ccShow->isRebroadcast(), ]
);
$form->getElement('add_show_record')->setOptions(array('disabled' => true));
$form->getElement('add_show_record')->setOptions(['disabled' => true]);
}
private function populateFormRebroadcastRelative($form)
{
$relativeRebroadcasts = $this->ccShow->getRebroadcastsRelative();
$formValues = array();
$formValues = [];
$i = 1;
foreach ($relativeRebroadcasts as $rr) {
$formValues["add_show_rebroadcast_date_$i"] = $rr->getDbDayOffset();
$formValues["add_show_rebroadcast_time_$i"] = Application_Common_DateHelper::removeSecondsFromTime(
$rr->getDbStartTime());
$i++;
$formValues["add_show_rebroadcast_date_{$i}"] = $rr->getDbDayOffset();
$formValues["add_show_rebroadcast_time_{$i}"] = Application_Common_DateHelper::removeSecondsFromTime(
$rr->getDbStartTime()
);
++$i;
}
$form->populate($formValues);
@ -425,47 +443,49 @@ class Application_Service_ShowFormService
$absolutRebroadcasts = $this->ccShow->getRebroadcastsAbsolute();
$timezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
$formValues = array();
$formValues = [];
$i = 1;
foreach ($absolutRebroadcasts as $ar) {
//convert dates to user's local time
$start = new DateTime($ar->getDbStarts(), new DateTimeZone("UTC"));
$start = new DateTime($ar->getDbStarts(), new DateTimeZone('UTC'));
$start->setTimezone(new DateTimeZone($timezone));
$formValues["add_show_rebroadcast_date_absolute_$i"] = $start->format("Y-m-d");
$formValues["add_show_rebroadcast_time_absolute_$i"] = $start->format("H:i");
$i++;
$formValues["add_show_rebroadcast_date_absolute_{$i}"] = $start->format('Y-m-d');
$formValues["add_show_rebroadcast_time_absolute_{$i}"] = $start->format('H:i');
++$i;
}
$form->populate($formValues);
}
/**
*
* Enter description here ...
* @param DateTime $showStart user's local time
*
* @param DateTime $showStart user's local time
* @param mixed $p_showStart
*/
private function hasShowStarted($p_showStart) {
private function hasShowStarted($p_showStart)
{
$showStart = clone $p_showStart;
$showStart->setTimeZone(new DateTimeZone("UTC"));
$showStart->setTimeZone(new DateTimeZone('UTC'));
if ($showStart->format("Y-m-d H:i:s") < gmdate("Y-m-d H:i:s")) {
if ($showStart->format('Y-m-d H:i:s') < gmdate('Y-m-d H:i:s')) {
return true;
} else {
return false;
}
return false;
}
/**
* Before we send the form data in for validation, there
* are a few fields we may need to adjust first
*
* are a few fields we may need to adjust first.
*
* @param $formData
*/
public function preEditShowValidationCheck($formData)
{
// If the start date or time were disabled, don't validate them
$validateStartDate = $formData['start_date_disabled'] === "false";
$validateStartTime = $formData['start_time_disabled'] === "false";
$validateStartDate = $formData['start_date_disabled'] === 'false';
$validateStartTime = $formData['start_time_disabled'] === 'false';
//CcShowDays object of the show currently being edited
$currentShowDay = $this->ccShow->getFirstCcShowDay();
@ -481,13 +501,12 @@ class Application_Service_ShowFormService
$originalShowStartDateTime = $dt;
}
return array($formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime);
return [$formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime];
}
/**
*
* Returns a DateTime object, in the user's local time,
* of the current or next show instance start time
* of the current or next show instance start time.
*
* Returns null if there is no next future repeating show instance
*/
@ -496,15 +515,16 @@ class Application_Service_ShowFormService
$ccShowInstance = CcShowInstancesQuery::create()
->filterByDbShowId($this->ccShow->getDbId())
->filterByDbModifiedInstance(false)
->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_EQUAL)
->filterByDbStarts(gmdate('Y-m-d H:i:s'), Criteria::GREATER_EQUAL)
->orderByDbStarts()
->findOne();
->findOne()
;
if (!$ccShowInstance) {
return null;
}
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone('UTC'));
$showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
$starts->setTimezone(new DateTimeZone($showTimezone));
@ -512,53 +532,69 @@ class Application_Service_ShowFormService
return $starts;
}
/**
*
* Validates show forms
*
* @return boolean
* Validates show forms.
*
* @param mixed $forms
* @param mixed $formData
* @param mixed $validateStartDate
* @param null|mixed $originalStartDate
* @param mixed $editShow
* @param null|mixed $instanceId
*
* @return bool
*/
public function validateShowForms($forms, $formData, $validateStartDate = true,
$originalStartDate=null, $editShow=false, $instanceId=null)
{
$what = $forms["what"]->isValid($formData);
$autoplaylist = $forms["autoplaylist"]->isValid($formData);
$live = $forms["live"]->isValid($formData);
$record = $forms["record"]->isValid($formData);
$who = $forms["who"]->isValid($formData);
public function validateShowForms(
$forms,
$formData,
$validateStartDate = true,
$originalStartDate = null,
$editShow = false,
$instanceId = null
) {
$what = $forms['what']->isValid($formData);
$autoplaylist = $forms['autoplaylist']->isValid($formData);
$live = $forms['live']->isValid($formData);
$record = $forms['record']->isValid($formData);
$who = $forms['who']->isValid($formData);
/*
* hack to prevent validating the file upload field since it
* isn't passed into $data
*/
$upload = $forms["style"]->getElement("add_show_logo");
$forms["style"]->removeElement("add_show_logo");
$style = $forms["style"]->isValid($formData);
$upload = $forms['style']->getElement('add_show_logo');
$forms['style']->removeElement('add_show_logo');
$style = $forms['style']->isValid($formData);
// re-add the upload element
$forms["style"]->addElement($upload);
$when = $forms["when"]->isWhenFormValid($formData, $validateStartDate,
$originalStartDate, $editShow, $instanceId);
$forms['style']->addElement($upload);
$when = $forms['when']->isWhenFormValid(
$formData,
$validateStartDate,
$originalStartDate,
$editShow,
$instanceId
);
$repeats = true;
if ($formData["add_show_repeats"]) {
$repeats = $forms["repeats"]->isValid($formData);
if ($formData['add_show_repeats']) {
$repeats = $forms['repeats']->isValid($formData);
/*
* Make the absolute rebroadcast form valid since
* it does not get used if the show is repeating
*/
$forms["abs_rebroadcast"]->reset();
$forms['abs_rebroadcast']->reset();
$absRebroadcast = true;
$rebroadcast = true;
if (isset($formData["add_show_rebroadcast"]) && $formData["add_show_rebroadcast"]) {
$formData["add_show_duration"] = Application_Service_ShowService::formatShowDuration(
$formData["add_show_duration"]);
$rebroadcast = $forms["rebroadcast"]->isValid($formData);
if (isset($formData['add_show_rebroadcast']) && $formData['add_show_rebroadcast']) {
$formData['add_show_duration'] = Application_Service_ShowService::formatShowDuration(
$formData['add_show_duration']
);
$rebroadcast = $forms['rebroadcast']->isValid($formData);
}
} else {
/*
@ -566,25 +602,25 @@ class Application_Service_ShowFormService
* not get used if the show is not repeating.
* Instead, we use the absolute rebroadcast form
*/
$forms["rebroadcast"]->reset();
$forms['rebroadcast']->reset();
$rebroadcast = true;
$absRebroadcast = true;
if (isset($formData["add_show_rebroadcast"]) && $formData["add_show_rebroadcast"]) {
$formData["add_show_duration"] = Application_Service_ShowService::formatShowDuration(
$formData["add_show_duration"]);
$absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData);
if (isset($formData['add_show_rebroadcast']) && $formData['add_show_rebroadcast']) {
$formData['add_show_duration'] = Application_Service_ShowService::formatShowDuration(
$formData['add_show_duration']
);
$absRebroadcast = $forms['abs_rebroadcast']->isValid($formData);
}
}
return ($what && $autoplaylist && $live && $record && $who && $style && $when &&
$repeats && $absRebroadcast && $rebroadcast);
return $what && $autoplaylist && $live && $record && $who && $style && $when
&& $repeats && $absRebroadcast && $rebroadcast;
}
public function calculateDuration($start, $end, $timezone)
{
try {
$tz = new DateTimeZone($timezone);
$startDateTime = new DateTime($start, $tz);
$endDateTime = new DateTime($end, $tz);
@ -598,33 +634,37 @@ class Application_Service_ShowFormService
$hour += $day * 24;
$hour = min($hour, 99);
$sign = $duration->format('%r');
return sprintf('%s%02dh %02dm', $sign, $hour, $min);
} else {
return $duration->format('%r%Hh %Im');
}
return $duration->format('%r%Hh %Im');
} catch (Exception $e) {
Logging::info($e->getMessage());
return "Invalid Date";
return 'Invalid Date';
}
}
/**
* When the timezone is changed in add-show form this function
* applies the new timezone to the start and end time
* applies the new timezone to the start and end time.
*
* @param $date String
* @param $time String
* @param $timezone String
* @param mixed $newTimezone
* @param mixed $oldTimezone
*/
public static function localizeDateTime($date, $time, $newTimezone, $oldTimezone)
{
$dt = new DateTime($date." ".$time, new DateTimeZone($oldTimezone));
$dt = new DateTime($date . ' ' . $time, new DateTimeZone($oldTimezone));
$dt->setTimeZone(new DateTimeZone($newTimezone));
return array(
"date" => $dt->format("Y-m-d"),
"time" => $dt->format("H:i")
);
return [
'date' => $dt->format('Y-m-d'),
'time' => $dt->format('H:i'),
];
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
<?php
abstract class Application_Service_ThirdPartyCeleryService extends Application_Service_ThirdPartyService {
abstract class Application_Service_ThirdPartyCeleryService extends Application_Service_ThirdPartyService
{
/**
* @var string broker exchange name for third-party tasks
*/
@ -13,24 +13,29 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
protected static $_CELERY_TASKS;
/**
* Execute a Celery task with the given name and data parameters
* Execute a Celery task with the given name and data parameters.
*
* @param string $taskName the name of the celery task to execute
* @param array $data the data array to send as task parameters
* @param int $fileId the unique identifier for the file involved in the task
*
* @return CeleryTasks the created task
* @param array $data the data array to send as task parameters
* @param int $fileId the unique identifier for the file involved in the task
*
* @throws Exception
*
* @return CeleryTasks the created task
*/
protected function _executeTask($taskName, $data, $fileId = null) {
protected function _executeTask($taskName, $data, $fileId = null)
{
try {
$brokerTaskId = CeleryManager::sendCeleryMessage($taskName,
static::$_CELERY_EXCHANGE_NAME,
$data);
$brokerTaskId = CeleryManager::sendCeleryMessage(
$taskName,
static::$_CELERY_EXCHANGE_NAME,
$data
);
return $this->_createTaskReference($fileId, $brokerTaskId, $taskName);
} catch (Exception $e) {
Logging::error("Invalid request: " . $e->getMessage());
Logging::error('Invalid request: ' . $e->getMessage());
throw $e;
}
}
@ -44,21 +49,23 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
* receive completed task messages
* @param $taskName string broker task name
*
* @return CeleryTasks the created task
*
* @throws Exception
* @throws PropelException
*
* @return CeleryTasks the created task
*/
protected function _createTaskReference($fileId, $brokerTaskId, $taskName) {
protected function _createTaskReference($fileId, $brokerTaskId, $taskName)
{
$trackReferenceId = $this->createTrackReference($fileId);
$task = new CeleryTasks();
$task->setDbTaskId($brokerTaskId);
$task->setDbName($taskName);
$utc = new DateTimeZone("UTC");
$task->setDbDispatchTime(new DateTime("now", $utc));
$utc = new DateTimeZone('UTC');
$task->setDbDispatchTime(new DateTime('now', $utc));
$task->setDbStatus(CELERY_PENDING_STATUS);
$task->setDbTrackReference($trackReferenceId);
$task->save();
return $task;
}
@ -72,13 +79,14 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
* @throws Exception
* @throws PropelException
*/
public function updateTask($task, $status) {
public function updateTask($task, $status)
{
$task->setDbStatus($status);
$task->save();
}
/**
* Update a ThirdPartyTrackReferences object for a completed upload
* Update a ThirdPartyTrackReferences object for a completed upload.
*
* Manipulation and use of the track object is left up to child implementations
*
@ -87,23 +95,25 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
* @param $result mixed Celery task result message
* @param $status string Celery task status
*
* @return ThirdPartyTrackReferences the updated ThirdPartyTrackReferences object
*
* @throws Exception
* @throws PropelException
*
* @return ThirdPartyTrackReferences the updated ThirdPartyTrackReferences object
*/
public function updateTrackReference($task, $trackId, $result, $status) {
public function updateTrackReference($task, $trackId, $result, $status)
{
static::updateTask($task, $status);
$ref = ThirdPartyTrackReferencesQuery::create()
->findOneByDbId($trackId);
->findOneByDbId($trackId)
;
if (is_null($ref)) {
$ref = new ThirdPartyTrackReferences();
}
$ref->setDbService(static::$_SERVICE_NAME);
$utc = new DateTimeZone("UTC");
$ref->setDbUploadTime(new DateTime("now", $utc));
$utc = new DateTimeZone('UTC');
$ref->setDbUploadTime(new DateTime('now', $utc));
$ref->save();
return $ref;
}
}
}

View file

@ -1,15 +1,17 @@
<?php
/**
* Class ServiceNotFoundException
* Class ServiceNotFoundException.
*/
class ServiceNotFoundException extends Exception {}
class ServiceNotFoundException extends Exception
{
}
/**
* Class ThirdPartyService generic superclass for third-party services
* Class ThirdPartyService generic superclass for third-party services.
*/
abstract class Application_Service_ThirdPartyService {
abstract class Application_Service_ThirdPartyService
{
/**
* @var string service name to store in ThirdPartyTrackReferences database
*/
@ -22,60 +24,68 @@ abstract class Application_Service_ThirdPartyService {
*
* @param $fileId int local CcFiles identifier
*
* @return string the new ThirdPartyTrackReferences identifier
*
* @throws Exception
* @throws PropelException
*
* @return string the new ThirdPartyTrackReferences identifier
*/
public function createTrackReference($fileId) {
public function createTrackReference($fileId)
{
// First, check if the track already has an entry in the database
// If the file ID given is null, create a new reference
$ref = is_null($fileId) ? null : ThirdPartyTrackReferencesQuery::create()
->filterByDbService(static::$_SERVICE_NAME)
->findOneByDbFileId($fileId);
->findOneByDbFileId($fileId)
;
if (is_null($ref)) {
$ref = new ThirdPartyTrackReferences();
}
$ref->setDbService(static::$_SERVICE_NAME);
$ref->setDbFileId($fileId);
$ref->save();
return $ref->getDbId();
}
/**
* Remove a ThirdPartyTrackReferences row from the database.
* This is necessary if the track was removed from the service
* or the foreign id in our database is incorrect
* or the foreign id in our database is incorrect.
*
* @param $fileId int cc_files identifier
*
* @throws Exception
* @throws PropelException
*/
public function removeTrackReference($fileId) {
public function removeTrackReference($fileId)
{
$ref = ThirdPartyTrackReferencesQuery::create()
->filterByDbService(static::$_SERVICE_NAME)
->findOneByDbFileId($fileId);
->findOneByDbFileId($fileId)
;
$ref->delete();
}
/**
* Given a CcFiles identifier for a file that's been uploaded to a third-party service,
* return the third-party identifier for the remote file
* return the third-party identifier for the remote file.
*
* @param int $fileId the cc_files identifier
*
* @return string the service foreign identifier
*/
public function getServiceId($fileId) {
public function getServiceId($fileId)
{
$ref = ThirdPartyTrackReferencesQuery::create()
->filterByDbService(static::$_SERVICE_NAME)
->findOneByDbFileId($fileId); // There shouldn't be duplicates!
->findOneByDbFileId($fileId) // There shouldn't be duplicates!
;
return empty($ref) ? '' : $ref->getDbForeignId();
}
/**
* Check if a reference exists for a given CcFiles identifier
* Check if a reference exists for a given CcFiles identifier.
*
* @param int $fileId the cc_files identifier
*
@ -83,18 +93,22 @@ abstract class Application_Service_ThirdPartyService {
* 0 if the file has yet to be published,
* or -1 if the file is in a pending state
*/
public function referenceExists($fileId) {
public function referenceExists($fileId)
{
$ref = ThirdPartyTrackReferencesQuery::create()
->filterByDbService(static::$_SERVICE_NAME)
->findOneByDbFileId($fileId);
->findOneByDbFileId($fileId)
;
if (!empty($ref)) {
$task = CeleryTasksQuery::create()
->orderByDbDispatchTime(Criteria::DESC)
->findOneByDbTrackReference($ref->getDbId());
->findOneByDbTrackReference($ref->getDbId())
;
return $task->getDbStatus() == CELERY_PENDING_STATUS ? -1
: ($task->getDbStatus() == CELERY_FAILED_STATUS ? 0 : 1);
}
return 0;
}
}
}

View file

@ -13,8 +13,7 @@ class Application_Service_UserService
}
/**
*
* Returns a CcSubjs object
* Returns a CcSubjs object.
*/
public function getCurrentUser()
{
@ -24,5 +23,4 @@ class Application_Service_UserService
return $this->currentUser;
}
}
}