diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f2fb9ff70..36b6bbe66 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -245,19 +245,14 @@ class ScheduleController extends Zend_Controller_Action public function clearShowAction() { - $showInstanceId = $this->_getParam('id'); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); - try { - $show = new Application_Model_ShowInstance($showInstanceId); - } catch (Exception $e) { - $this->view->show_error = true; + $instanceId = $this->_getParam('id'); + $service_scheduler = new Application_Service_SchedulerService(); + + if (!$service_scheduler->emptyShowContent($instanceId)) { + $this->view->show_error = true; return false; } - - if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)) || $user->isHostOfShow($show->getShowId())) - $show->clearShow(); } public function getCurrentPlaylistAction() diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 3778cf007..17888fe46 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -602,6 +602,12 @@ class Application_Model_Scheduler $nextStartDT = $endTimeDT; $pos++; + /* If we are adjusting start and end times for items + * after the insert location, we need to exclude the + * schedule item we just inserted because it has correct + * start and end times*/ + $excludeIds[] = $sched->getDbId(); + }//all files have been inserted/moved // update is_scheduled flag for each cc_file @@ -617,12 +623,6 @@ class Application_Model_Scheduler $filesToInsert = null; } - /* If we are adjusting start and end times for items - * after the insert location, we need to exclude the - * schedule item we just inserted because it has correct - * start and end times*/ - $excludeIds[] = $sched->getDbId(); - if ($adjustSched === true) { $followingSchedItems = CcScheduleQuery::create() ->filterByDBStarts($initalStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index b8086e4a2..6f1dcb920 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -204,4 +204,40 @@ class Application_Service_SchedulerService } //if at least one linked instance has content } } + + public function emptyShowContent($instanceId) + { + try { + $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId); + + $instances = array(); + + if ($ccShowInstance->getCcShow()->isLinked()) { + $instanceIds = array(); + foreach ($ccShowInstance->getCcShow()->getCcShowInstancess() as $instance) { + $instanceIds[] = $instance->getDbId(); + $instances[] = $instance; + } + CcScheduleQuery::create() + ->filterByDbInstanceId($instanceIds, Criteria::IN) + ->delete(); + } else { + $instances[] = $ccShowInstance; + CcScheduleQuery::create() + ->filterByDbInstanceId($ccShowInstance->getDbId()) + ->delete(); + } + + Application_Model_RabbitMq::PushSchedule(); + $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME); + foreach ($instances as $instance) { + $instance->updateDbTimeFilled($con); + } + + return true; + } catch (Exception $e) { + Logging::info($e->getMessage()); + return false; + } + } } \ No newline at end of file