Improve the publish service implementation
This commit is contained in:
parent
42e55f193c
commit
7707378c2b
5 changed files with 59 additions and 45 deletions
|
@ -20,4 +20,17 @@ interface Publish {
|
||||||
*/
|
*/
|
||||||
public function unpublish($fileId);
|
public function unpublish($fileId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the publication status for the file with the given ID
|
||||||
|
*
|
||||||
|
* @param int $fileId the ID of the file to check
|
||||||
|
*
|
||||||
|
* @return int 1 if the file has been published,
|
||||||
|
* 0 if the file has yet to be published,
|
||||||
|
* -1 if the file is in a pending state,
|
||||||
|
* 2 if the source is unreachable (disconnected)
|
||||||
|
*/
|
||||||
|
public function getPublishStatus($fileId);
|
||||||
|
|
||||||
}
|
}
|
|
@ -215,6 +215,22 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the publication status for the file with the given ID
|
||||||
|
*
|
||||||
|
* @param int $fileId the ID of the file to check
|
||||||
|
*
|
||||||
|
* @return int 1 if the file has been published,
|
||||||
|
* 0 if the file has yet to be published,
|
||||||
|
* -1 if the file is in a pending state,
|
||||||
|
* 2 if the source is unreachable (disconnected)
|
||||||
|
*/
|
||||||
|
public function getPublishStatus($fileId) {
|
||||||
|
$stationPodcast = StationPodcastQuery::create()
|
||||||
|
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId());
|
||||||
|
return (int) $stationPodcast->hasEpisodeForFile($fileId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $episodeId
|
* @param $episodeId
|
||||||
* @return array
|
* @return array
|
||||||
|
|
|
@ -10,15 +10,6 @@ class Application_Service_PublishService {
|
||||||
"station_podcast" => "My Podcast"
|
"station_podcast" => "My Podcast"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array map of arbitrary source names to functions that return
|
|
||||||
* their publication state (true = published)
|
|
||||||
*/
|
|
||||||
private static $SOURCE_FUNCTIONS = array(
|
|
||||||
"soundcloud" => "getSoundCloudPublishStatus",
|
|
||||||
"station_podcast" => "getStationPodcastPublishStatus"
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish or remove the file with the given file ID from the services
|
* Publish or remove the file with the given file ID from the services
|
||||||
* specified in the request data (ie. SoundCloud, the station podcast)
|
* specified in the request data (ie. SoundCloud, the station podcast)
|
||||||
|
@ -58,9 +49,8 @@ class Application_Service_PublishService {
|
||||||
public static function getSourceLists($fileId) {
|
public static function getSourceLists($fileId) {
|
||||||
$sources = array();
|
$sources = array();
|
||||||
foreach (self::$SOURCES as $source => $label) {
|
foreach (self::$SOURCES as $source => $label) {
|
||||||
$fn = self::$SOURCE_FUNCTIONS[$source];
|
$service = PublishServiceFactory::getService($source);
|
||||||
// Should be in a ternary but PHP doesn't play nice
|
$status = $service->getPublishStatus($fileId);
|
||||||
$status = self::$fn($fileId);
|
|
||||||
array_push($sources, array(
|
array_push($sources, array(
|
||||||
"source" => $source,
|
"source" => $source,
|
||||||
"label" => _($label),
|
"label" => _($label),
|
||||||
|
@ -72,36 +62,23 @@ class Application_Service_PublishService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflective accessor for SoundCloud publication status for the
|
* Given a cc_file identifier, check if the associated file has
|
||||||
* file with the given ID
|
* been published to any sources.
|
||||||
*
|
*
|
||||||
* @param int $fileId the ID of the file to check
|
* @param int $fileId the cc_files identifier of the file to check
|
||||||
*
|
*
|
||||||
* @return int 1 if the file has been published to SoundCloud,
|
* @return bool true if the file has been published to any source,
|
||||||
* 0 if the file has yet to be published,
|
* otherwise false
|
||||||
* -1 if the file is in a pending state
|
|
||||||
*/
|
*/
|
||||||
private static function getSoundCloudPublishStatus($fileId) {
|
public static function isPublished($fileId) {
|
||||||
$soundcloudService = new Application_Service_SoundcloudService();
|
foreach (self::$SOURCES as $source => $label) {
|
||||||
if (!$soundcloudService->hasAccessToken()) { return 2; }
|
$service = PublishServiceFactory::getService($source);
|
||||||
return ($soundcloudService->referenceExists($fileId));
|
// 1: published or -1: pending
|
||||||
}
|
if (abs($service->getPublishStatus($fileId)) == 1) {
|
||||||
|
return true;
|
||||||
/**
|
}
|
||||||
*
|
}
|
||||||
* Reflective accessor for Station podcast publication status for the
|
return false;
|
||||||
* file with the given ID
|
|
||||||
*
|
|
||||||
* @param int $fileId the ID of the file to check
|
|
||||||
*
|
|
||||||
* @return int 1 if the file has been published to SoundCloud,
|
|
||||||
* 0 if the file has yet to be published, or -1 if the
|
|
||||||
* file is in a pending state
|
|
||||||
*/
|
|
||||||
private static function getStationPodcastPublishStatus($fileId) {
|
|
||||||
$stationPodcast = StationPodcastQuery::create()
|
|
||||||
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId());
|
|
||||||
return (int) $stationPodcast->hasEpisodeForFile($fileId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,4 +332,18 @@ class Application_Service_SoundcloudService extends Application_Service_ThirdPar
|
||||||
$this->delete($fileId);
|
$this->delete($fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the publication status for the file with the given ID
|
||||||
|
*
|
||||||
|
* @param int $fileId the ID of the file to check
|
||||||
|
*
|
||||||
|
* @return int 1 if the file has been published,
|
||||||
|
* 0 if the file has yet to be published,
|
||||||
|
* -1 if the file is in a pending state,
|
||||||
|
* 2 if the source is unreachable (disconnected)
|
||||||
|
*/
|
||||||
|
public function getPublishStatus($fileId) {
|
||||||
|
if (!$this->hasAccessToken()) { return 2; }
|
||||||
|
return ($this->referenceExists($fileId));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class Application_Service_StationPodcastService
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue