From 8d56c03fe3e198f944513069c80bd7a399675156 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 19 Oct 2012 11:32:35 -0400 Subject: [PATCH 1/5] deep voodoo magic to optimize schedule --- airtime_mvc/application/models/Show.php | 4 ++-- .../application/models/ShowInstance.php | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index bb58409fd..5da348b52 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1789,9 +1789,9 @@ SQL; $showInstance = new Application_Model_ShowInstance( $show["instance_id"]); - $showContent = $showInstance->getShowListContent(); + //$showContent = $showInstance->getShowListContent(); - $options["show_empty"] = empty($showContent) ? 1 : 0; + $options["show_empty"] = ($showInstance->showEmpty()) ? 1 : 0; $events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 3dfd8756f..e657494f9 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -661,6 +661,28 @@ SQL; return $returnStr; } + + public function showEmpty() + { + $sql = <<= 0 + AND ((s.stream_id IS NOT NULL) + OR (s.file_id IS NOT NULL)) LIMIT 1 +SQL; + # TODO : use prepareAndExecute properly + $res = Application_Common_Database::prepareAndExecute($sql, + array( ':instance_id' => $this->_instanceId ), 'all' ); + # TODO : A bit retarded. fix this later + foreach ($res as $r) { + return false; + } + return true; + + } + public function getShowListContent() { $con = Propel::getConnection(); From a51c3174e0f18f844b312d4c1ea401f2098d74d8 Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 19 Oct 2012 12:33:12 -0400 Subject: [PATCH 2/5] SAAS-282: Overlap detection prevents creation of a repeating show -fixed --- airtime_mvc/application/forms/AddShowWhen.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 1ed9d2619..e6d164022 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -143,10 +143,12 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm * upto this point */ if ($valid) { + $utc = new DateTimeZone('UTC'); + $localTimezone = new DateTimeZone(Application_Model_Preference::GetTimezone()); $show_start = new DateTime($start_time); - $show_start->setTimezone(new DateTimeZone('UTC')); + $show_start->setTimezone($utc); $show_end = new DateTime($end_time); - $show_end->setTimezone(new DateTimeZone('UTC')); + $show_end->setTimezone($utc); if ($formData["add_show_repeats"]) { @@ -155,7 +157,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $date = Application_Model_Preference::GetShowsPopulatedUntil(); if (is_null($date)) { - $populateUntilDateTime = new DateTime("now", new DateTimeZone('UTC')); + $populateUntilDateTime = new DateTime("now", $utc); Application_Model_Preference::SetShowsPopulatedUntil($populateUntilDateTime); } else { $populateUntilDateTime = clone $date; @@ -164,7 +166,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm } elseif (!$formData["add_show_no_end"]) { $popUntil = $formData["add_show_end_date"]." ".$formData["add_show_end_time"]; $populateUntilDateTime = new DateTime($popUntil); - $populateUntilDateTime->setTimezone(new DateTimeZone('UTC')); + $populateUntilDateTime->setTimezone($utc); } //get repeat interval @@ -203,8 +205,18 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm else $daysAdd = $day - $startDow; + /* In case we are crossing daylights saving time we need + * to convert show start and show end to local time before + * adding the interval for the next repeating show + */ + + $repeatShowStart->setTimezone($localTimezone); + $repeatShowEnd->setTimezone($localTimezone); $repeatShowStart->add(new DateInterval("P".$daysAdd."D")); $repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); + //set back to UTC + $repeatShowStart->setTimezone($utc); + $repeatShowEnd->setTimezone($utc); } /* Here we are checking each repeating show by * the show day. @@ -238,8 +250,12 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); break 1; } else { + $repeatShowStart->setTimezone($localTimezone); + $repeatShowEnd->setTimezone($localTimezone); $repeatShowStart->add(new DateInterval($interval)); $repeatShowEnd->add(new DateInterval($interval)); + $repeatShowStart->setTimezone($utc); + $repeatShowEnd->setTimezone($utc); } } } From a1e653b41f0657ca8d366897e0c824cd993fe7a5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 19 Oct 2012 13:22:00 -0400 Subject: [PATCH 3/5] Deep optimization --- airtime_mvc/application/models/Show.php | 7 ++++--- .../application/models/ShowInstance.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 5da348b52..0006057f7 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1743,7 +1743,8 @@ SQL; $days = $interval->format('%a'); $shows = Application_Model_Show::getShows($p_start, $p_end); $nowEpoch = time(); - + $content_count = Application_Model_ShowInstance::getContentCount( + $p_start, $p_end); $timezone = date_default_timezone_get(); foreach ($shows as $show) { @@ -1789,9 +1790,9 @@ SQL; $showInstance = new Application_Model_ShowInstance( $show["instance_id"]); - //$showContent = $showInstance->getShowListContent(); - $options["show_empty"] = ($showInstance->showEmpty()) ? 1 : 0; + $options["show_empty"] = (array_key_exists($show['instance_id'], + $content_count)) ? 1 : 0; $events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index e657494f9..8854f3896 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -662,6 +662,27 @@ SQL; } + + public static function getContentCount($p_start, $p_end) + { + $sql = << :p_start::TIMESTAMP + AND starts < :p_end::TIMESTAMP +GROUP BY instance_id; +SQL; + + $counts = Application_Common_Database::prepareAndExecute( $sql, array( + ':p_start' => $p_start->format("Y-m-d G:i:s"), + ':p_end' => $p_end->format("Y-m-d G:i:s")) + , 'all'); + + return $counts; + + } + public function showEmpty() { $sql = << Date: Fri, 19 Oct 2012 13:24:06 -0400 Subject: [PATCH 4/5] Removed trailing whitespace --- airtime_mvc/application/models/ShowInstance.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 8854f3896..5b60e1f70 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -671,16 +671,16 @@ SELECT instance_id, FROM cc_schedule WHERE ends > :p_start::TIMESTAMP AND starts < :p_end::TIMESTAMP -GROUP BY instance_id; -SQL; +GROUP BY instance_id +SQL; - $counts = Application_Common_Database::prepareAndExecute( $sql, array( - ':p_start' => $p_start->format("Y-m-d G:i:s"), + $counts = Application_Common_Database::prepareAndExecute( $sql, array( + ':p_start' => $p_start->format("Y-m-d G:i:s"), ':p_end' => $p_end->format("Y-m-d G:i:s")) - , 'all'); - - return $counts; - + , 'all'); + + return $counts; + } public function showEmpty() From 8f998fd2c89edc5334f3ae1d138f04aaee0bc0e2 Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 19 Oct 2012 13:42:24 -0400 Subject: [PATCH 5/5] CC-4595: Fade in/out setting doesn't work -fixed --- airtime_mvc/application/models/airtime/CcSchedule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcSchedule.php b/airtime_mvc/application/models/airtime/CcSchedule.php index e051df6c3..db7fb19a7 100644 --- a/airtime_mvc/application/models/airtime/CcSchedule.php +++ b/airtime_mvc/application/models/airtime/CcSchedule.php @@ -127,9 +127,9 @@ class CcSchedule extends BaseCcSchedule { } if ($microsecond == 0) { - $this->fadein = $dt->format('H:i:s.u'); + $this->fade_in = $dt->format('H:i:s.u'); } else { - $this->fadein = $dt->format('H:i:s').".".$microsecond; + $this->fade_in = $dt->format('H:i:s').".".$microsecond; } $this->modifiedColumns[] = CcSchedulePeer::FADE_IN; @@ -164,9 +164,9 @@ class CcSchedule extends BaseCcSchedule { } if ($microsecond == 0) { - $this->fadeout = $dt->format('H:i:s.u'); + $this->fade_out = $dt->format('H:i:s.u'); } else { - $this->fadeout = $dt->format('H:i:s').".".$microsecond; + $this->fade_out = $dt->format('H:i:s').".".$microsecond; } $this->modifiedColumns[] = CcSchedulePeer::FADE_OUT;