From 9c4f2e329845f92da47d3edcd9674d24872c9d68 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 3 Nov 2012 01:16:57 -0400 Subject: [PATCH] refactored addWatchedDir to use early return style --- airtime_mvc/application/models/MusicDir.php | 63 ++++++++++----------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index 40ccc58be..1098bd5a0 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -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; }