Esempio n. 1
0
 public function delete($rabbitmqPush = true)
 {
     // see if it was recording show
     $recording = $this->isRecorded();
     // get show id
     $showId = $this->getShowId();
     $show = $this->getShow();
     $current_timestamp = gmdate("Y-m-d H:i:s");
     if ($current_timestamp <= $this->getShowInstanceEnd()) {
         if ($show->isRepeating()) {
             CcShowInstancesQuery::create()->findPK($this->_instanceId)->setDbModifiedInstance(true)->save();
             if ($this->isRebroadcast()) {
                 return;
             }
             //delete the rebroadcasts of the removed recorded show.
             if ($recording) {
                 CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->delete();
             }
             /* Automatically delete all files scheduled in cc_schedules table. */
             CcScheduleQuery::create()->filterByDbInstanceId($this->_instanceId)->delete();
             if ($this->checkToDeleteShow($showId)) {
                 CcShowQuery::create()->filterByDbId($showId)->delete();
             }
         } else {
             if ($this->isRebroadcast()) {
                 $this->_showInstance->delete();
             } else {
                 $show->delete();
             }
         }
     }
     if ($rabbitmqPush) {
         Application_Model_RabbitMq::PushSchedule();
     }
 }
Esempio n. 2
0
 public function removeItems($scheduledItems, $adjustSched = true)
 {
     $showInstances = array();
     $this->con->beginTransaction();
     try {
         $this->validateRequest($scheduledItems);
         $scheduledIds = array();
         foreach ($scheduledItems as $item) {
             $scheduledIds[] = $item["id"];
         }
         $removedItems = CcScheduleQuery::create()->findPks($scheduledIds);
         //check to make sure all items selected are up to date
         foreach ($removedItems as $removedItem) {
             $instance = $removedItem->getCcShowInstances($this->con);
             //check to truncate the currently playing item instead of deleting it.
             if ($removedItem->isCurrentItem($this->epochNow)) {
                 $nEpoch = $this->epochNow;
                 $sEpoch = $removedItem->getDbStarts('U.u');
                 $length = bcsub($nEpoch, $sEpoch, 6);
                 $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn());
                 $cueOutSec = bcadd($cueinSec, $length, 6);
                 $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec);
                 //Set DbEnds - 1 second because otherwise there can be a timing issue
                 //when sending the new schedule to Pypo where Pypo thinks the track is still
                 //playing.
                 $removedItem->setDbCueOut($cueout)->setDbClipLength($cliplength)->setDbEnds($this->nowDT)->save($this->con);
             } else {
                 $removedItem->delete($this->con);
             }
         }
         if ($adjustSched === true) {
             //get the show instances of the shows we must adjust times for.
             foreach ($removedItems as $item) {
                 $instance = $item->getDBInstanceId();
                 if (!in_array($instance, $showInstances)) {
                     $showInstances[] = $instance;
                 }
             }
             foreach ($showInstances as $instance) {
                 $this->removeGaps($instance);
             }
         }
         //update the status flag in cc_schedule.
         $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->find($this->con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($this->con);
         }
         //update the last scheduled timestamp.
         CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
         $this->con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
 public function resizeShow($deltaDay, $deltaMin)
 {
     try {
         $con = Propel::getConnection();
         $con->beginTransaction();
         $con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Esempio n. 4
0
    public function cancelShow($day_timestamp)
    {
        $timeinfo = explode(" ", $day_timestamp);
        CcShowDaysQuery::create()->filterByDbShowId($this->_showId)->update(array('DbLastShow' => $timeinfo[0]));
        $sql = <<<SQL
SELECT id from cc_show_instances
WHERE starts >= :dayTimestamp::TIMESTAMP
  AND show_id = :showId
SQL;
        $rows = Application_Common_Database::prepareAndExecute($sql, array(':dayTimestamp' => $day_timestamp, ':showId' => $this->getId()), 'all');
        foreach ($rows as $row) {
            try {
                $showInstance = new Application_Model_ShowInstance($row["id"]);
                $showInstance->delete($rabbitmqPush = false);
            } catch (Exception $e) {
                Logging::info($e->getMessage());
            }
        }
        Application_Model_RabbitMq::PushSchedule();
    }
 public function rabbitmqDoPushAction()
 {
     Logging::info("Notifying RabbitMQ to send message to pypo");
     Application_Model_RabbitMq::SendMessageToPypo("reset_liquidsoap_bootstrap", array());
     Application_Model_RabbitMq::PushSchedule();
 }
 public function emptyShowContent($instanceId)
 {
     try {
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         $instances = array();
         $instanceIds = array();
         if ($ccShowInstance->getCcShow()->isLinked()) {
             foreach ($ccShowInstance->getCcShow()->getCcShowInstancess() as $instance) {
                 $instanceIds[] = $instance->getDbId();
                 $instances[] = $instance;
             }
         } else {
             $instanceIds[] = $ccShowInstance->getDbId();
             $instances[] = $ccShowInstance;
         }
         /* Get the file ids of the tracks we are about to delete
          * from cc_schedule. We need these so we can update the
          * is_scheduled flag in cc_files
          */
         $ccSchedules = CcScheduleQuery::create()->filterByDbInstanceId($instanceIds, Criteria::IN)->setDistinct(CcSchedulePeer::FILE_ID)->find();
         $fileIds = array();
         foreach ($ccSchedules as $ccSchedule) {
             $fileIds[] = $ccSchedule->getDbFileId();
         }
         /* Clear out the schedule */
         CcScheduleQuery::create()->filterByDbInstanceId($instanceIds, Criteria::IN)->delete();
         /* Now that the schedule has been cleared we need to make
          * sure we do not update the is_scheduled flag for tracks
          * that are scheduled in other shows
          */
         $futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles();
         foreach ($fileIds as $k => $v) {
             if (in_array($v, $futureScheduledFiles)) {
                 unset($fileIds[$k]);
             }
         }
         $selectCriteria = new Criteria();
         $selectCriteria->add(CcFilesPeer::ID, $fileIds, Criteria::IN);
         $updateCriteria = new Criteria();
         $updateCriteria->add(CcFilesPeer::IS_SCHEDULED, false);
         BasePeer::doUpdate($selectCriteria, $updateCriteria, Propel::getConnection());
         Application_Model_RabbitMq::PushSchedule();
         $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
         foreach ($instances as $instance) {
             $instance->updateDbTimeFilled($con);
         }
         return true;
     } catch (Exception $e) {
         Logging::info($e->getMessage());
         return false;
     }
 }
Esempio n. 7
0
 public function removeItems($scheduledItems, $adjustSched = true, $cancelShow = false)
 {
     $showInstances = array();
     $this->con->beginTransaction();
     try {
         $this->validateRequest($scheduledItems);
         $scheduledIds = array();
         foreach ($scheduledItems as $item) {
             $scheduledIds[] = $item["id"];
         }
         $removedItems = CcScheduleQuery::create()->findPks($scheduledIds);
         //check to make sure all items selected are up to date
         foreach ($removedItems as $removedItem) {
             $instance = $removedItem->getCcShowInstances($this->con);
             //check if instance is linked and if so get the schedule items
             //for all linked instances so we can delete them too
             if (!$cancelShow && $instance->getCcShow()->isLinked()) {
                 //returns all linked instances if linked
                 $ccShowInstances = $this->getInstances($instance->getDbId());
                 $instanceIds = array();
                 foreach ($ccShowInstances as $ccShowInstance) {
                     $instanceIds[] = $ccShowInstance->getDbId();
                 }
                 /*
                  * Find all the schedule items that are in the same position
                  * as the selected item by the user.
                  * The position of each track is the same across each linked instance
                  */
                 $itemsToDelete = CcScheduleQuery::create()->filterByDbPosition($removedItem->getDbPosition())->filterByDbInstanceId($instanceIds, Criteria::IN)->find();
                 foreach ($itemsToDelete as $item) {
                     if (!$removedItems->contains($item)) {
                         $removedItems->append($item);
                     }
                 }
             }
             //check to truncate the currently playing item instead of deleting it.
             if ($removedItem->isCurrentItem($this->epochNow)) {
                 $nEpoch = $this->epochNow;
                 $sEpoch = $removedItem->getDbStarts('U.u');
                 $length = bcsub($nEpoch, $sEpoch, 6);
                 $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn());
                 $cueOutSec = bcadd($cueinSec, $length, 6);
                 $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec);
                 //Set DbEnds - 1 second because otherwise there can be a timing issue
                 //when sending the new schedule to Pypo where Pypo thinks the track is still
                 //playing.
                 $removedItem->setDbCueOut($cueout)->setDbClipLength($cliplength)->setDbEnds($this->nowDT)->save($this->con);
             } else {
                 $removedItem->delete($this->con);
             }
             // update is_scheduled in cc_files but only if
             // the file is not scheduled somewhere else
             $fileId = $removedItem->getDbFileId();
             // check if the removed item is scheduled somewhere else
             $futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles();
             if (!is_null($fileId) && !in_array($fileId, $futureScheduledFiles)) {
                 $db_file = CcFilesQuery::create()->findPk($fileId, $this->con);
                 $db_file->setDbIsScheduled(false)->save($this->con);
             }
         }
         if ($adjustSched === true) {
             //get the show instances of the shows we must adjust times for.
             foreach ($removedItems as $item) {
                 $instance = $item->getDBInstanceId();
                 if (!in_array($instance, $showInstances)) {
                     $showInstances[] = $instance;
                 }
             }
             foreach ($showInstances as $instance) {
                 $this->removeGaps($instance);
                 $this->calculateCrossfades($instance);
             }
         }
         //update the status flag in cc_schedule.
         $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->find($this->con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($this->con);
             $instance->correctSchedulePositions();
         }
         //update the last scheduled timestamp.
         CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
         $this->con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
Esempio n. 8
0
 /**
  * We are going to use cc_show_days as a template, to generate Show Instances. This function
  * is basically a dispatcher that looks at the show template, and sends it to the correct function
  * so that Show Instance generation can begin. After the all show instances have been created, pushes
  * the schedule to Pypo.
  *
  * @param array $p_showRow
  *        A row from cc_show_days table
  * @param DateTime $p_populateUntilDateTime
  *        DateTime object in UTC time.
  */
 private static function populateShow($p_showDaysRow, $p_populateUntilDateTime)
 {
     // TODO : use constants instead of int values here? or maybe php will
     // get enum types by the time somebody gets around to fix this. -- RG
     if ($p_showDaysRow["repeat_type"] == -1) {
         Application_Model_Show::populateNonRepeatingShow($p_showDaysRow, $p_populateUntilDateTime);
     } elseif ($p_showDaysRow["repeat_type"] == 0) {
         Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P7D');
     } elseif ($p_showDaysRow["repeat_type"] == 1) {
         Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P14D');
     } elseif ($p_showDaysRow["repeat_type"] == 2) {
         Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P1M');
     }
     Application_Model_RabbitMq::PushSchedule();
 }
Esempio n. 9
0
 public function deleteShow($instanceId, $singleInstance = false)
 {
     $service_user = new Application_Service_UserService();
     $currentUser = $service_user->getCurrentUser();
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         if (!$currentUser->isAdminOrPM()) {
             throw new Exception("Permission denied");
         }
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         if (!$ccShowInstance) {
             throw new Exception("Could not find show instance");
         }
         $showId = $ccShowInstance->getDbShowId();
         if ($singleInstance) {
             $ccShowInstances = CcShowInstancesQuery::create()->filterByDbShowId($showId)->filterByDbStarts($ccShowInstance->getDbStarts(), Criteria::GREATER_EQUAL)->filterByDbEnds($ccShowInstance->getDbEnds(), Criteria::LESS_EQUAL)->find();
         } else {
             $ccShowInstances = CcShowInstancesQuery::create()->filterByDbShowId($showId)->filterByDbStarts($ccShowInstance->getDbStarts(), Criteria::GREATER_EQUAL)->find();
         }
         if (gmdate("Y-m-d H:i:s") <= $ccShowInstance->getDbEnds()) {
             $this->deleteShowInstances($ccShowInstances, $ccShowInstance->getDbShowId());
         }
         Application_Model_StoredFile::updatePastFilesIsScheduled();
         Application_Model_RabbitMq::PushSchedule();
         $con->commit();
         return $showId;
     } catch (Exception $e) {
         $con->rollback();
         Logging::info("Delete show instance failed");
         Logging::info($e->getMessage());
         return false;
     }
 }
Esempio n. 10
0
    /**
     * There are 2 cases where this function can be called.
     * 1. When watched dir was removed
     * 2. When some dir was watched, but it was unmounted
     *
     *  In case of 1, $userAddedWatchedDir should be true
     *  In case of 2, $userAddedWatchedDir should be false
     *
     *  When $userAddedWatchedDir is true, it will set "Watched" flag to false
     *  otherwise, it will set "Exists" flag to true
     */
    public function remove($userAddedWatchedDir = true)
    {
        $music_dir_id = $this->getId();
        $sql = <<<SQL
SELECT DISTINCT s.instance_id
FROM cc_music_dirs            AS md
LEFT JOIN cc_files            AS f ON f.directory = md.id
RIGHT JOIN cc_schedule        AS s ON s.file_id = f.id
WHERE md.id = :musicDirId;
SQL;
        $show_instances = Application_Common_Database::prepareAndExecute($sql, array(':musicDirId' => $music_dir_id), 'all');
        // get all the files on this dir
        $sql = <<<SQL
UPDATE cc_files
SET file_exists = 'f'
WHERE id IN
    (SELECT f.id
     FROM cc_music_dirs AS md
     LEFT JOIN cc_files AS f ON f.directory = md.id
     WHERE md.id = :musicDirId);
SQL;
        $affected = Application_Common_Database::prepareAndExecute($sql, array(':musicDirId' => $music_dir_id), 'all');
        // set RemovedFlag to true
        if ($userAddedWatchedDir) {
            self::setWatchedFlag(false);
        } else {
            self::setExistsFlag(false);
        }
        //$res = $this->_dir->delete();
        foreach ($show_instances as $show_instance_row) {
            $temp_show = new Application_Model_ShowInstance($show_instance_row["instance_id"]);
            $temp_show->updateScheduledTime();
        }
        Application_Model_RabbitMq::PushSchedule();
    }