From c55a3a4d7425ff34fd9739127ffde2869c18f5f8 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 25 Aug 2014 14:45:04 -0400 Subject: [PATCH 01/16] Use SSL with Recaptcha to fix it --- airtime_mvc/application/forms/Login.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/forms/Login.php b/airtime_mvc/application/forms/Login.php index 302a06ac0..02e942079 100644 --- a/airtime_mvc/application/forms/Login.php +++ b/airtime_mvc/application/forms/Login.php @@ -76,7 +76,8 @@ class Application_Form_Login extends Zend_Form $pubKey = '6Ld4JsISAAAAAIxUKT4IjjOGi3DHqdoH2zk6WkYG'; $privKey = '6Ld4JsISAAAAAJynYlXdrE4hfTReTSxYFe5szdyv'; - $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey); + $params= array('ssl' => true); + $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey, $params); $captcha = new Zend_Form_Element_Captcha('captcha', array( From 192c4e884f386faf77a8278a4630deabd377ab03 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 25 Aug 2014 14:18:23 -0400 Subject: [PATCH 02/16] Bugfix in LocaleController --- airtime_mvc/application/controllers/LocaleController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/LocaleController.php b/airtime_mvc/application/controllers/LocaleController.php index 1e12dbca3..da921f055 100644 --- a/airtime_mvc/application/controllers/LocaleController.php +++ b/airtime_mvc/application/controllers/LocaleController.php @@ -16,9 +16,8 @@ class LocaleController extends Zend_Controller_Action $locale = Application_Model_Preference::GetLocale(); echo "var datatables_dict =" . file_get_contents(Application_Common_OsPath::join( - $_SERVER["DOCUMENT_ROOT"], - $baseUrl, - "js/datatables/i18n/", + dirname(__file__), + "../../public/js/datatables/i18n/", $locale.".txt") ); } From afc3d981e80902e985044f44768744ffb960bad1 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 15 Aug 2014 15:32:52 -0400 Subject: [PATCH 03/16] Commented out unnecessary functions using too much memory --- .../application/services/ShowService.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index f484ee670..34fa6e689 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -362,10 +362,10 @@ class Application_Service_ShowService } } - if (isset($this->linkedShowContent)) { + /*if (isset($this->linkedShowContent)) { Application_Service_SchedulerService::fillPreservedLinkedShowContent( $this->ccShow, $this->linkedShowContent); - } + }*/ return $this->ccShow; } @@ -544,9 +544,9 @@ SQL; if (count($daysRemoved) > 0) { //delete repeating show instances for the repeating //days that were removed - if ($this->ccShow->isLinked()) { + /*if ($this->ccShow->isLinked()) { $this->preserveLinkedShowContent(); - } + }*/ $this->deleteRemovedShowDayInstances($daysRemoved, $ccShowDays, $showId); } @@ -589,11 +589,11 @@ SQL; return $daysAdded; } - private function preserveLinkedShowContent() + /*private function preserveLinkedShowContent() { - /* Get show content from any future linked instance. It doesn't - * matter which instance since content is the same in all. - */ + // Get show content from any future linked instance. It doesn't + // matter which instance since content is the same in all. + // $ccShowInstance = $this->ccShow->getFutureCcShowInstancess()->getFirst(); if (!$ccShowInstance) { @@ -606,7 +606,7 @@ SQL; if (!$ccSchedules->isEmpty()) { $this->linkedShowContent = $ccSchedules; } - } + }*/ /* * returns a DateTime of the current show end date set to the timezone of the show. From ee52c7692cf9772c8af8ed4198f677a542b837da Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 18 Aug 2014 12:59:43 -0400 Subject: [PATCH 04/16] CC-5902: Linked Shows -> Replace content check assumes content of shows have the same number of tracks Conflicts: airtime_mvc/application/services/SchedulerService.php --- .../application/services/SchedulerService.php | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index b4f41ba0c..3b716291d 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -333,22 +333,32 @@ class Application_Service_SchedulerService } } - private static function replaceInstanceContentCheck($currentShowStamp, $showStamp) + private static function replaceInstanceContentCheck($currentShowStamp, $showStamp, $instance_id) { $counter = 0; - foreach ($showStamp as $item) { - if ($item["file_id"] != $currentShowStamp[$counter]["file_id"] || - $item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) { - /*CcScheduleQuery::create() - ->filterByDbInstanceId($ccShowInstance->getDbId()) - ->delete();*/ - $delete_sql = "DELETE FROM cc_schedule ". - "WHERE instance_id = {$currentShowStamp[$counter]["instance_id"]}"; - Application_Common_Database::prepareAndExecute( - $delete_sql, array(), Application_Common_Database::EXECUTE); - return true; - } - $counter += 1; + $erraseShow = false; + if (count($currentShowStamp) != count($showStamp)) { + $erraseShow = true; + } else { + foreach ($showStamp as $item) { + if ($item["file_id"] != $currentShowStamp[$counter]["file_id"] || + $item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) { + $erraseShow = true; + break; + /*CcScheduleQuery::create() + ->filterByDbInstanceId($ccShowInstance->getDbId()) + ->delete();*/ + } + $counter += 1; + } + } + + if ($erraseShow) { + $delete_sql = "DELETE FROM cc_schedule ". + "WHERE instance_id = {$instance_id}"; + Application_Common_Database::prepareAndExecute( + $delete_sql, array(), Application_Common_Database::EXECUTE); + return true; } /* If we get here, the content in the show instance is the same From 81357bc51f5ab901ce59f534ab391ce8c2962af1 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 18 Aug 2014 18:10:45 -0400 Subject: [PATCH 05/16] CC-5904: New linked show instances may get an old copy of the schedule --- .../application/models/airtime/CcShow.php | 19 +++++ .../application/services/SchedulerService.php | 69 +++++++++++-------- 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index cd16bb7a2..666fdb2d9 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -288,7 +288,26 @@ class CcShow extends BaseCcShow { } return $instanceIds; } + + /* + * Returns all show instances ordered by 'starts' column in desc order. + */ + public function getInstanceIdsSortedByMostRecentStartTime() + { + $instances = CcShowInstancesQuery::create() + ->filterByCcShow($this) + ->filterByDbModifiedInstance(false) + ->orderByDbStarts(Criteria::DESC) + ->find(); + + $instanceIdsDescOrder = array(); + foreach ($instances as $instance) { + $instanceIdsDescOrder[] = $instance->getDbId(); + } + return $instanceIdsDescOrder; + } + //what is this?? public function getOtherInstances($instanceId) { return CcShowInstancesQuery::create() diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 3b716291d..61796d34e 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -152,15 +152,25 @@ class Application_Service_SchedulerService public static function fillNewLinkedInstances($ccShow) { - /* First check if any linked instances have content - * If all instances are empty then we don't need to fill - * any other instances with content + /* In order to get the linked show's schedule we need to retrieve + * every instance of the show, even if they are in the past in case + * no new instances were generated past the 'shows_populated_until' + * date in cc_pref - CC-5898 + * + * We retrieve the instances ids sorted by desc start date to ensure + * we always use the most up to date schedule when filling the new + * show instances with content */ - $instanceIds = $ccShow->getInstanceIds(); + + $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); if (count($instanceIds) == 0) { return; } + /* First check if any linked instances have content + * If all instances are empty then we don't need to fill + * any other instances with content + */ $doesAnyShowInstanceHaveContent = false; foreach ($instanceIds as $instanceId) { @@ -181,29 +191,31 @@ class Application_Service_SchedulerService return; } - /* Find the show contents of just one of the instances. It doesn't - * matter which instance we use since all the content is the same - */ - $ccSchedule = $ccSchedules[0]; - $showStamp_sql = "SELECT * FROM cc_schedule ". - "WHERE instance_id = {$ccSchedule["instance_id"]} ". - "ORDER BY starts"; - $showStamp = Application_Common_Database::prepareAndExecute( - $showStamp_sql); - - //get time_filled so we can update cc_show_instances - $timeFilled_sql = "SELECT time_filled FROM cc_show_instances ". - "WHERE id = {$ccSchedule["instance_id"]}"; - $timeFilled = Application_Common_Database::prepareAndExecute( - $timeFilled_sql, array(), Application_Common_Database::COLUMN); - - //need to find out which linked instances are empty - $values = array(); - $futureInstanceIds = $ccShow->getFutureInstanceIds(); - $con = Propel::getConnection(); - try { - $con->beginTransaction(); - foreach ($instanceIds as $id) + /* Find the show contents of just one of the instances. Because we + * sorted the instances by desc order, we are using the most recent + * instance, which will have the most up to date schedule. + */ + $ccSchedule = $ccSchedules[0]; + $showStamp_sql = "SELECT * FROM cc_schedule ". + "WHERE instance_id = {$ccSchedule["instance_id"]} ". + "ORDER BY starts"; + $showStamp = Application_Common_Database::prepareAndExecute( + $showStamp_sql); + Logging::info(count($showStamp)); + Logging::info($showStamp[0]); + //get time_filled so we can update cc_show_instances + $timeFilled_sql = "SELECT time_filled FROM cc_show_instances ". + "WHERE id = {$ccSchedule["instance_id"]}"; + $timeFilled = Application_Common_Database::prepareAndExecute( + $timeFilled_sql, array(), Application_Common_Database::COLUMN); + + //need to find out which linked instances are empty + $values = array(); + $futureInstanceIds = $ccShow->getFutureInstanceIds(); + $con = Propel::getConnection(); + try { + $con->beginTransaction(); + foreach ($futureInstanceIds as $id) { $instanceSched_sql = "SELECT * FROM cc_schedule ". "WHERE instance_id = {$id} ". @@ -217,7 +229,7 @@ class Application_Service_SchedulerService * (The show stamp is taken from the first show instance's content) */ if (count($ccSchedules) < 1 || - self::replaceInstanceContentCheck($ccSchedules, $showStamp)) + self::replaceInstanceContentCheck($ccSchedules, $showStamp, $id)) { $instanceStart_sql = "SELECT starts FROM cc_show_instances ". @@ -264,7 +276,6 @@ class Application_Service_SchedulerService "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); } From 9a6e617f7c42df10a0016994373bb4cfd9358517 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 18 Aug 2014 18:55:03 -0400 Subject: [PATCH 06/16] CC-5904: New linked show instances may get an old copy of the schedule Better way of getting show stamp Renamed variables --- .../application/services/SchedulerService.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 61796d34e..b39f491ed 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -163,6 +163,8 @@ class Application_Service_SchedulerService */ $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); + $mostRecentInstanceId = $instanceIds[0]; + if (count($instanceIds) == 0) { return; } @@ -183,6 +185,8 @@ class Application_Service_SchedulerService break; } } + //variable out of scope outside foreach loop + unset($ccSchedules); if ($doesAnyShowInstanceHaveContent == false) { @@ -195,17 +199,14 @@ class Application_Service_SchedulerService * sorted the instances by desc order, we are using the most recent * instance, which will have the most up to date schedule. */ - $ccSchedule = $ccSchedules[0]; $showStamp_sql = "SELECT * FROM cc_schedule ". - "WHERE instance_id = {$ccSchedule["instance_id"]} ". + "WHERE instance_id = $mostRecentInstanceId ". "ORDER BY starts"; $showStamp = Application_Common_Database::prepareAndExecute( $showStamp_sql); - Logging::info(count($showStamp)); - Logging::info($showStamp[0]); //get time_filled so we can update cc_show_instances $timeFilled_sql = "SELECT time_filled FROM cc_show_instances ". - "WHERE id = {$ccSchedule["instance_id"]}"; + "WHERE id = $mostRecentInstanceId"; $timeFilled = Application_Common_Database::prepareAndExecute( $timeFilled_sql, array(), Application_Common_Database::COLUMN); @@ -221,15 +222,15 @@ class Application_Service_SchedulerService "WHERE instance_id = {$id} ". "ORDER by starts"; - $ccSchedules = Application_Common_Database::prepareAndExecute( + $showInstanceContents = Application_Common_Database::prepareAndExecute( $instanceSched_sql); /* If the show instance is empty OR it has different content than * the first instance, we need to fill/replace with the show stamp * (The show stamp is taken from the first show instance's content) */ - if (count($ccSchedules) < 1 || - self::replaceInstanceContentCheck($ccSchedules, $showStamp, $id)) + if (count($showInstanceContents) < 1 || + self::replaceInstanceContentCheck($showInstanceContents, $showStamp, $id)) { $instanceStart_sql = "SELECT starts FROM cc_show_instances ". From 08e82cb32e697ad589b6cf4d18951df3212e44a7 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 18 Aug 2014 19:27:42 -0400 Subject: [PATCH 07/16] CC-5904: New linked show instances may get an old copy of the schedule Change the way get the show stamp --- airtime_mvc/application/services/SchedulerService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index b39f491ed..c5dfe1fdc 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -199,8 +199,10 @@ class Application_Service_SchedulerService * sorted the instances by desc order, we are using the most recent * instance, which will have the most up to date schedule. */ + $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + $showStamp_sql = "SELECT * FROM cc_schedule ". - "WHERE instance_id = $mostRecentInstanceId ". + "WHERE starts < '{$showsPopulatedUntil->format('Y-m-d H:i:s')}' ". "ORDER BY starts"; $showStamp = Application_Common_Database::prepareAndExecute( $showStamp_sql); @@ -232,7 +234,7 @@ class Application_Service_SchedulerService if (count($showInstanceContents) < 1 || self::replaceInstanceContentCheck($showInstanceContents, $showStamp, $id)) { - +Logging::info($showStamp_sql); $instanceStart_sql = "SELECT starts FROM cc_show_instances ". "WHERE id = {$id} ". "ORDER BY starts"; From 57c1e76dc7a4a5aea39dc9852c8df08f8f621d35 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 20 Aug 2014 16:35:59 -0400 Subject: [PATCH 08/16] Added criteria parameter to CcShow->getFutureInstanceIds so we can retrieve results from database instead of cache --- airtime_mvc/application/models/airtime/CcShow.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index 666fdb2d9..fac6aee00 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -281,9 +281,16 @@ class CcShow extends BaseCcShow { return $instanceIds; } - public function getFutureInstanceIds() { + /* + * Returns cc_show_instance ids where the start time is greater than + * the current time + * + * If a Criteria object is passed in Propel will always fetch the + * results from the database and not return a cached collection + */ + public function getFutureInstanceIds($criteria = null) { $instanceIds = array(); - foreach ($this->getFutureCcShowInstancess() as $ccShowInstance) { + foreach ($this->getFutureCcShowInstancess($criteria) as $ccShowInstance) { $instanceIds[] = $ccShowInstance->getDbId(); } return $instanceIds; From d81de5c6eb623d7096401abd21b1826fb10181ba Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 20 Aug 2014 16:37:44 -0400 Subject: [PATCH 09/16] Better way of getting the linked show schedule and moved that into its own function. Store the ids of the new, created show instances so we can pass them to the fillNewLinkedInstances function --- .../application/services/SchedulerService.php | 94 ++++++++++++------- .../application/services/ShowService.php | 40 ++++++-- 2 files changed, 93 insertions(+), 41 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index c5dfe1fdc..94d81643a 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -150,7 +150,37 @@ class Application_Service_SchedulerService return $dt; } - public static function fillNewLinkedInstances($ccShow) + public static function getLinkedShowSchedule($showId, $instancsIdsToFill) + { + $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + + $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() + ->filterByDbShowId($showId) + ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) + ->filterByDbId($instancsIdsToFill, Criteria::NOT_IN) + ->orderByDbStarts(Criteria::DESC) + ->limit(1) + ->findOne(); + + $con = Propel::getConnection(); + $instanceId = $showInstanceWithMostRecentSchedule->getDbId(); + $linkedShowSchedule_sql = $con->prepare( + "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(); + } + + /** + * + * Enter description here ... + * @param CcShow_type $ccShow + * @param array $instanceIdsToFill ids of the new linked cc_show_instances that + * were created and now need their schedules filled + */ + public static function fillNewLinkedInstances($ccShow, $instanceIdsToFill) { /* In order to get the linked show's schedule we need to retrieve * every instance of the show, even if they are in the past in case @@ -163,8 +193,6 @@ class Application_Service_SchedulerService */ $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); - $mostRecentInstanceId = $instanceIds[0]; - if (count($instanceIds) == 0) { return; } @@ -195,30 +223,28 @@ class Application_Service_SchedulerService return; } - /* Find the show contents of just one of the instances. Because we - * sorted the instances by desc order, we are using the most recent - * instance, which will have the most up to date schedule. - */ - $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + $linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill); - $showStamp_sql = "SELECT * FROM cc_schedule ". - "WHERE starts < '{$showsPopulatedUntil->format('Y-m-d H:i:s')}' ". - "ORDER BY starts"; - $showStamp = Application_Common_Database::prepareAndExecute( - $showStamp_sql); //get time_filled so we can update cc_show_instances - $timeFilled_sql = "SELECT time_filled FROM cc_show_instances ". - "WHERE id = $mostRecentInstanceId"; - $timeFilled = Application_Common_Database::prepareAndExecute( - $timeFilled_sql, array(), Application_Common_Database::COLUMN); + if (!empty($linkedShowSchedule)) { + $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); + } else { + $timeFilled = "00:00:00"; + } //need to find out which linked instances are empty $values = array(); - $futureInstanceIds = $ccShow->getFutureInstanceIds(); + //pass in new criteria object so propel doesn't return cached results + //$futureInstanceIds = $ccShow->getFutureInstanceIds(new Criteria()); + $con = Propel::getConnection(); try { $con->beginTransaction(); - foreach ($futureInstanceIds as $id) + //foreach ($futureInstanceIds as $id) + foreach ($instanceIdsToFill as $id) { $instanceSched_sql = "SELECT * FROM cc_schedule ". "WHERE instance_id = {$id} ". @@ -228,13 +254,13 @@ class Application_Service_SchedulerService $instanceSched_sql); /* If the show instance is empty OR it has different content than - * the first instance, we need to fill/replace with the show stamp - * (The show stamp is taken from the first show instance's content) + * the most recent instance, we need to fill/replace with the linked + * show schedule */ if (count($showInstanceContents) < 1 || - self::replaceInstanceContentCheck($showInstanceContents, $showStamp, $id)) + self::replaceInstanceContentCheck($showInstanceContents, $linkedShowSchedule, $id)) { -Logging::info($showStamp_sql); + $instanceStart_sql = "SELECT starts FROM cc_show_instances ". "WHERE id = {$id} ". "ORDER BY starts"; @@ -246,7 +272,7 @@ Logging::info($showStamp_sql); $defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration(); unset($values); $values = array(); - foreach ($showStamp as $item) { + foreach ($linkedShowSchedule as $item) { $endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]); if (is_null($item["file_id"])) { @@ -283,16 +309,21 @@ Logging::info($showStamp_sql); $insert_sql, array(), Application_Common_Database::EXECUTE); } } + //update cc_schedule status column + $instance = CcShowInstancesQuery::create()->findPk($id); + $instance->updateScheduleStatus($con); } //foreach linked instance - //update time_filled in cc_show_instances + //update time_filled and last_scheduled in cc_show_instances $now = gmdate("Y-m-d H:i:s"); - $update_sql = "UPDATE cc_show_instances SET ". - "time_filled = '{$timeFilled}', ". - "last_scheduled = '{$now}' ". - "WHERE show_id = {$ccShow->getDbId()}"; - Application_Common_Database::prepareAndExecute( - $update_sql, array(), Application_Common_Database::EXECUTE); + $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"); @@ -366,7 +397,6 @@ Logging::info($showStamp_sql); $counter += 1; } } - if ($erraseShow) { $delete_sql = "DELETE FROM cc_schedule ". "WHERE instance_id = {$instance_id}"; diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 34fa6e689..be07a03fa 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -15,13 +15,18 @@ class Application_Service_ShowService private $isRebroadcast; private $repeatType; private $isUpdate; - private $linkedShowContent; + /*private $linkedShowContent;*/ private $oldShowTimezone; private $localShowStartHour; private $localShowStartMin; private $origCcShowDay; private $origShowRepeatStatus; private $instanceIdsForScheduleUpdates; + + //keeps track of which show instances are new from either adding a new show + //day or changing the repeat type day during a show edit, or when a user moves + //forward in the calendar + private $newInstanceIdsCreated; public function __construct($showId=null, $showData=null, $isUpdate=false) { @@ -42,6 +47,7 @@ class Application_Service_ShowService $this->isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0; $this->isUpdate = $isUpdate; $this->instanceIdsForScheduleUpdates = array(); + $this->newInstanceIdsCreated = array(); } public function editRepeatingShowInstance($showData) { @@ -323,8 +329,15 @@ class Application_Service_ShowService $this->isRecorded = $this->ccShow->isRecorded(); $this->isRebroadcast = $this->ccShow->isRebroadcast(); - if (!isset($ccShows[$day->getDbShowId()])) { - $ccShows[$day->getDbShowId()] = $day->getccShow(); + $show_id = $day->getDbShowId(); + if (!isset($ccShows[$show_id])) { + $ccShows[$show_id] = $day->getccShow(); + } + + //keep track of the new show instances getting created + //so we can fill their schedule after + if (!isset($this->newInstanceIdsCreated[$show_id])) { + $this->newInstanceIdsCreated[$show_id] = array(); } switch ($day->getDbRepeatType()) { @@ -358,7 +371,8 @@ class Application_Service_ShowService foreach ($ccShows as $ccShow) { if (($this->isUpdate || $fillInstances) && $ccShow->isLinked()) { - Application_Service_SchedulerService::fillNewLinkedInstances($ccShow); + Application_Service_SchedulerService::fillNewLinkedInstances( + $ccShow, $this->newInstanceIdsCreated[$ccShow->getDbId()]); } } @@ -1131,16 +1145,16 @@ SQL; if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - $updateScheduleStatus = true; + //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - $updateScheduleStatus = false; + //$updateScheduleStatus = false; } } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - $updateScheduleStatus = false; + //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1153,6 +1167,10 @@ SQL; $ccShowInstance->setDbRecord($record); $ccShowInstance->save(); } + + if ($newInstance) { + array_push($this->newInstanceIdsCreated[$show_id], $ccShowInstance->getDbId()); + } if ($this->isRebroadcast) { $this->createRebroadcastInstances($showDay, $date, $ccShowInstance->getDbId()); @@ -1229,11 +1247,11 @@ SQL; if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - $updateScheduleStatus = true; + //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - $updateScheduleStatus = false; + //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1246,6 +1264,10 @@ SQL; $ccShowInstance->setDbRecord($record); $ccShowInstance->save(); } + + if ($newInstance) { + array_push($this->newInstanceIdsCreated[$show_id], $ccShowInstance->getDbId()); + } if ($this->isRebroadcast) { $this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId()); From 29c07f24386475dc5f4df4121f8bfa37e5a965d7 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 21 Aug 2014 09:47:54 -0400 Subject: [PATCH 10/16] Removed old comments --- .../application/services/SchedulerService.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 94d81643a..64f8833a2 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -182,15 +182,7 @@ class Application_Service_SchedulerService */ public static function fillNewLinkedInstances($ccShow, $instanceIdsToFill) { - /* In order to get the linked show's schedule we need to retrieve - * every instance of the show, even if they are in the past in case - * no new instances were generated past the 'shows_populated_until' - * date in cc_pref - CC-5898 - * - * We retrieve the instances ids sorted by desc start date to ensure - * we always use the most up to date schedule when filling the new - * show instances with content - */ + //TODO can we remove the code until line 216 ?? $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); if (count($instanceIds) == 0) { @@ -221,7 +213,7 @@ class Application_Service_SchedulerService //The linked shows are all empty, so there's nothing for us to do. //(No content should be propagated to the other show instances... return; - } + } $linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill); From e3596dfed3794846a191b60f0e71916f59b66139 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 15 Oct 2014 17:11:38 -0400 Subject: [PATCH 11/16] Added comments and removed some unused code --- .../application/services/SchedulerService.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 64f8833a2..dc4d1efbc 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -150,10 +150,20 @@ class Application_Service_SchedulerService return $dt; } + /** + * + * Gets a copy of the linked show's schedule from cc_schedule table + * The schedule is taken from the most recent show instance that existed + * before new show instances were created. + * + * @param integer $showId + * @param array $instancsIdsToFill + */ public static function getLinkedShowSchedule($showId, $instancsIdsToFill) { $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() ->filterByDbShowId($showId) ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) @@ -175,7 +185,9 @@ class Application_Service_SchedulerService /** * - * Enter description here ... + * This function gets called after new linked show_instances are created. + * It fills the new show instances' schedules. + * * @param CcShow_type $ccShow * @param array $instanceIdsToFill ids of the new linked cc_show_instances that * were created and now need their schedules filled @@ -229,13 +241,10 @@ class Application_Service_SchedulerService //need to find out which linked instances are empty $values = array(); - //pass in new criteria object so propel doesn't return cached results - //$futureInstanceIds = $ccShow->getFutureInstanceIds(new Criteria()); $con = Propel::getConnection(); try { $con->beginTransaction(); - //foreach ($futureInstanceIds as $id) foreach ($instanceIdsToFill as $id) { $instanceSched_sql = "SELECT * FROM cc_schedule ". @@ -249,6 +258,7 @@ class Application_Service_SchedulerService * the most recent instance, we need to fill/replace with the linked * show schedule */ + //TODO can this check be removed? if (count($showInstanceContents) < 1 || self::replaceInstanceContentCheck($showInstanceContents, $linkedShowSchedule, $id)) { From 32e06a7456c02c42d2593d34bfc842405165d81c Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 21 Aug 2014 13:39:25 -0400 Subject: [PATCH 12/16] Clean up and simplifcation of linked show filling --- .../application/services/SchedulerService.php | 155 +++++++++--------- 1 file changed, 80 insertions(+), 75 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index dc4d1efbc..36d16356d 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -196,15 +196,15 @@ class Application_Service_SchedulerService { //TODO can we remove the code until line 216 ?? + /* $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); if (count($instanceIds) == 0) { return; } - /* First check if any linked instances have content - * If all instances are empty then we don't need to fill - * any other instances with content - */ + //First check if any linked instances have content + //If all instances are empty then we don't need to fill + //any other instances with content $doesAnyShowInstanceHaveContent = false; foreach ($instanceIds as $instanceId) { @@ -226,7 +226,10 @@ class Application_Service_SchedulerService //(No content should be propagated to the other show instances... return; } + */ + //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); //get time_filled so we can update cc_show_instances @@ -236,81 +239,72 @@ class Application_Service_SchedulerService $timeFilled = Application_Common_Database::prepareAndExecute( $timeFilled_sql, array(), 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"; } - //need to find out which linked instances are empty $values = array(); $con = Propel::getConnection(); + + //Here we begin to fill the new show instances (as specified by $instanceIdsToFill) + //with content from $linkedShowSchedule. try { $con->beginTransaction(); foreach ($instanceIdsToFill as $id) { - $instanceSched_sql = "SELECT * FROM cc_schedule ". - "WHERE instance_id = {$id} ". - "ORDER by starts"; - - $showInstanceContents = Application_Common_Database::prepareAndExecute( - $instanceSched_sql); - - /* If the show instance is empty OR it has different content than - * the most recent instance, we need to fill/replace with the linked - * show schedule - */ - //TODO can this check be removed? - if (count($showInstanceContents) < 1 || - self::replaceInstanceContentCheck($showInstanceContents, $linkedShowSchedule, $id)) - { - - $instanceStart_sql = "SELECT starts FROM cc_show_instances ". - "WHERE id = {$id} ". - "ORDER BY starts"; - $nextStartDT = new DateTime( - Application_Common_Database::prepareAndExecute( - $instanceStart_sql, array(), Application_Common_Database::COLUMN), - new DateTimeZone("UTC")); - - $defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration(); - unset($values); - $values = array(); - foreach ($linkedShowSchedule as $item) { - $endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]); - - if (is_null($item["file_id"])) { - $item["file_id"] = "null"; - } - if (is_null($item["stream_id"])) { - $item["stream_id"] = "null"; - } - - $values[] = "(". - "'{$nextStartDT->format("Y-m-d H:i:s")}', ". - "'{$endTimeDT->format("Y-m-d H:i:s")}', ". - "'{$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); - - } //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, ","); + //Start by clearing the show instance that needs to be filling. This ensure + //we're not going to get in trouble in case there's an programming error somewhere else. + 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"; + + //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( - $insert_sql, array(), Application_Common_Database::EXECUTE); + $instanceStart_sql, array(), + Application_Common_Database::COLUMN), + new DateTimeZone("UTC")); + + $defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration(); + unset($values); + $values = array(); + foreach ($linkedShowSchedule as $item) { + $endTimeDT = self::findEndTime($nextStartDT, + $item["clip_length"]); + + if (is_null($item["file_id"])) { + $item["file_id"] = "null"; } - } + if (is_null($item["stream_id"])) { + $item["stream_id"] = "null"; + } + + $values[] = "(" . "'{$nextStartDT->format("Y-m-d H:i:s")}', " . + "'{$endTimeDT->format("Y-m-d H:i:s")}', " . + "'{$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); + } //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, ","); + Application_Common_Database::prepareAndExecute( + $insert_sql, array(), Application_Common_Database::EXECUTE); + } + //update cc_schedule status column $instance = CcShowInstancesQuery::create()->findPk($id); $instance->updateScheduleStatus($con); @@ -380,6 +374,17 @@ class Application_Service_SchedulerService } } + /** Clears a show instance's schedule (which is actually clearing cc_schedule during that show instance's time slot.) */ + private static function clearShowInstanceContents($instanceId) + { + //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->bindParam(':instance_id', $instanceId); + $query->execute(); + } + + /* private static function replaceInstanceContentCheck($currentShowStamp, $showStamp, $instance_id) { $counter = 0; @@ -392,26 +397,26 @@ class Application_Service_SchedulerService $item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) { $erraseShow = true; break; - /*CcScheduleQuery::create() - ->filterByDbInstanceId($ccShowInstance->getDbId()) - ->delete();*/ + //CcScheduleQuery::create() + // ->filterByDbInstanceId($ccShowInstance->getDbId()) + // ->delete(); } $counter += 1; } } if ($erraseShow) { $delete_sql = "DELETE FROM cc_schedule ". - "WHERE instance_id = {$instance_id}"; + "WHERE instance_id = :instance_id"; Application_Common_Database::prepareAndExecute( $delete_sql, array(), Application_Common_Database::EXECUTE); return true; } - /* 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 - */ + //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; - } + }*/ public function emptyShowContent($instanceId) { From 10cb5484fee4df053df678a870afa33ee50c56e3 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 21 Aug 2014 16:40:01 -0400 Subject: [PATCH 13/16] Removed unused function. Removed commented out code. Renamed fillNewLinkedInstances to fillLinkedInstances. Streamline show instance content if a show goes from unlinked to linked. --- .../application/models/airtime/CcShow.php | 18 ------- .../application/services/SchedulerService.php | 53 ++++++++++++------- .../application/services/ShowService.php | 21 ++++---- .../public/js/airtime/schedule/add-show.js | 13 +++-- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index fac6aee00..b9f140e3e 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -295,24 +295,6 @@ class CcShow extends BaseCcShow { } return $instanceIds; } - - /* - * Returns all show instances ordered by 'starts' column in desc order. - */ - public function getInstanceIdsSortedByMostRecentStartTime() - { - $instances = CcShowInstancesQuery::create() - ->filterByCcShow($this) - ->filterByDbModifiedInstance(false) - ->orderByDbStarts(Criteria::DESC) - ->find(); - - $instanceIdsDescOrder = array(); - foreach ($instances as $instance) { - $instanceIdsDescOrder[] = $instance->getDbId(); - } - return $instanceIdsDescOrder; - } //what is this?? public function getOtherInstances($instanceId) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 36d16356d..60509390a 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -153,46 +153,59 @@ class Application_Service_SchedulerService /** * * Gets a copy of the linked show's schedule from cc_schedule table - * The schedule is taken from the most recent show instance that existed - * before new show instances were created. + * + * 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 + * 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 array $instancsIdsToFill + * @param integer $instanceId */ - public static function getLinkedShowSchedule($showId, $instancsIdsToFill) + private static function getLinkedShowSchedule($showId, $instancsIdsToFill, $instanceId) { - $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); - - - $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() - ->filterByDbShowId($showId) - ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) - ->filterByDbId($instancsIdsToFill, Criteria::NOT_IN) - ->orderByDbStarts(Criteria::DESC) - ->limit(1) - ->findOne(); - $con = Propel::getConnection(); - $instanceId = $showInstanceWithMostRecentSchedule->getDbId(); + + if (is_null($instanceId)) { + $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + + $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() + ->filterByDbShowId($showId) + ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) + ->filterByDbId($instancsIdsToFill, Criteria::NOT_IN) + ->orderByDbStarts(Criteria::DESC) + ->limit(1) + ->findOne(); + + $instanceId = $showInstanceWithMostRecentSchedule->getDbId(); + } + $linkedShowSchedule_sql = $con->prepare( "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. + * 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 - * were created and now need their schedules filled + * need their schedules filled */ - public static function fillNewLinkedInstances($ccShow, $instanceIdsToFill) + public static function fillLinkedInstances($ccShow, $instanceIdsToFill, $instanceId=null) { //TODO can we remove the code until line 216 ?? @@ -230,7 +243,7 @@ class Application_Service_SchedulerService //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); + $linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill, $instanceId); //get time_filled so we can update cc_show_instances if (!empty($linkedShowSchedule)) { diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index be07a03fa..5a2f22e63 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -15,7 +15,6 @@ class Application_Service_ShowService private $isRebroadcast; private $repeatType; private $isUpdate; - /*private $linkedShowContent;*/ private $oldShowTimezone; private $localShowStartHour; private $localShowStartMin; @@ -199,6 +198,7 @@ class Application_Service_ShowService $daysAdded = array(); if ($this->isUpdate) { + if (!$this->ccShow->getCcShowDayss()->isEmpty()) { $this->storeOrigLocalShowInfo(); } @@ -371,7 +371,7 @@ class Application_Service_ShowService foreach ($ccShows as $ccShow) { if (($this->isUpdate || $fillInstances) && $ccShow->isLinked()) { - Application_Service_SchedulerService::fillNewLinkedInstances( + Application_Service_SchedulerService::fillLinkedInstances( $ccShow, $this->newInstanceIdsCreated[$ccShow->getDbId()]); } } @@ -1145,16 +1145,13 @@ SQL; if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1247,11 +1244,9 @@ SQL; if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1520,10 +1515,14 @@ SQL; $ccShow->setDbLiveStreamUsingCustomAuth($showData['cb_custom_auth'] == 1); $ccShow->setDbLiveStreamUser($showData['custom_username']); $ccShow->setDbLiveStreamPass($showData['custom_password']); - - // Once a show is unlinked it cannot be linked again - if ($ccShow->getDbLinked() && !$showData["add_show_linked"]) { - $ccShow->setDbIsLinkable(false); + + //Here a user has edited a show and linked it. + //We need to grab the existing show instances ids and fill their content + //with the content from the show instance that was clicked on to edit the show. + //We do this because linked show instances need to have the same content in each. + if ($this->isUpdate && (!$ccShow->getDbLinked() && $showData["add_show_linked"])) { + $existingShowInstanceIds = $ccShow->getFutureInstanceIds(new Criteria()); + Application_Service_SchedulerService::fillLinkedInstances($ccShow, $existingShowInstanceIds, $showData["add_show_instance_id"]); } $ccShow->setDbLinked($showData["add_show_linked"]); diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 6ec2996b3..307a5c2c6 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -273,9 +273,16 @@ function setAddShowEvents(form) { } return false; } - - if (!$(this).attr("checked") && $("#show-link-warning").length === 0) { - $(this).parent().after(""); + + //only display the warning message if a show is being edited + if ($(".button-bar.bottom").find(".ui-button-text").text() === "Update show") { + if ($(this).attr("checked") && $("#show-link-warning").length === 0) { + $(this).parent().after(""); + } + + if (!$(this).attr("checked") && $("#show-link-warning").length !== 0) { + $("#show-link-warning").remove(); + } } }); From 20a5649dbe45932725d857f7d906a81ebf8f489c Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 21 Aug 2014 17:12:54 -0400 Subject: [PATCH 14/16] Removed unused code. Changed linked show warning message in the edit show form. --- .../application/services/SchedulerService.php | 34 ------------------- .../public/js/airtime/schedule/add-show.js | 2 +- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 60509390a..a31bd380a 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -207,40 +207,6 @@ class Application_Service_SchedulerService */ public static function fillLinkedInstances($ccShow, $instanceIdsToFill, $instanceId=null) { - //TODO can we remove the code until line 216 ?? - - /* - $instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime(); - if (count($instanceIds) == 0) { - return; - } - - //First check if any linked instances have content - //If all instances are empty then we don't need to fill - //any other instances with content - $doesAnyShowInstanceHaveContent = false; - foreach ($instanceIds as $instanceId) - { - $schedule_sql = "SELECT instance_id FROM cc_schedule ". - "WHERE instance_id=$instanceId";//#IN (".implode($instanceIds, ",").")"; - $ccSchedules = Application_Common_Database::prepareAndExecute( - $schedule_sql); - if (count($ccSchedules) > 0) { - $doesAnyShowInstanceHaveContent = true; - break; - } - } - //variable out of scope outside foreach loop - unset($ccSchedules); - - if ($doesAnyShowInstanceHaveContent == false) - { - //The linked shows are all empty, so there's nothing for us to do. - //(No content should be propagated to the other show instances... - return; - } - */ - //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); diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 307a5c2c6..5e0ad5b37 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -277,7 +277,7 @@ function setAddShowEvents(form) { //only display the warning message if a show is being edited if ($(".button-bar.bottom").find(".ui-button-text").text() === "Update show") { if ($(this).attr("checked") && $("#show-link-warning").length === 0) { - $(this).parent().after(""); + $(this).parent().after(""); } if (!$(this).attr("checked") && $("#show-link-warning").length !== 0) { From 871ddb47d8006e9aa106a93a3088e60df3ee9c41 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 21 Aug 2014 17:56:00 -0400 Subject: [PATCH 15/16] Removed database test that confirms the is_linkable is set to false after a show is un-linked. Since we removed this behaviour from Airtime, and a show can be linked and unlinked as many times as the user wants, this test is deprecated. --- .../services/database/ShowServiceDbTest.php | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php index 8a7f54f1b..e8c03a57c 100644 --- a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php +++ b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php @@ -442,26 +442,6 @@ class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createLinkedShow.xml"), $ds ); - - /** Test unlinking a show **/ - $data["add_show_id"] = 1; - $data["add_show_linked"] = 0; - $showService = new Application_Service_ShowService(null, $data, true); - $showService->addUpdateShow($data); - - $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet( - $this->getConnection() - ); - $ds->addTable('cc_show', 'select * from cc_show'); - $ds->addTable('cc_show_days', 'select * from cc_show_days'); - $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances order by id'); - $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast'); - $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts'); - - $this->assertDataSetsEqual( - $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_unlinkLinkedShow.xml"), - $ds - ); } /** Test the creation of a single record and rebroadcast(RR) show **/ From d1971b6d2bdc6e45b11685706250449c6420d415 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 26 Aug 2014 13:32:35 -0400 Subject: [PATCH 16/16] Remove cc_locale table and add Selenium running script * Fixes CC-5906 --- airtime_mvc/application/models/Locale.php | 36 +++++++++++++------ airtime_mvc/build/schema.xml | 5 --- tests/README | 13 +++++++ tests/run_selenium.sh | 43 +++++++++++++++++++++++ 4 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 tests/README create mode 100755 tests/run_selenium.sh diff --git a/airtime_mvc/application/models/Locale.php b/airtime_mvc/application/models/Locale.php index c07c9974c..328344496 100644 --- a/airtime_mvc/application/models/Locale.php +++ b/airtime_mvc/application/models/Locale.php @@ -2,17 +2,32 @@ class Application_Model_Locale { + public static $locales = array( + "en_CA" => "English (Canada)", + "en_GB" => "English (Britain)", + "en_US" => "English (USA)", + "cs_CZ" => "Český", + "de_DE" => "Deutsch", + "de_AT" => "Deutsch (Österreich)", + "el_GR" => "Ελληνικά", + "es_ES" => "Español", + "fr_FR" => "Français", + "hr_HR" => "Hrvatski", + "hu_HU" => "Magyar", + "it_IT" => "Italiano", + //"ja" => "日本語", + "ko_KR" => "한국어", + "pl_PL" => "Polski", + "pt_BR" => "Português (Brasil)", + "ru_RU" => "Русский", + "sr_RS" => "Српски (Ћирилица)", + "sr_RS@latin" => "Srpski (Latinica)", + "zh_CN" => "简体中文" + ); + public static function getLocales() { - $con = Propel::getConnection(); - $sql = "SELECT * FROM cc_locale"; - $res = Application_Common_Database::prepareAndExecute($sql); - $out = array(); - foreach ($res as $r) { - $out[$r["locale_code"]] = $r["locale_lang"]; - } - - return $out; + return self::$locales; } public static function configureLocalization($locale = null) @@ -32,4 +47,5 @@ class Application_Model_Locale textdomain($domain); bind_textdomain_codeset($domain, $codeset); } -} \ No newline at end of file +} + diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index d5ba76516..6dea9ac7c 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -474,11 +474,6 @@ - - - - -
diff --git a/tests/README b/tests/README new file mode 100644 index 000000000..60dff673d --- /dev/null +++ b/tests/README @@ -0,0 +1,13 @@ +Airtime Tests + +Selenium: +- No prerequisites required. +- To set it up and run it, run: + $ ./run_selenium.sh + + +Airtime web app unit tests: +- See airtime_mvc/tests/README + +Airtime Analyzer unit tests +- See python_app/airtime_analyzer/README diff --git a/tests/run_selenium.sh b/tests/run_selenium.sh new file mode 100755 index 000000000..761c386ae --- /dev/null +++ b/tests/run_selenium.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +SELENIUM_BIN=selenium-server-standalone-2.42.2.jar +SELENIUM_URL=http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar + +printUsage() +{ + echo "Usage: ${0} airtime_url" + echo " Example: ${0} http://bananas.airtime.pro" +} +if [ -z "$1" ] +then + printUsage + exit 1 +fi + +AIRTIME_URL="${1}" + +# Check if java is installed +which java >& /dev/null +if [ $? -gt 0 ] +then + echo "java not found. Please install it." +fi + +# Check for selenium-server +if [ ! -f ${SELENIUM_BIN} ] +then + echo "Selenium not found, downloading it..." + wget ${SELENIUM_URL} +fi + +# Check for xvfb-run, which lets us run Firefox in a headless X server +which xvfb-run >& /dev/null +if [ $? -gt 0 ] +then + echo "xvfb-run not found, apt-getting it now..." + sudo apt-get install xvfb +fi + +# You must pass the full path to the HTML suite and the results file to Selenium: +xvfb-run java -jar ${SELENIUM_BIN} -htmlSuite "*firefox" "${AIRTIME_URL}" "${PWD}"/selenium/Airtime.html "${PWD}"/results.html +