Exemplo n.º 1
0
 public function dispatchLoopShutdown()
 {
     if (Application_Model_RabbitMq::$doPush) {
         $md = array('schedule' => Application_Model_Schedule::getSchedule());
         Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md);
         if (!isset($_SERVER['AIRTIME_SRV'])) {
             Application_Model_RabbitMq::SendMessageToShowRecorder("update_recorder_schedule");
         }
     }
     if (memory_get_peak_usage() > 30 * pow(2, 20)) {
         Logging::debug("Peak memory usage: " . memory_get_peak_usage() / 1000000 . " MB while accessing URI " . $_SERVER['REQUEST_URI']);
         Logging::debug("Should try to keep memory footprint under 25 MB");
     }
 }
 public function switchSourceAction()
 {
     $sourcename = $this->_getParam('sourcename');
     $current_status = $this->_getParam('status');
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     $show = Application_Model_Show::getCurrentShow();
     $show_id = isset($show[0]['id']) ? $show[0]['id'] : 0;
     $source_connected = Application_Model_Preference::GetSourceStatus($sourcename);
     if ($user->canSchedule($show_id) && ($source_connected || $sourcename == 'scheduled_play' || $current_status == "on")) {
         $change_status_to = "on";
         if (strtolower($current_status) == "on") {
             $change_status_to = "off";
         }
         $data = array("sourcename" => $sourcename, "status" => $change_status_to);
         Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data);
         if (strtolower($current_status) == "on") {
             Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off");
             $this->view->status = "OFF";
             //Log table updates
             Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play' ? 'S' : 'L', new DateTime("now", new DateTimeZone('UTC')));
         } else {
             Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on");
             $this->view->status = "ON";
             //Log table updates
             Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play' ? 'S' : 'L', new DateTime("now", new DateTimeZone('UTC')));
         }
     } else {
         if ($source_connected) {
             $this->view->error = _("You don't have permission to switch source.");
         } else {
             if ($sourcename == 'scheduled_play') {
                 $this->view->error = _("You don't have permission to disconnect source.");
             } else {
                 $this->view->error = _("There is no source connected to this input.");
             }
         }
     }
 }
Exemplo n.º 3
0
 public function cancelCurrentShowAction()
 {
     $user = Application_Model_User::getCurrentUser();
     if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
         $id = $this->_getParam('id');
         try {
             $scheduler = new Application_Model_Scheduler();
             $scheduler->cancelShow($id);
             // send kick out source stream signal to pypo
             $data = array("sourcename" => "live_dj");
             Application_Model_RabbitMq::SendMessageToPypo("disconnect_source", $data);
         } catch (Exception $e) {
             $this->view->error = $e->getMessage();
             Logging::info($e->getMessage());
         }
     }
 }
Exemplo n.º 4
0
 public function rabbitmqDoPushAction()
 {
     Logging::info("Notifying RabbitMQ to send message to pypo");
     Application_Model_RabbitMq::SendMessageToPypo("reset_liquidsoap_bootstrap", array());
     Application_Model_RabbitMq::PushSchedule();
 }
Exemplo n.º 5
0
 public function rescanWatchDirectoryAction()
 {
     $dir = Application_Model_MusicDir::getDirByPath($this->getRequest()->getParam("dir"));
     $id = $dir->getId();
     $data = array();
     $data['directory'] = $dir->getDirectory();
     $data['id'] = $id;
     Application_Model_RabbitMq::SendMessageToMediaMonitor('rescan_watch', $data);
     die;
 }
Exemplo n.º 6
0
 /**
  * Delete stored virtual file
  *
  * @param boolean $p_deleteFile
  *
  */
 public function delete()
 {
     $filepath = $this->getFilePath();
     // Check if the file is scheduled to be played in the future
     if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
         throw new DeleteScheduledFileException();
     }
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     if (!$isAdminOrPM && $this->getFileOwnerId() != $user->getId()) {
         throw new FileNoPermissionException();
     }
     $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
     $type = $music_dir->getType();
     if (file_exists($filepath) && $type == "stor") {
         $data = array("filepath" => $filepath, "delete" => 1);
         try {
             Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
         } catch (Exception $e) {
             Logging::error($e->getMessage());
             return;
         }
     }
     // set hidden flag to true
     $this->_file->setDbHidden(true);
     $this->_file->save();
     // need to explicitly update any playlist's and block's length
     // that contains the file getting deleted
     $fileId = $this->_file->getDbId();
     $plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find();
     foreach ($plRows as $row) {
         $pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne();
         $pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME)));
         $pl->save();
     }
     $blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find();
     foreach ($blRows as $row) {
         $bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne();
         $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME)));
         $bl->save();
     }
 }
Exemplo n.º 7
0
 public function resizeShow($deltaDay, $deltaMin)
 {
     try {
         $con = Propel::getConnection();
         $con->beginTransaction();
         $con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Exemplo n.º 8
0
 public function cancelShow($p_id)
 {
     $this->con->beginTransaction();
     try {
         $instance = CcShowInstancesQuery::create()->findPK($p_id);
         if (!$instance->getDbRecord()) {
             $items = CcScheduleQuery::create()->filterByDbInstanceId($p_id)->filterByDbEnds($this->nowDT, Criteria::GREATER_THAN)->find($this->con);
             if (count($items) > 0) {
                 $remove = array();
                 $ts = $this->nowDT->format('U');
                 for ($i = 0; $i < count($items); $i++) {
                     $remove[$i]["instance"] = $p_id;
                     $remove[$i]["timestamp"] = $ts;
                     $remove[$i]["id"] = $items[$i]->getDbId();
                 }
                 $this->removeItems($remove, false);
             }
         } else {
             $rebroadcasts = $instance->getCcShowInstancessRelatedByDbId(null, $this->con);
             $rebroadcasts->delete($this->con);
         }
         $instance->setDbEnds($this->nowDT);
         $instance->save($this->con);
         $this->con->commit();
         if ($instance->getDbRecord()) {
             Application_Model_RabbitMq::SendMessageToShowRecorder("cancel_recording");
         }
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
 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;
     }
 }
Exemplo n.º 10
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();
 }
Exemplo n.º 11
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;
     }
 }
Exemplo n.º 12
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 static function removeWatchedDir($p_dir, $userAddedWatchedDir = true)
 {
     //make sure that $p_dir has a trailing "/"
     $real_path = Application_Common_OsPath::normpath($p_dir) . "/";
     if ($real_path != "/") {
         $p_dir = $real_path;
     }
     $dir = Application_Model_MusicDir::getDirByPath($p_dir);
     if (is_null($dir)) {
         return array("code" => 1, "error" => "'{$p_dir}' doesn't exist in the watched list.");
     } else {
         $dir->remove($userAddedWatchedDir);
         $data = array();
         $data["directory"] = $p_dir;
         Application_Model_RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
         return array("code" => 0);
     }
 }
Exemplo n.º 13
0
 /**
  * Sets a flag to push the schedule at the end of the request.
  */
 public static function PushSchedule()
 {
     self::$doPush = true;
 }
Exemplo n.º 14
0
 public function editFileMdAction()
 {
     $user = Application_Model_User::getCurrentUser();
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     if (!$isAdminOrPM) {
         return;
     }
     $request = $this->getRequest();
     $form = new Application_Form_EditAudioMD();
     $file_id = $this->_getParam('id', null);
     $file = Application_Model_StoredFile::Recall($file_id);
     $form->populate($file->getDbColMetadata());
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $formdata = $form->getValues();
             $file->setDbColMetadata($formdata);
             $data = $file->getMetadata();
             // set MDATA_KEY_FILEPATH
             $data['MDATA_KEY_FILEPATH'] = $file->getFilePath();
             Logging::info($data['MDATA_KEY_FILEPATH']);
             Application_Model_RabbitMq::SendMessageToMediaMonitor("md_update", $data);
             $this->_redirect('Library');
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 15
0
 public static function SetStreamLabelFormat($type)
 {
     self::setValue("stream_label_format", $type);
     $eventType = "update_stream_format";
     $md = array("stream_format" => $type);
     Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
 }
Exemplo n.º 16
0
    $instances = Application_Model_Show::getShows($showTime, $showTime);
    $instance = array_pop($instances);
    $show = new Application_Model_ShowInstance($instance["instance_id"]);
    //echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n";
    $show->scheduleShow(array(1));
    //echo "done\n";
    //$show->scheduleShow(array($playlist->getId()));
}
$showTime = new DateTime();
$resolution = "hour";
$showNumber = 1;
$numberOfDays = 180;
$numberOfHours = 0;
$endDate = new DateTime();
$endDate->add(new DateInterval("P" . $numberOfDays . "DT" . $numberOfHours . "H"));
echo "End date: " . $endDate->format("Y-m-d H:i") . "\n";
while ($showTime < $endDate) {
    echo $showTime->format("Y-m-d H:i") . " < " . $endDate->format("Y-m-d H:i") . "\n";
    if ($resolution == "minute") {
        createTestShow($showNumber, $showTime, "0:01");
        $showTime->add(new DateInterval("PT1M"));
    } elseif ($resolution == "hour") {
        createTestShow($showNumber, $showTime);
        $showTime->add(new DateInterval("PT1H"));
    }
    $showNumber = $showNumber + 1;
}
if (Application_Model_RabbitMq::$doPush) {
    $md = array('schedule' => Application_Model_Schedule::getSchedule());
    Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md);
}
 public function rescanWatchDirectoryAction()
 {
     $dir_path = $this->getRequest()->getParam('dir');
     $dir = Application_Model_MusicDir::getDirByPath($dir_path);
     $data = array('directory' => $dir->getDirectory(), 'id' => $dir->getId());
     Application_Model_RabbitMq::SendMessageToMediaMonitor('rescan_watch', $data);
     Logging::info("Unhiding all files belonging to:: {$dir_path}");
     $dir->unhideFiles();
     $this->_helper->json->sendJson(null);
 }
Exemplo n.º 18
0
 /**
  * Delete stored virtual file
  *
  * @param boolean $p_deleteFile
  *
  */
 public function delete($deleteFromPlaylist = false)
 {
     $filepath = $this->getFilePath();
     // Check if the file is scheduled to be played in the future
     if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
         throw new DeleteScheduledFileException();
     }
     $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
     $type = $music_dir->getType();
     if (file_exists($filepath) && $type == "stor") {
         $data = array("filepath" => $filepath, "delete" => 1);
         Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
     }
     if ($deleteFromPlaylist) {
         Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId());
     }
     // set file_exists falg to false
     $this->_file->setDbFileExists(false);
     $this->_file->save();
 }
Exemplo n.º 19
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();
    }
Exemplo n.º 20
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();
     }
 }
Exemplo n.º 21
0
 public function editFileMdAction()
 {
     $user = Application_Model_User::getCurrentUser();
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     $request = $this->getRequest();
     $file_id = $this->_getParam('id', null);
     $file = Application_Model_StoredFile::RecallById($file_id);
     if (!$isAdminOrPM && $file->getFileOwnerId() != $user->getId()) {
         return;
     }
     $form = new Application_Form_EditAudioMD();
     $form->startForm($file_id);
     $form->populate($file->getDbColMetadata());
     if ($request->isPost()) {
         $js = $this->_getParam('data');
         $serialized = array();
         //need to convert from serialized jQuery array.
         foreach ($js as $j) {
             $serialized[$j["name"]] = $j["value"];
         }
         if ($form->isValid($serialized)) {
             $formValues = $this->_getParam('data', null);
             $formdata = array();
             foreach ($formValues as $val) {
                 $formdata[$val["name"]] = $val["value"];
             }
             $file->setDbColMetadata($formdata);
             $data = $file->getMetadata();
             // set MDATA_KEY_FILEPATH
             $data['MDATA_KEY_FILEPATH'] = $file->getFilePath();
             Logging::info($data['MDATA_KEY_FILEPATH']);
             Application_Model_RabbitMq::SendMessageToMediaMonitor("md_update", $data);
             $this->_redirect('Library');
         }
     }
     $this->view->form = $form;
     $this->view->dialog = $this->view->render('library/edit-file-md.phtml');
 }