CC-2551:airtime-import:Script doesnot send msg to media monitor
- move all error checking and RabitMq calls into MusicDir functions - fix in PreferenceController.php so it works with new functions from MusicDir
This commit is contained in:
parent
47645a2049
commit
2b1a0b4f72
|
@ -124,22 +124,9 @@ class PreferenceController extends Zend_Controller_Action
|
|||
$element = $this->getRequest()->getParam("element");
|
||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||
$watched_dirs_form->populate(array('storageFolder' => $chosen));
|
||||
$bool = $watched_dirs_form->verifyChosenFolder($element);
|
||||
|
||||
// it has error checking in two part. It checks is_dir above, and
|
||||
// check uniqueness in DB below. We should put is_dir checking into
|
||||
// MusicDir class.
|
||||
if ($bool === true) {
|
||||
$res = MusicDir::setStorDir($chosen);
|
||||
if($res['code'] == 0){
|
||||
$dirId = MusicDir::getStorDir()->getId();
|
||||
$data = array();
|
||||
$data["directory"] = $chosen;
|
||||
$data["dir_id"] = $dirId;
|
||||
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
||||
}else{
|
||||
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||
}
|
||||
$res = MusicDir::setStorDir($chosen);
|
||||
if($res['code'] != 0){
|
||||
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||
}
|
||||
|
||||
$this->view->subform = $watched_dirs_form->render();
|
||||
|
@ -151,20 +138,9 @@ class PreferenceController extends Zend_Controller_Action
|
|||
$element = $this->getRequest()->getParam("element");
|
||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
|
||||
$bool = $watched_dirs_form->verifyChosenFolder($element);
|
||||
|
||||
// it has error checking in two part. It checks is_dir above, and
|
||||
// check uniqueness in DB below. We should put is_dir checking into
|
||||
// MusicDir class.
|
||||
if ($bool === true) {
|
||||
$res = MusicDir::addWatchedDir($chosen);
|
||||
if($res['code'] == 0){
|
||||
$data = array();
|
||||
$data["directory"] = $chosen;
|
||||
RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
|
||||
}else{
|
||||
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||
}
|
||||
$res = MusicDir::addWatchedDir($chosen);
|
||||
if($res['code'] != 0){
|
||||
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||
}
|
||||
|
||||
$this->view->subform = $watched_dirs_form->render();
|
||||
|
@ -174,12 +150,7 @@ class PreferenceController extends Zend_Controller_Action
|
|||
{
|
||||
$chosen = $this->getRequest()->getParam("dir");
|
||||
|
||||
$dir = MusicDir::getDirByPath($chosen);
|
||||
$dir->remove();
|
||||
|
||||
$data = array();
|
||||
$data["directory"] = $chosen;
|
||||
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
|
||||
$dir = MusicDir::removeWatchedDir($chosen);
|
||||
|
||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||
$this->view->subform = $watched_dirs_form->render();
|
||||
|
|
|
@ -45,6 +45,9 @@ class MusicDir {
|
|||
|
||||
public static function addDir($p_path, $p_type)
|
||||
{
|
||||
if(!is_dir($p_path)){
|
||||
return array("code"=>2, "error"=>"'$p_path' is not a valid directory.");
|
||||
}
|
||||
$dir = new CcMusicDirs();
|
||||
$dir->setType($p_type);
|
||||
$p_path = realpath($p_path)."/";
|
||||
|
@ -55,14 +58,20 @@ class MusicDir {
|
|||
}
|
||||
catch(Exception $e){
|
||||
//echo $e->getMessage();
|
||||
return array("code"=>1, "error"=>"$p_path is already set as the current storage dir or in the watched folders list");
|
||||
return array("code"=>1, "error"=>"'$p_path' is already set as the current storage dir or in the watched folders list");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function addWatchedDir($p_path)
|
||||
{
|
||||
return self::addDir($p_path, "watched");
|
||||
$res = self::addDir($p_path, "watched");
|
||||
if($res['code'] == 0){
|
||||
$data = array();
|
||||
$data["directory"] = $p_path;
|
||||
RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function getDirByPK($pk)
|
||||
|
@ -118,15 +127,23 @@ class MusicDir {
|
|||
|
||||
public static function setStorDir($p_dir)
|
||||
{
|
||||
if(!is_dir($p_dir)){
|
||||
return array("code"=>2, "error"=>"'$p_dir' is not a valid directory.");
|
||||
}
|
||||
$dir = self::getStorDir();
|
||||
// if $p_dir doesn't exist in DB
|
||||
$p_dir = realpath($p_dir)."/";
|
||||
$exist = $dir->getDirByPath($p_dir);
|
||||
if($exist == NULL){
|
||||
$dir->setDirectory($p_dir);
|
||||
$dirId = $dir->getId();
|
||||
$data = array();
|
||||
$data["directory"] = $p_dir;
|
||||
$data["dir_id"] = $dirId;
|
||||
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
||||
return array("code"=>0);
|
||||
}else{
|
||||
return array("code"=>1, "error"=>"$p_dir is already set as the current storage dir or in the watched folders list");
|
||||
return array("code"=>1, "error"=>"'$p_dir' is already set as the current storage dir or in the watched folders list.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,9 +167,12 @@ class MusicDir {
|
|||
$p_dir = realpath($p_dir)."/";
|
||||
$dir = MusicDir::getDirByPath($p_dir);
|
||||
if($dir == NULL){
|
||||
return array("code"=>1,"error"=>"$p_dir doesn't exist in the watched list");
|
||||
return array("code"=>1,"error"=>"'$p_dir' doesn't exist in the watched list.");
|
||||
}else{
|
||||
$dir->remove();
|
||||
$data = array();
|
||||
$data["directory"] = $p_dir;
|
||||
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
|
||||
return array("code"=>0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue