From 3416ba20d99affe59bebadb1cfd2ac283758ea80 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 18 May 2011 14:33:11 -0400 Subject: [PATCH] cc-2263: unable to cancel recording show -made cancelled recorded shows still upload. --- .../application/controllers/ApiController.php | 63 +++++++++++-------- airtime_mvc/application/models/Shows.php | 42 ++++++------- install/include/AirtimeInstall.php | 2 +- python_apps/show-recorder/recorder.py | 3 +- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 43f9831bd..5c836fe8a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -64,7 +64,7 @@ class ApiController extends Zend_Controller_Action $api_key = $this->_getParam('api_key'); $downlaod = $this->_getParam('download'); - + if(!in_array($api_key, $CC_CONFIG["apiKey"])) { header('HTTP/1.0 401 Unauthorized'); @@ -263,10 +263,10 @@ class ApiController extends Zend_Controller_Action $end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $this->view->shows = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE); - - + + $this->view->is_recording = false; - + $rows = Show_DAL::GetCurrentShow($today_timestamp); if (count($rows) > 0){ $this->view->is_recording = ($rows[0]['record'] == 1); @@ -289,38 +289,47 @@ class ApiController extends Zend_Controller_Action $file = StoredFile::uploadFile($upload_dir); $show_instance = $this->_getParam('show_instance'); - $show_inst = new ShowInstance($show_instance); - $show_inst->setRecordedFile($file->getId()); - $show_name = $show_inst->getName(); - $show_genre = $show_inst->getGenre(); - $show_start_time = $show_inst->getShowStart(); + try { + $show_inst = new ShowInstance($show_instance); - if(Application_Model_Preference::GetDoSoundCloudUpload()) - { - for($i=0; $i<$CC_CONFIG['soundcloud-connection-retries']; $i++) { + $show_inst->setRecordedFile($file->getId()); + $show_name = $show_inst->getName(); + $show_genre = $show_inst->getGenre(); + $show_start_time = $show_inst->getShowStart(); - $show = new Show($show_inst->getShowId()); - $description = $show->getDescription(); - $hosts = $show->getHosts(); + if(Application_Model_Preference::GetDoSoundCloudUpload()) + { + for($i=0; $i<$CC_CONFIG['soundcloud-connection-retries']; $i++) { - $tags = array_merge($hosts, array($show_name)); + $show = new Show($show_inst->getShowId()); + $description = $show->getDescription(); + $hosts = $show->getHosts(); - try { - $soundcloud = new ATSoundcloud(); - $soundcloud_id = $soundcloud->uploadTrack($file->getRealFilePath(), $file->getName(), $description, $tags, $show_start_time, $show_genre); - $show_inst->setSoundCloudFileId($soundcloud_id); - break; - } - catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { - $code = $e->getHttpCode(); - if(!in_array($code, array(0, 100))) { + $tags = array_merge($hosts, array($show_name)); + + try { + $soundcloud = new ATSoundcloud(); + $soundcloud_id = $soundcloud->uploadTrack($file->getRealFilePath(), $file->getName(), $description, $tags, $show_start_time, $show_genre); + $show_inst->setSoundCloudFileId($soundcloud_id); break; } - } + catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { + $code = $e->getHttpCode(); + if(!in_array($code, array(0, 100))) { + break; + } + } - sleep($CC_CONFIG['soundcloud-connection-wait']); + sleep($CC_CONFIG['soundcloud-connection-wait']); + } } + } catch (Exception $e){ + //we've reached here probably because the show was + //cancelled, and therefore the show instance does not + //exist anymore (ShowInstance constructor threw this error). + //We've done all we can do (upload the file and put it in + //the library), now lets just return. } $this->view->id = $file->getId(); diff --git a/airtime_mvc/application/models/Shows.php b/airtime_mvc/application/models/Shows.php index 7b8a8d21e..83e63f41e 100644 --- a/airtime_mvc/application/models/Shows.php +++ b/airtime_mvc/application/models/Shows.php @@ -1173,16 +1173,21 @@ class Show { class ShowInstance { private $_instanceId; + private $_showInstance; public function __construct($instanceId) { $this->_instanceId = $instanceId; + $this->_showInstance = CcShowInstancesQuery::create()->findPK($instanceId); + + if (is_null($this->_showInstance)){ + throw new Exception(); + } } public function getShowId() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbShowId(); + return $this->_showInstance->getDbShowId(); } public function getShowInstanceId() @@ -1192,14 +1197,12 @@ class ShowInstance { public function isRebroadcast() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbOriginalShow(); + return $this->_showInstance->getDbOriginalShow(); } public function isRecorded() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbRecord(); + return $this->_showInstance->getDbRecord(); } public function getName() @@ -1216,14 +1219,12 @@ class ShowInstance { public function getShowStart() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbStarts(); + return $this->_showInstance->getDbStarts(); } public function getShowEnd() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbEnds(); + return $this->_showInstance->getDbEnds(); } public function getStartDate() @@ -1243,21 +1244,18 @@ class ShowInstance { public function setSoundCloudFileId($p_soundcloud_id) { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $showInstance->setDbSoundCloudId($p_soundcloud_id) + $this->_showInstance->setDbSoundCloudId($p_soundcloud_id) ->save(); } public function getSoundCloudFileId() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - return $showInstance->getDbSoundCloudId(); + return $this->_showInstance->getDbSoundCloudId(); } public function getRecordedFile() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $file_id = $showInstance->getDbRecordedFile(); + $file_id = $this->_showInstance->getDbRecordedFile(); if(isset($file_id)) { $file = StoredFile::Recall($file_id); @@ -1276,16 +1274,14 @@ class ShowInstance { public function setShowStart($start) { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $showInstance->setDbStarts($start) + $this->_showInstance->setDbStarts($start) ->save(); RabbitMq::PushSchedule(); } public function setShowEnd($end) { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $showInstance->setDbEnds($end) + $this->_showInstance->setDbEnds($end) ->save(); RabbitMq::PushSchedule(); } @@ -1293,8 +1289,7 @@ class ShowInstance { public function updateScheduledTime() { $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME); - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $showInstance->updateDbTimeFilled($con); + $this->_showInstance->updateDbTimeFilled($con); } public function correctScheduleStartTimes(){ @@ -1539,8 +1534,7 @@ class ShowInstance { public function getTimeScheduled() { - $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); - $time = $showInstance->getDbTimeFilled(); + $time = $this->_showInstance->getDbTimeFilled(); if(is_null($time)) { $time = "00:00:00"; diff --git a/install/include/AirtimeInstall.php b/install/include/AirtimeInstall.php index d240503a7..492250758 100644 --- a/install/include/AirtimeInstall.php +++ b/install/include/AirtimeInstall.php @@ -188,7 +188,7 @@ class AirtimeInstall echo "* Creating database tables".PHP_EOL; // Put Propel sql files in Database - $command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql 2>propel-error.log"; + $command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql"; @exec($command, $output, $results); } diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index 51871d7f5..367779a5a 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -73,7 +73,7 @@ class ShowRecorder(Thread): self.p = Popen(args) - #blocks at the following lines until the child process + #blocks at the following line until the child process #quits code = self.p.wait() self.p = None @@ -109,6 +109,7 @@ class ShowRecorder(Thread): code, filepath = self.record_show() if code == 0: + self.logger.info("Preparing to upload %s" % filepath) self.upload_file(filepath) else: self.logger.info("problem recording show")