/**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCcSchedule !== null) {
             if ($this->aCcSchedule->isModified() || $this->aCcSchedule->isNew()) {
                 $affectedRows += $this->aCcSchedule->save($con);
             }
             $this->setCcSchedule($this->aCcSchedule);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = CcWebstreamMetadataPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $criteria = $this->buildCriteria();
                 if ($criteria->keyContainsValue(CcWebstreamMetadataPeer::ID)) {
                     throw new PropelException('Cannot insert a value for auto-increment primary key (' . CcWebstreamMetadataPeer::ID . ')');
                 }
                 $pk = BasePeer::doInsert($criteria, $con);
                 $affectedRows += 1;
                 $this->setDbId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += CcWebstreamMetadataPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #2
0
 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;
     }
 }