public static function RecallByPartialFilepath($partial_path) { $path_info = Application_Model_MusicDir::splitFilePath($partial_path); if (is_null($path_info)) { return null; } $music_dir = Application_Model_MusicDir::getDirByPath($path_info[0]); $files = CcFilesQuery::create()->filterByDbDirectory($music_dir->getId())->filterByDbFilepath("{$path_info['1']}%")->find(); $res = array(); foreach ($files as $file) { $storedFile = new Application_Model_StoredFile(); $storedFile->_file = $file; $res[] = $storedFile; } return $res; }
public function updateFileSystemMountAction() { $request = $this->getRequest(); $params = $request->getParams(); $added_list = empty($params['added_dir']) ? array() : explode(',', $params['added_dir']); $removed_list = empty($params['removed_dir']) ? array() : explode(',', $params['removed_dir']); // get all watched dirs $watched_dirs = Application_Model_MusicDir::getWatchedDirs(null, null); foreach ($added_list as $ad) { $ad .= '/'; foreach ($watched_dirs as $dir) { $dirPath = $dir->getDirectory(); // if mount path itself was watched if ($dirPath == $ad) { Application_Model_MusicDir::addWatchedDir($dirPath, false); } elseif (substr($dirPath, 0, strlen($ad)) === $ad && $dir->getExistsFlag() == false) { // if dir contains any dir in removed_list( if watched dir resides on new mounted path ) Application_Model_MusicDir::addWatchedDir($dirPath, false); } elseif (substr($ad, 0, strlen($dirPath)) === $dirPath) { // is new mount point within the watched dir? // pyinotify doesn't notify anyhing in this case, so we add this mount point as // watched dir // bypass nested loop check Application_Model_MusicDir::addWatchedDir($ad, false, true); } } } foreach ($removed_list as $rd) { $rd .= '/'; foreach ($watched_dirs as $dir) { $dirPath = $dir->getDirectory(); // if dir contains any dir in removed_list( if watched dir resides on new mounted path ) if (substr($dirPath, 0, strlen($rd)) === $rd && $dir->getExistsFlag() == true) { Application_Model_MusicDir::removeWatchedDir($dirPath, false); } elseif (substr($rd, 0, strlen($dirPath)) === $dirPath) { // is new mount point within the watched dir? // pyinotify doesn't notify anyhing in this case, so we walk through all files within // this watched dir in DB and mark them deleted. // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to // compare agaisnt all files in cc_files table $watchDir = Application_Model_MusicDir::getDirByPath($rd); // get all the files that is under $dirPath $files = Application_Model_StoredFile::listAllFiles($dir->getId(), $all = false); foreach ($files as $f) { // if the file is from this mount if (substr($f->getFilePath(), 0, strlen($rd)) === $rd) { $f->delete(); } } if ($watchDir) { Application_Model_MusicDir::removeWatchedDir($rd, false); } } } } }
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); }
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; }
/** 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); } }