CC-5725: Changing a show's repeat type removes first instance from repeating series

This commit is contained in:
drigato 2014-03-07 14:52:32 -05:00
parent 35fd639c1c
commit 6b91d2daf8
1 changed files with 39 additions and 25 deletions

View File

@ -415,6 +415,13 @@ SQL;
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); ':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
} }
private function deleteAllShowDays($showId)
{
CcShowDaysQuery::create()
->filterByDbShowId($showId)
->delete();
}
/** /**
* TODO: This function is messy. Needs refactoring * TODO: This function is messy. Needs refactoring
* *
@ -436,8 +443,14 @@ SQL;
//CcShowDay object //CcShowDay object
if ($this->ccShow->isRepeating()) { if ($this->ccShow->isRepeating()) {
$currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
//all cc_show_days
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else { } else {
$currentShowDay = $this->ccShow->getFirstCcShowDay(); $currentShowDay = $this->ccShow->getFirstCcShowDay();
//all cc_show_days
$ccShowDays = $this->ccShow->getCcShowDayss();
} }
//new end date in the show's timezone (from the select box) //new end date in the show's timezone (from the select box)
@ -446,6 +459,7 @@ SQL;
//repeat option was toggled //repeat option was toggled
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) { if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
$this->deleteAllRepeatInstances($currentShowDay, $showId); $this->deleteAllRepeatInstances($currentShowDay, $showId);
//if repeat option was checked we need to treat the current show day //if repeat option was checked we need to treat the current show day
//as a new show day so the repeat instances get created properly //as a new show day so the repeat instances get created properly
//in createWeeklyRepeatInstances() //in createWeeklyRepeatInstances()
@ -477,17 +491,13 @@ SQL;
//and the repeat type changed //and the repeat type changed
if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) { if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) {
$this->deleteAllInstances($showId); $this->deleteAllInstances($showId);
$this->deleteAllShowDays($showId);
// when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days // when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days
} elseif ($currentRepeatType != 2) { } elseif ($currentRepeatType != 2) {
//repeat type is the same, check if the days of the week are the same //repeat type is the same, check if the days of the week are the same
$repeatingDaysChanged = false; $repeatingDaysChanged = false;
if ($this->ccShow->isRepeating()) {
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else {
$ccShowDays = $this->ccShow->getCcShowDayss();
}
$showDays = array(); $showDays = array();
foreach ($ccShowDays as $day) { foreach ($ccShowDays as $day) {
$showDays[] = $day->getDbDay(); $showDays[] = $day->getDbDay();
@ -560,11 +570,14 @@ SQL;
private function preserveLinkedShowContent() private function preserveLinkedShowContent()
{ {
/* Get show content from any linekd instance. It doesn't /* Get show content from any linked instance. It doesn't
* matter which instance since content is the same in all. * matter which instance since content is the same in all.
*/ */
$ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst(); $ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst();
if (!$ccShowInstance) {
return;
}
$ccSchedules = CcScheduleQuery::create() $ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($ccShowInstance->getDbId()) ->filterByDbInstanceId($ccShowInstance->getDbId())
->find(); ->find();
@ -1512,8 +1525,12 @@ SQL;
if ($this->isUpdate) { if ($this->isUpdate) {
$showDay = CcShowDaysQuery::create() $showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbRepeatType($showData['add_show_repeat_type']) ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
->findOne(); ->findOne();
if (!$showDay) {
//repeat type changed so we have to create a new show_day rule
$showDay = new CcShowDays();
}
} else { } else {
$showDay = new CcShowDays(); $showDay = new CcShowDays();
} }
@ -1545,23 +1562,20 @@ SQL;
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
if ($this->isUpdate) { if ($this->isUpdate) {
if ($this->repeatType >= 0) { if ($this->origCcShowDay->getDbRepeatType() == 2 ||
$showDay = CcShowDaysQuery::create() $this->origCcShowDay->getDbRepeatType() == 3) {
->filterByDbShowId($showId) $day = null;
->filterByDbRepeatType($this->repeatType) }
->filterByDbDay($day) $showDay = CcShowDaysQuery::create()
->findOne(); ->filterByDbShowId($showId)
if (!$showDay) { ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
//if no show day object was found it is because a new ->filterByDbDay($day)
//repeating day of the week was added ->findOne();
$showDay = new CcShowDays(); if (!$showDay) {
} //if no show day object was found it is because a new
} else { //repeating day of the week was added OR the repeat
$showDay = CcShowDaysQuery::create() //type has changed
->filterByDbShowId($showId) $showDay = new CcShowDays();
->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
->filterByDbDay($this->origCcShowDay->getDbDay())
->findOne();
} }
} else { } else {
$showDay = new CcShowDays(); $showDay = new CcShowDays();