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; }
/** * 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(); }
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); }
/** 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); } }
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; }
/** * 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(); } }
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'); }