refactored addWatchedDir to use early return style

This commit is contained in:
Rudi Grinberg 2012-11-03 01:16:57 -04:00
parent 5d3aa68c72
commit 9c4f2e3298
1 changed files with 31 additions and 32 deletions

View File

@ -246,50 +246,49 @@ SQL;
{
$res = self::addDir($p_path, "watched", $userAddedWatchedDir, $nestedWatch);
if ($res['code'] == 0) {
if ($res['code'] != 0) { return $res; }
//convert "linked" files (Airtime <= 1.8.2) to watched files.
$propel_link_dir = CcMusicDirsQuery::create()
->filterByType('link')
//convert "linked" files (Airtime <= 1.8.2) to watched files.
$propel_link_dir = CcMusicDirsQuery::create()
->filterByType('link')
->findOne();
//see if any linked files exist.
if (isset($propel_link_dir)) {
//newly added watched directory object
$propel_new_watch = CcMusicDirsQuery::create()
->filterByDirectory(Application_Common_OsPath::normpath($p_path)."/")
->findOne();
//see if any linked files exist.
if (isset($propel_link_dir)) {
//any files of the deprecated "link" type.
$link_files = CcFilesQuery::create()
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->filterByDbDirectory($propel_link_dir->getId())
->find();
//newly added watched directory object
$propel_new_watch = CcMusicDirsQuery::create()
->filterByDirectory(Application_Common_OsPath::normpath($p_path)."/")
->findOne();
$newly_watched_dir = $propel_new_watch->getDirectory();
//any files of the deprecated "link" type.
$link_files = CcFilesQuery::create()
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->filterByDbDirectory($propel_link_dir->getId())
->find();
foreach ($link_files as $link_file) {
$link_filepath = $link_file->getDbFilepath();
$newly_watched_dir = $propel_new_watch->getDirectory();
//convert "link" file into a watched file.
if ((strlen($newly_watched_dir) < strlen($link_filepath)) && (substr($link_filepath, 0, strlen($newly_watched_dir)) === $newly_watched_dir)) {
foreach ($link_files as $link_file) {
$link_filepath = $link_file->getDbFilepath();
//get the filepath path not including the watched directory.
$sub_link_filepath = substr($link_filepath, strlen($newly_watched_dir));
//convert "link" file into a watched file.
if ((strlen($newly_watched_dir) < strlen($link_filepath)) && (substr($link_filepath, 0, strlen($newly_watched_dir)) === $newly_watched_dir)) {
//get the filepath path not including the watched directory.
$sub_link_filepath = substr($link_filepath, strlen($newly_watched_dir));
$link_file->setDbDirectory($propel_new_watch->getId());
$link_file->setDbFilepath($sub_link_filepath);
$link_file->save();
}
$link_file->setDbDirectory($propel_new_watch->getId());
$link_file->setDbFilepath($sub_link_filepath);
$link_file->save();
}
}
$data = array();
$data["directory"] = $p_path;
Application_Model_RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
}
$data = array();
$data["directory"] = $p_path;
Application_Model_RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
return $res;
}