CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show
Create a new cc_show_day rule instead of a new cc_show
This commit is contained in:
parent
f571000657
commit
6f9254e655
|
@ -183,6 +183,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$deltaDay = $this->_getParam('day');
|
||||
$deltaMin = $this->_getParam('min');
|
||||
$showId = $this->_getParam('showId');
|
||||
$instanceId = $this->_getParam('instanceId');
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
|
@ -195,7 +196,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
return false;
|
||||
}
|
||||
$error = $show->resizeShow($deltaDay, $deltaMin);
|
||||
$error = $show->resizeShow($deltaDay, $deltaMin, $instanceId);
|
||||
}
|
||||
|
||||
if (isset($error)) {
|
||||
|
|
|
@ -172,16 +172,16 @@ SQL;
|
|||
$show->delete();
|
||||
}
|
||||
|
||||
public function resizeShow($deltaDay, $deltaMin)
|
||||
public function resizeShow($deltaDay, $deltaMin, $instanceId)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
|
||||
if ($deltaDay > 0) {
|
||||
return _("Shows can have a max length of 24 hours.");
|
||||
}
|
||||
|
||||
|
||||
$utc = new DateTimeZone("UTC");
|
||||
|
||||
|
||||
$nowDateTime = new DateTime("now", $utc);
|
||||
|
||||
$showInstances = CcShowInstancesQuery::create()
|
||||
|
|
|
@ -15,8 +15,20 @@
|
|||
*/
|
||||
class CcShow extends BaseCcShow {
|
||||
|
||||
public function getCcShowDays(){
|
||||
return CcShowDaysQuery::create()->filterByDbShowId($this->getDbId())->find();
|
||||
/*
|
||||
* Returns all cc_show_day rules that belong to a cc_show and that are
|
||||
* repeating.
|
||||
* We do this because editing a single instance from a repeating sequence
|
||||
* creates a new rule in cc_show_days with the same cc_show id and a repeat
|
||||
* type of -1 (non-repeating).
|
||||
* So when the entire cc_show is updated after that, the single edited
|
||||
* instance can remain separate from the rest of the instances
|
||||
*/
|
||||
public function getRepeatingCcShowDays(){
|
||||
return CcShowDaysQuery::create()
|
||||
->filterByDbShowId($this->id)
|
||||
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,6 +66,49 @@ class CcShow extends BaseCcShow {
|
|||
return $this->collCcShowDayss[0];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* A repeating show may have a rule in cc_show_days with a repeat type
|
||||
* of -1 (not repeating). This happens when a single instances was edited
|
||||
* from the repeating sequence.
|
||||
*
|
||||
* When the repeating show gets edited in this case, we want to exclude all
|
||||
* the edited instances from the update. We do this by not returning any of
|
||||
* the cc_show_day rules with a -1 repeat type.
|
||||
*/
|
||||
public function getFirstRepeatingCcShowDay()
|
||||
{
|
||||
return CcShowDaysQuery::create()
|
||||
->filterByDbShowId($this->id)
|
||||
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
|
||||
->orderByDbFirstShow()
|
||||
->findOne();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* In order to determine if a show is repeating we need to check each
|
||||
* cc_show_day entry and check if there are any non -1 repeat types.
|
||||
* Because editing a single instances creates a new cc_show_day rule
|
||||
* with a -1 (non repeating) repeat type we need to check all cc_show_day
|
||||
* entries
|
||||
*/
|
||||
public function isRepeating()
|
||||
{
|
||||
//get ALL cc_show_day entries
|
||||
$ccShowDays = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($this->id)
|
||||
->find();
|
||||
|
||||
foreach ($ccShowDays as $day) {
|
||||
if ($day->getDbRepeatType() >= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of CcShowInstances objects which contain a foreign key that references this object.
|
||||
*
|
||||
|
|
|
@ -124,7 +124,11 @@ class Application_Service_ShowFormService
|
|||
|
||||
private function populateFormWhen($form)
|
||||
{
|
||||
$ccShowDay = $this->ccShow->getFirstCcShowDay();
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$ccShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
|
||||
} else {
|
||||
$ccShowDay = $this->ccShow->getFirstCcShowDay();
|
||||
}
|
||||
|
||||
$showStart = $ccShowDay->getLocalStartDateAndTime();
|
||||
$showEnd = $ccShowDay->getLocalEndDateAndTime($showStart);
|
||||
|
@ -198,7 +202,11 @@ class Application_Service_ShowFormService
|
|||
*/
|
||||
private function populateFormRepeats($form, $nextFutureShowStart)
|
||||
{
|
||||
$ccShowDays = $this->ccShow->getCcShowDays();
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
|
||||
} else {
|
||||
$ccShowDays = $this->ccShow->getCcShowDayss();
|
||||
}
|
||||
|
||||
$days = array();
|
||||
foreach ($ccShowDays as $ccShowDay) {
|
||||
|
|
|
@ -55,11 +55,13 @@ class Application_Service_ShowService
|
|||
throw new Exception("Permission denied");
|
||||
}
|
||||
|
||||
$showId = $showData["add_show_id"];
|
||||
|
||||
/****** UPDATE SCHEDULE START TIME ******/
|
||||
//get the ccShow object to which this instance belongs
|
||||
//so we can get the original start date and time
|
||||
$oldCcShow = CcShowQuery::create()
|
||||
->findPk($showData["add_show_id"]);
|
||||
$this->ccShow = CcShowQuery::create()
|
||||
->findPk($showId);
|
||||
|
||||
//DateTime in shows's local time
|
||||
$newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
|
||||
|
@ -68,52 +70,78 @@ class Application_Service_ShowService
|
|||
|
||||
$ccShowInstanceOrig = CcShowInstancesQuery::create()
|
||||
->findPk($showData["add_show_instance_id"]);
|
||||
$diff = $this->calculateShowStartDiff($newStartDateTime,
|
||||
$ccShowInstanceOrig->getLocalStartDateTime());
|
||||
|
||||
if ($diff > 0) {
|
||||
//convert original start time into the show's local timezone
|
||||
$origLocalStartDateTime = $ccShowInstanceOrig->getLocalStartDateTime();
|
||||
|
||||
$diff = $this->calculateShowStartDiff($newStartDateTime,
|
||||
$origLocalStartDateTime);
|
||||
|
||||
if ($diff != 0) {
|
||||
Application_Service_SchedulerService::updateScheduleStartTime(
|
||||
array($showData["add_show_instance_id"]), $diff);
|
||||
}
|
||||
/****** UPDATE SCHEDULE START TIME ENDS******/
|
||||
|
||||
$this->setCcShow($showData);
|
||||
/*
|
||||
* Set the new cc_show_day record
|
||||
* Associates it with the current show_id and sets it to non-repeating
|
||||
*/
|
||||
$this->setCcShowDays($showData);
|
||||
$this->setCcShowHosts($showData);
|
||||
$this->delegateInstanceCreation();
|
||||
|
||||
//get the new instance id
|
||||
$ccShowInstance = CcShowInstancesQuery::create()
|
||||
->filterByDbShowId($this->ccShow->getDbId())
|
||||
/*
|
||||
* In the case where an instance is being edited for a second
|
||||
* (or third, fourth, etc.) time we need to delete the old
|
||||
* cc_show_day record
|
||||
*
|
||||
* Since we don't store the cc_show_day ids we need to use the
|
||||
* original start time from cc_show_instances, convert it to the show's
|
||||
* local timezone, and find the record in cc_show_days
|
||||
*
|
||||
* *** There is a flaw here: We have to assume the show timezone has
|
||||
* *** not changed (make timezone readonly??)
|
||||
*/
|
||||
$origCcShowDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType(-1)
|
||||
->filterByDbFirstShow($origLocalStartDateTime->format("Y-m-d"))
|
||||
->filterByDbStartTime($origLocalStartDateTime->format("H:i:s"))
|
||||
->delete();
|
||||
|
||||
// DO WE NEED THIS?
|
||||
$this->setCcShowHosts($showData);
|
||||
|
||||
/*
|
||||
* We need to find the new show day rule we just created by passing
|
||||
* in the first show and start time in case multiple single
|
||||
* instances have been edited out of the repeating sequence.
|
||||
*/
|
||||
$showDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType(-1)
|
||||
->filterByDbFirstShow($showData["add_show_start_date"])
|
||||
->filterByDbStartTime($showData["add_show_start_time"])
|
||||
->findOne();
|
||||
|
||||
$newInstanceId = $ccShowInstance->getDbId();
|
||||
$ccShowInstance = $this->createNonRepeatingInstance($showDay,
|
||||
$this->getPopulateShowUntilDateTIme());
|
||||
|
||||
//update cc_schedule with the new instance id
|
||||
$ccSchedules = CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($showData["add_show_instance_id"])
|
||||
->find();
|
||||
|
||||
foreach ($ccSchedules as $ccSchedule) {
|
||||
$ccSchedule->setDbInstanceId($newInstanceId);
|
||||
$ccSchedule->save();
|
||||
}
|
||||
|
||||
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
|
||||
$selectCriteria = new Criteria();
|
||||
$selectCriteria->add(CcSchedulePeer::INSTANCE_ID, $showData["add_show_instance_id"]);
|
||||
$updateCriteria = new Criteria();
|
||||
$updateCriteria->add(CcSchedulePeer::INSTANCE_ID, $ccShowInstance->getDbId());
|
||||
BasePeer::doUpdate($selectCriteria, $updateCriteria, $con);
|
||||
|
||||
$ccShowInstance
|
||||
->setDbLastScheduled(gmdate("Y-m-d H:i:s"))
|
||||
->save();
|
||||
$ccShowInstance->updateDbTimeFilled($con);
|
||||
|
||||
//delete the edited instance from the repeating sequence
|
||||
$ccShowInstanceOrig->setDbModifiedInstance(true)->save();
|
||||
|
||||
$service_showForm = new Application_Service_ShowFormService($showData["add_show_id"]);
|
||||
list($start, $end) = $service_showForm->getNextFutureRepeatShowTime();
|
||||
$oldCcShowDay = $oldCcShow->getFirstCcShowDay();
|
||||
$oldCcShowDay
|
||||
->setDbFirstShow(
|
||||
$start->setTimezone(new DateTimeZone(
|
||||
$oldCcShowDay->getDbTimezone()))->format("Y-m-d"))
|
||||
->save();
|
||||
|
||||
$con->commit();
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
} catch (Exception $e) {
|
||||
|
@ -131,7 +159,7 @@ class Application_Service_ShowService
|
|||
*/
|
||||
private function storeOrigLocalShowInfo()
|
||||
{
|
||||
$this->origCcShowDay = $this->ccShow->getFirstCcShowDay();
|
||||
$this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
|
||||
|
||||
$this->oldShowTimezone = $this->origCcShowDay->getDbTimezone();
|
||||
|
||||
|
@ -165,7 +193,7 @@ class Application_Service_ShowService
|
|||
|
||||
$this->deleteRebroadcastInstances();
|
||||
|
||||
$this->deleteCcShowDays();
|
||||
//$this->deleteCcShowDays();
|
||||
$this->deleteCcShowHosts();
|
||||
if ($this->isRebroadcast) {
|
||||
//delete entry in cc_show_rebroadcast
|
||||
|
@ -225,7 +253,11 @@ class Application_Service_ShowService
|
|||
if (is_null($this->ccShow)) {
|
||||
$ccShowDays = $this->getShowDaysInRange($populateUntil, $end);
|
||||
} else {
|
||||
$ccShowDays = $this->ccShow->getCcShowDays();
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
|
||||
} else {
|
||||
$ccShowDays = $this->ccShow->getCcShowDayss();
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($end)) {
|
||||
|
@ -372,7 +404,7 @@ SQL;
|
|||
$daysAdded = array();
|
||||
|
||||
//CcShowDay object
|
||||
$currentShowDay = $this->ccShow->getFirstCcShowDay();
|
||||
$currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
|
||||
|
||||
//new end date in users' local time
|
||||
$endDateTime = $this->calculateEndDate($showData);
|
||||
|
@ -420,7 +452,12 @@ SQL;
|
|||
//repeat type is the same, check if the days of the week are the same
|
||||
$repeatingDaysChanged = false;
|
||||
|
||||
$ccShowDays = $this->ccShow->getCcShowDays();
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
|
||||
} else {
|
||||
$ccShowDays = $this->ccShow->getCcShowDayss();
|
||||
}
|
||||
|
||||
$showDays = array();
|
||||
foreach ($ccShowDays as $day) {
|
||||
$showDays[] = $day->getDbDay();
|
||||
|
@ -710,6 +747,7 @@ SQL;
|
|||
$ccShowDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbDay($dayOfWeek)
|
||||
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
if (isset($ccShowDay)) {
|
||||
|
@ -725,10 +763,10 @@ SQL;
|
|||
}
|
||||
|
||||
//remove the old repeating deleted instances.
|
||||
CcShowInstancesQuery::create()
|
||||
/*CcShowInstancesQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbModifiedInstance(true)
|
||||
->delete();
|
||||
->delete();*/
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -915,6 +953,7 @@ SQL;
|
|||
$this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId());
|
||||
}
|
||||
}
|
||||
return $ccShowInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -971,6 +1010,9 @@ SQL;
|
|||
if ($this->isUpdate) {
|
||||
if ($this->hasInstance($utcStartDateTime)) {
|
||||
$ccShowInstance = $this->getInstance($utcStartDateTime);
|
||||
if ($ccShowInstance->getDbModifiedInstance()) {
|
||||
continue;
|
||||
}
|
||||
$newInstance = false;
|
||||
$updateScheduleStatus = true;
|
||||
} else {
|
||||
|
@ -1259,12 +1301,13 @@ SQL;
|
|||
$temp = clone($starts);
|
||||
$temp->setTimezone(new DateTimeZone($this->oldShowTimezone));
|
||||
$temp->setTime($this->localShowStartHour, $this->localShowStartMin);
|
||||
|
||||
$temp->setTimezone(new DateTimeZone("UTC"));
|
||||
|
||||
$ccShowInstance = CcShowInstancesQuery::create()
|
||||
->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL)
|
||||
->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL)
|
||||
->filterByDbModifiedInstance(false, Criteria::EQUAL)
|
||||
//->filterByDbModifiedInstance(false, Criteria::EQUAL)
|
||||
->filterByDbRebroadcast(0, Criteria::EQUAL)
|
||||
->limit(1)
|
||||
->find();
|
||||
|
@ -1369,7 +1412,16 @@ SQL;
|
|||
|
||||
// Don't set day for monthly repeat type, it's invalid
|
||||
if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) {
|
||||
$showDay = new CcShowDays();
|
||||
|
||||
if ($this->isUpdate) {
|
||||
$showDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType($showData['add_show_repeat_type'])
|
||||
->findOne();
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
|
||||
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
||||
$showDay->setDbLastShow($endDate);
|
||||
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
||||
|
@ -1395,7 +1447,22 @@ SQL;
|
|||
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
|
||||
}
|
||||
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
|
||||
$showDay = new CcShowDays();
|
||||
|
||||
if ($this->isUpdate) {
|
||||
$showDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType($showData['add_show_repeat_type'])
|
||||
->filterByDbDay($day)
|
||||
->findOne();
|
||||
if (!$showDay) {
|
||||
//if no show day object was found it is because a new
|
||||
//repeating day of the week was added
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
|
||||
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
||||
$showDay->setDbLastShow($endDate);
|
||||
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
||||
|
@ -1562,6 +1629,7 @@ SQL;
|
|||
$repeatInfo = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbDay($day)
|
||||
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
$repeatInfo->setDbNextPopDate($nextInfo[0])
|
||||
|
|
|
@ -332,7 +332,7 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie
|
|||
var url = baseUrl+'Schedule/resize-show/format/json';
|
||||
|
||||
$.post(url,
|
||||
{day: dayDelta, min: minuteDelta, showId: event.showId},
|
||||
{day: dayDelta, min: minuteDelta, showId: event.showId, instanceId: event.id},
|
||||
function(json){
|
||||
if(json.show_error == true){
|
||||
alertShowErrorAndReload();
|
||||
|
|
Loading…
Reference in New Issue