Merge branch 'saas-dev-publishing' of https://github.com/sourcefabric/Airtime into saas-dev-publishing

Conflicts:

airtime_mvc/application/modules/rest/controllers/PodcastEpisodesController.php
This commit is contained in:
drigato 2015-10-22 15:03:38 -04:00
commit 58a7b9324b
11 changed files with 91 additions and 70 deletions

View file

@ -5,11 +5,6 @@ require_once('PodcastFactory.php');
class Rest_PodcastController extends Zend_Rest_Controller
{
/**
* @var Application_Service_PodcastEpisodeService
*/
protected $_service;
public function init()
{
$this->view->layout()->disableLayout();
@ -17,7 +12,6 @@ class Rest_PodcastController extends Zend_Rest_Controller
// Remove reliance on .phtml files to render requests
$this->_helper->viewRenderer->setNoRender(true);
$this->view->setScriptPath(APPLICATION_PATH . 'views/scripts/');
$this->_service = new Application_Service_PodcastEpisodeService();
}
public function indexAction()
@ -120,11 +114,6 @@ class Rest_PodcastController extends Zend_Rest_Controller
try {
$requestData = json_decode($this->getRequest()->getRawBody(), true);
// Create placeholders in PodcastEpisodes so we know these episodes are being downloaded
// to prevent the user from trying to download them again while Celery is running
$episodes = $this->_service->addPodcastEpisodePlaceholders($requestData["podcast"]["id"],
$requestData["podcast"]["episodes"]);
$this->_service->downloadEpisodes($episodes);
$podcast = Application_Service_PodcastService::updatePodcastFromArray($id, $requestData);
$this->getResponse()
@ -167,7 +156,7 @@ class Rest_PodcastController extends Zend_Rest_Controller
* Endpoint for performing bulk actions (deleting multiple podcasts, opening multiple editors)
*/
public function bulkAction() {
if ($this->_request->getMethod() != "POST") {
if ($this->_request->getMethod() != HttpRequestType::POST) {
$this->getResponse()
->setHttpResponseCode(405)
->appendBody("ERROR: Method not accepted");
@ -175,28 +164,20 @@ class Rest_PodcastController extends Zend_Rest_Controller
}
$ids = $this->_getParam('ids', []);
$method = $this->_getParam('method', 'GET');
$method = $this->_getParam('method', HttpRequestType::GET);
$responseBody = [];
switch($method) {
case "DELETE":
case HttpRequestType::DELETE:
foreach($ids as $id) {
Application_Service_PodcastService::deletePodcastById($id);
}
// XXX: do we need this to be more descriptive?
$responseBody = "Successfully deleted podcasts";
break;
case "GET":
case HttpRequestType::GET:
foreach($ids as $id) {
// Check the StationPodcast table rather than checking
// the station podcast ID key in preferences for extensibility
$podcast = StationPodcastQuery::create()->findOneByDbPodcastId($id);
$path = $podcast ? 'podcast/station_podcast.phtml' : 'podcast/podcast.phtml';
$podcast = Application_Service_PodcastService::getPodcastById($id);
$responseBody[] = array(
"podcast"=>json_encode($podcast),
"html"=>$this->view->render($path),
);
$responseBody[] = Application_Service_PodcastService::buildPodcastEditorResponse($id, $this->view);
}
break;
}

View file

@ -2,12 +2,19 @@
class Rest_PodcastEpisodesController extends Zend_Rest_Controller
{
/**
* @var Application_Service_PodcastEpisodeService
*/
protected $_service;
public function init()
{
$this->view->layout()->disableLayout();
// Remove reliance on .phtml files to render requests
$this->_helper->viewRenderer->setNoRender(true);
$this->_service = new Application_Service_PodcastEpisodeService();
}
public function indexAction()
@ -64,7 +71,7 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
public function getAction()
{
//TODO: can we delete this?
// podcast ID
$id = $this->getId();
if (!$id) {
return;
@ -78,7 +85,7 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
try {
$this->getResponse()
->setHttpResponseCode(201)
->appendBody(json_encode(Application_Service_PodcastEpisodeService::getPodcastEpisodeById($episodeId)));
->appendBody(json_encode($this->_service->getPodcastEpisodeById($episodeId)));
} catch (PodcastNotFoundException $e) {
$this->podcastNotFoundResponse();
@ -99,7 +106,8 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
if ($episodeId = $this->_getParam('episode_id', false)) {
$resp = $this->getResponse();
$resp->setHttpResponseCode(400);
$resp->appendBody("ERROR: Episode ID should not be specified when using POST. POST is only used for importing podcast episodes, and an episode ID will be chosen by Airtime");
$resp->appendBody("ERROR: Episode ID should not be specified when using POST. POST is only used for "
. "importing podcast episodes, and an episode ID will be chosen by Airtime");
return;
}
@ -111,10 +119,7 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
try {
$requestData = json_decode($this->getRequest()->getRawBody(), true);
//$requestData = $this->getRequest()->getPost();
$episode = Application_Service_PodcastEpisodeService::createPodcastEpisode($id, $requestData);
$episode = $this->_service->importEpisode($id, $requestData["episode"]);
$this->getResponse()
->setHttpResponseCode(201)
->appendBody(json_encode($episode));
@ -128,9 +133,6 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
public function deleteAction()
{
Logging::info("delete - episodes");
//TODO: can we delete this?
$id = $this->getId();
if (!$id) {
return;
@ -142,7 +144,7 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
}
try {
Application_Service_PodcastEpisodeService::deletePodcastEpisodeById($episodeId);
$this->_service->deletePodcastEpisodeById($episodeId);
$this->getResponse()
->setHttpResponseCode(204);
} catch (PodcastEpisodeNotFoundException $e) {