private function insertAfter($scheduleItems, $schedFiles, $adjustSched = true) { try { $affectedShowInstances = array(); //dont want to recalculate times for moved items. $excludeIds = array(); foreach ($schedFiles as $file) { if (isset($file["sched_id"])) { $excludeIds[] = intval($file["sched_id"]); } } $startProfile = microtime(true); foreach ($scheduleItems as $schedule) { $id = intval($schedule["id"]); if ($id !== 0) { $schedItem = CcScheduleQuery::create()->findPK($id, $this->con); $instance = $schedItem->getCcShowInstances($this->con); $schedItemEndDT = $schedItem->getDbEnds(null); $nextStartDT = $this->findNextStartTime($schedItemEndDT, $instance); } else { $instance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con); $showStartDT = $instance->getDbStarts(null); $nextStartDT = $this->findNextStartTime($showStartDT, $instance); } if (!in_array($instance->getDbId(), $affectedShowInstances)) { $affectedShowInstances[] = $instance->getDbId(); } if ($adjustSched === true) { $pstart = microtime(true); $followingSchedItems = CcScheduleQuery::create()->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL)->filterByDbInstanceId($instance->getDbId())->filterByDbId($excludeIds, Criteria::NOT_IN)->orderByDbStarts()->find($this->con); $pend = microtime(true); Logging::debug("finding all following items."); Logging::debug(floatval($pend) - floatval($pstart)); } foreach ($schedFiles as $file) { $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']); //item existed previously and is being moved. //need to keep same id for resources if we want REST. if (isset($file['sched_id'])) { $sched = CcScheduleQuery::create()->findPK($file['sched_id'], $this->con); } else { $sched = new CcSchedule(); } Logging::info($file); $sched->setDbStarts($nextStartDT)->setDbEnds($endTimeDT)->setDbCueIn($file['cuein'])->setDbCueOut($file['cueout'])->setDbFadeIn($file['fadein'])->setDbFadeOut($file['fadeout'])->setDbClipLength($file['cliplength'])->setDbInstanceId($instance->getDbId()); switch ($file["type"]) { case 0: $sched->setDbFileId($file['id']); break; case 1: $sched->setDbStreamId($file['id']); break; default: break; } $sched->save($this->con); $nextStartDT = $endTimeDT; } if ($adjustSched === true) { $pstart = microtime(true); //recalculate the start/end times after the inserted items. foreach ($followingSchedItems as $item) { $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength()); $item->setDbStarts($nextStartDT); $item->setDbEnds($endTimeDT); $item->save($this->con); $nextStartDT = $endTimeDT; } $pend = microtime(true); Logging::debug("adjusting all following items."); Logging::debug(floatval($pend) - floatval($pstart)); } } $endProfile = microtime(true); Logging::debug("finished adding scheduled items."); Logging::debug(floatval($endProfile) - floatval($startProfile)); //update the status flag in cc_schedule. $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($affectedShowInstances)->find($this->con); $startProfile = microtime(true); foreach ($instances as $instance) { $instance->updateScheduleStatus($this->con); } $endProfile = microtime(true); Logging::debug("updating show instances status."); Logging::debug(floatval($endProfile) - floatval($startProfile)); $startProfile = microtime(true); //update the last scheduled timestamp. CcShowInstancesQuery::create()->filterByPrimaryKeys($affectedShowInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con); $endProfile = microtime(true); Logging::debug("updating last scheduled timestamp."); Logging::debug(floatval($endProfile) - floatval($startProfile)); } catch (Exception $e) { Logging::debug($e->getMessage()); throw $e; } }