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,23 +124,10 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
$element = $this->getRequest()->getParam("element");
|
$element = $this->getRequest()->getParam("element");
|
||||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||||
$watched_dirs_form->populate(array('storageFolder' => $chosen));
|
$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);
|
$res = MusicDir::setStorDir($chosen);
|
||||||
if($res['code'] == 0){
|
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']));
|
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->view->subform = $watched_dirs_form->render();
|
$this->view->subform = $watched_dirs_form->render();
|
||||||
}
|
}
|
||||||
|
@ -151,21 +138,10 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
$element = $this->getRequest()->getParam("element");
|
$element = $this->getRequest()->getParam("element");
|
||||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||||
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
|
$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);
|
$res = MusicDir::addWatchedDir($chosen);
|
||||||
if($res['code'] == 0){
|
if($res['code'] != 0){
|
||||||
$data = array();
|
|
||||||
$data["directory"] = $chosen;
|
|
||||||
RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
|
|
||||||
}else{
|
|
||||||
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->view->subform = $watched_dirs_form->render();
|
$this->view->subform = $watched_dirs_form->render();
|
||||||
}
|
}
|
||||||
|
@ -174,12 +150,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
$chosen = $this->getRequest()->getParam("dir");
|
$chosen = $this->getRequest()->getParam("dir");
|
||||||
|
|
||||||
$dir = MusicDir::getDirByPath($chosen);
|
$dir = MusicDir::removeWatchedDir($chosen);
|
||||||
$dir->remove();
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
$data["directory"] = $chosen;
|
|
||||||
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
|
|
||||||
|
|
||||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||||
$this->view->subform = $watched_dirs_form->render();
|
$this->view->subform = $watched_dirs_form->render();
|
||||||
|
|
|
@ -45,6 +45,9 @@ class MusicDir {
|
||||||
|
|
||||||
public static function addDir($p_path, $p_type)
|
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 = new CcMusicDirs();
|
||||||
$dir->setType($p_type);
|
$dir->setType($p_type);
|
||||||
$p_path = realpath($p_path)."/";
|
$p_path = realpath($p_path)."/";
|
||||||
|
@ -55,14 +58,20 @@ class MusicDir {
|
||||||
}
|
}
|
||||||
catch(Exception $e){
|
catch(Exception $e){
|
||||||
//echo $e->getMessage();
|
//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)
|
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)
|
public static function getDirByPK($pk)
|
||||||
|
@ -118,15 +127,23 @@ class MusicDir {
|
||||||
|
|
||||||
public static function setStorDir($p_dir)
|
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();
|
$dir = self::getStorDir();
|
||||||
// if $p_dir doesn't exist in DB
|
// if $p_dir doesn't exist in DB
|
||||||
$p_dir = realpath($p_dir)."/";
|
$p_dir = realpath($p_dir)."/";
|
||||||
$exist = $dir->getDirByPath($p_dir);
|
$exist = $dir->getDirByPath($p_dir);
|
||||||
if($exist == NULL){
|
if($exist == NULL){
|
||||||
$dir->setDirectory($p_dir);
|
$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);
|
return array("code"=>0);
|
||||||
}else{
|
}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)."/";
|
$p_dir = realpath($p_dir)."/";
|
||||||
$dir = MusicDir::getDirByPath($p_dir);
|
$dir = MusicDir::getDirByPath($p_dir);
|
||||||
if($dir == NULL){
|
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{
|
}else{
|
||||||
$dir->remove();
|
$dir->remove();
|
||||||
|
$data = array();
|
||||||
|
$data["directory"] = $p_dir;
|
||||||
|
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
|
||||||
return array("code"=>0);
|
return array("code"=>0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue