Exemplo n.º 1
0
 /**
  * Method to invalidate the instance pool of all tables related to cc_files
  * by a foreign key with ON DELETE CASCADE
  */
 public static function clearRelatedInstancePool()
 {
     // Invalidate objects in CcShowInstancesPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowInstancesPeer::clearInstancePool();
     // Invalidate objects in CcPlaylistcontentsPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcPlaylistcontentsPeer::clearInstancePool();
     // Invalidate objects in CcSchedulePeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcSchedulePeer::clearInstancePool();
 }
Exemplo n.º 2
0
 public function resizeShow($deltaDay, $deltaMin, $instanceId)
 {
     $con = Propel::getConnection();
     if ($deltaDay > 0) {
         return _("Shows can have a max length of 24 hours.");
     }
     $utcTimezone = new DateTimeZone("UTC");
     $nowDateTime = new DateTime("now", $utcTimezone);
     //keep track of cc_show_day entries we need to update
     $showDayIds = array();
     /*
      * If the resized show is an edited instance of a repeating show we
      * need to treat it as a separate show and not resize the other instances
      * 
      * Also, if the resized show has edited instances, we need to exclude
      * those from the resize
      */
     $ccShow = CcShowQuery::create()->findPk($this->_showId);
     if ($ccShow->isRepeating()) {
         //convert instance to local timezone
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         $startsDT = $ccShowInstance->getDbStarts(null);
         $timezone = $ccShow->getFirstCcShowDay()->getDbTimezone();
         $startsDT->setTimezone(new DateTimeZone($timezone));
         /* Get cc_show_day for the current instance. If we don't find one
          * we know it is a repeat interval of one of cc_show_days first
          * show and we can assume we aren't resizing a modified instance
          */
         $ccShowDay = CcShowDaysQuery::create()->filterByDbFirstShow($startsDT->format("Y-m-d"))->filterByDbStartTime($startsDT->format("H:i:s"))->filterByDbShowId($this->_showId)->findOne();
         /* Check if this cc_show_day rule is non-repeating. If it is, then
          * we know this instance was edited out of the repeating sequence
          */
         if (!$ccShowDay || $ccShowDay->getDbRepeatType() != -1) {
             $ccShowDays = $ccShow->getRepeatingCcShowDays();
             foreach ($ccShowDays as $day) {
                 array_push($showDayIds, $day->getDbId());
             }
             $excludeIds = $ccShow->getEditedRepeatingInstanceIds();
             //exlcude edited instances from resize
             $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($this->_showId)->filterByDbModifiedInstance(false)->filterByDbId($excludeIds, criteria::NOT_IN)->find();
         } elseif ($ccShowDay->getDbRepeatType() == -1) {
             array_push($showDayIds, $ccShowDay->getDbId());
             //treat edited instance as separate show for resize
             $showInstances = CcShowInstancesQuery::create()->filterByDbId($instanceId)->find();
         }
     } else {
         $ccShowDays = $ccShow->getCcShowDayss();
         foreach ($ccShowDays as $day) {
             array_push($showDayIds, $day->getDbId());
         }
         $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($this->_showId)->find($con);
     }
     /* Check two things:
        1. If the show being resized and any of its repeats end in the past
        2. If the show being resized and any of its repeats overlap
           with other scheduled shows */
     //keep track of instance ids for update show instances start/end times
     $instanceIds = array();
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     //check if new show time overlaps with any other shows
     foreach ($showInstances as $si) {
         array_push($instanceIds, $si->getDbId());
         $startsDateTime = $si->getDbStarts(null);
         $endsDateTime = $si->getDbEnds(null);
         /* The user is moving the show on the calendar from the perspective
            of local time.  * incase a show is moved across a time change
            border offsets should be added to the local * timestamp and
            then converted back to UTC to avoid show time changes */
         $startsDateTime->setTimezone($displayTimezone);
         $endsDateTime->setTimezone($displayTimezone);
         //$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin);
         $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin);
         if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
             return _("End date/time cannot be in the past");
         }
         //convert our new starts/ends to UTC.
         //$newStartsDateTime->setTimezone($utc);
         $newEndsDateTime->setTimezone($utcTimezone);
         $overlapping = Application_Model_Schedule::checkOverlappingShows($startsDateTime, $newEndsDateTime, true, $si->getDbId());
         if ($overlapping) {
             return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show " . "affects all of its repeats.");
         }
     }
     $hours = $deltaMin / 60;
     $hours = $hours > 0 ? floor($hours) : ceil($hours);
     $mins = abs($deltaMin % 60);
     $sql_gen = "UPDATE cc_show_instances " . "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) " . "WHERE (id IN (" . implode($instanceIds, ",") . ") " . "AND ends > :current_timestamp1) " . "AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')";
     Application_Common_Database::prepareAndExecute($sql_gen, array(':deltaDay1' => "{$deltaDay} days", ':interval1' => "{$hours}:{$mins}", ':current_timestamp1' => $nowDateTime->format("Y-m-d H:i:s"), ':deltaDay2' => "{$deltaDay} days", ':interval2' => "{$hours}:{$mins}"), "execute");
     $sql_gen = "UPDATE cc_show_days " . "SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) " . "WHERE id IN (" . implode($showDayIds, ",") . ") " . "AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00')";
     Application_Common_Database::prepareAndExecute($sql_gen, array(':deltaDay3' => "{$deltaDay} days", ':interval3' => "{$hours}:{$mins}", ':deltaDay4' => "{$deltaDay} days", ':interval4' => "{$hours}:{$mins}"), "execute");
     $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
     $con->beginTransaction();
     try {
         //update the status flag in cc_schedule.
         /* Since we didn't use a propel object when updating
          * cc_show_instances table we need to clear the instances
          * so the correct information is retrieved from the db
          */
         CcShowInstancesPeer::clearInstancePool();
         $instances = CcShowInstancesQuery::create()->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN)->filterByDbId($instanceIds, Criteria::IN)->find($con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($con);
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         Logging::info("Couldn't update schedule status.");
         Logging::info($e->getMessage());
     }
     Application_Model_RabbitMq::PushSchedule();
 }
 /**
  * Method perform a DELETE on the database, given a CcShowInstances or Criteria object OR a primary key value.
  *
  * @param      mixed $values Criteria or CcShowInstances object or primary key or array of primary keys
  *              which is used to create the DELETE statement
  * @param      PropelPDO $con the connection to use
  * @return     int 	The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
  *				if supported by native driver or if emulated using Propel.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doDelete($values, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     if ($values instanceof Criteria) {
         // invalidate the cache for all objects of this type, since we have no
         // way of knowing (without running a query) what objects should be invalidated
         // from the cache based on this Criteria.
         CcShowInstancesPeer::clearInstancePool();
         // rename for clarity
         $criteria = clone $values;
     } elseif ($values instanceof CcShowInstances) {
         // it's a model object
         // invalidate the cache for this single object
         CcShowInstancesPeer::removeInstanceFromPool($values);
         // create criteria based on pk values
         $criteria = $values->buildPkeyCriteria();
     } else {
         // it's a primary key, or an array of pks
         $criteria = new Criteria(self::DATABASE_NAME);
         $criteria->add(CcShowInstancesPeer::ID, (array) $values, Criteria::IN);
         // invalidate the cache for this object(s)
         foreach ((array) $values as $singleval) {
             CcShowInstancesPeer::removeInstanceFromPool($singleval);
         }
     }
     // Set the correct dbName
     $criteria->setDbName(self::DATABASE_NAME);
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     try {
         // use transaction because $criteria could contain info
         // for more than one table or we could emulating ON DELETE CASCADE, etc.
         $con->beginTransaction();
         $affectedRows += BasePeer::doDelete($criteria, $con);
         CcShowInstancesPeer::clearRelatedInstancePool();
         $con->commit();
         return $affectedRows;
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemplo n.º 4
0
 /**
  * Method to invalidate the instance pool of all tables related to cc_show
  * by a foreign key with ON DELETE CASCADE
  */
 public static function clearRelatedInstancePool()
 {
     // Invalidate objects in CcShowInstancesPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowInstancesPeer::clearInstancePool();
     // Invalidate objects in CcShowDaysPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowDaysPeer::clearInstancePool();
     // Invalidate objects in CcShowRebroadcastPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowRebroadcastPeer::clearInstancePool();
     // Invalidate objects in CcShowHostsPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowHostsPeer::clearInstancePool();
 }