CC-4090: Make code style PSR compliant
-run psr-cs-fixer
This commit is contained in:
parent
5661872034
commit
794cf2c845
40 changed files with 2017 additions and 1874 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
class NestedDirectoryException extends Exception { }
|
||||
|
||||
class Application_Model_MusicDir {
|
||||
|
||||
class Application_Model_MusicDir
|
||||
{
|
||||
/**
|
||||
* @holds propel database object
|
||||
*/
|
||||
|
@ -40,21 +40,25 @@ class Application_Model_MusicDir {
|
|||
$this->_dir->save();
|
||||
}
|
||||
|
||||
public function setExistsFlag($flag){
|
||||
public function setExistsFlag($flag)
|
||||
{
|
||||
$this->_dir->setExists($flag);
|
||||
$this->_dir->save();
|
||||
}
|
||||
|
||||
public function setWatchedFlag($flag){
|
||||
public function setWatchedFlag($flag)
|
||||
{
|
||||
$this->_dir->setWatched($flag);
|
||||
$this->_dir->save();
|
||||
}
|
||||
|
||||
public function getWatchedFlag(){
|
||||
public function getWatchedFlag()
|
||||
{
|
||||
return $this->_dir->getWatched();
|
||||
}
|
||||
|
||||
public function getExistsFlag(){
|
||||
public function getExistsFlag()
|
||||
{
|
||||
return $this->_dir->getExists();
|
||||
}
|
||||
|
||||
|
@ -113,8 +117,9 @@ class Application_Model_MusicDir {
|
|||
* @return boolean
|
||||
* Returns true if it is the ancestor, false otherwise.
|
||||
*/
|
||||
private static function isAncestorDir($p_dir1, $p_dir2){
|
||||
if (strlen($p_dir1) > strlen($p_dir2)){
|
||||
private static function isAncestorDir($p_dir1, $p_dir2)
|
||||
{
|
||||
if (strlen($p_dir1) > strlen($p_dir2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -130,23 +135,24 @@ class Application_Model_MusicDir {
|
|||
* The path we want to validate
|
||||
* @return void
|
||||
*/
|
||||
public static function isPathValid($p_path){
|
||||
public static function isPathValid($p_path)
|
||||
{
|
||||
$dirs = self::getWatchedDirs();
|
||||
$dirs[] = self::getStorDir();
|
||||
|
||||
foreach ($dirs as $dirObj){
|
||||
foreach ($dirs as $dirObj) {
|
||||
$dir = $dirObj->getDirectory();
|
||||
$diff = strlen($dir) - strlen($p_path);
|
||||
if ($diff == 0){
|
||||
if ($dir == $p_path){
|
||||
if ($diff == 0) {
|
||||
if ($dir == $p_path) {
|
||||
throw new NestedDirectoryException("'$p_path' is already watched.");
|
||||
}
|
||||
} else if ($diff > 0){
|
||||
if (self::isAncestorDir($p_path, $dir)){
|
||||
} elseif ($diff > 0) {
|
||||
if (self::isAncestorDir($p_path, $dir)) {
|
||||
throw new NestedDirectoryException("'$p_path' contains nested watched directory: '$dir'");
|
||||
}
|
||||
} else { /* diff < 0*/
|
||||
if (self::isAncestorDir($dir, $p_path)){
|
||||
if (self::isAncestorDir($dir, $p_path)) {
|
||||
throw new NestedDirectoryException("'$p_path' is nested within existing watched directory: '$dir'");
|
||||
}
|
||||
}
|
||||
|
@ -167,37 +173,36 @@ class Application_Model_MusicDir {
|
|||
**/
|
||||
public static function addDir($p_path, $p_type, $userAddedWatchedDir=true, $nestedWatch=false)
|
||||
{
|
||||
if(!is_dir($p_path)){
|
||||
if (!is_dir($p_path)) {
|
||||
return array("code"=>2, "error"=>"'$p_path' is not a valid directory.");
|
||||
}
|
||||
$real_path = Application_Common_OsPath::normpath($p_path)."/";
|
||||
if($real_path != "/"){
|
||||
if ($real_path != "/") {
|
||||
$p_path = $real_path;
|
||||
}
|
||||
|
||||
$exist_dir = self::getDirByPath($p_path);
|
||||
|
||||
if( $exist_dir == NULL ){
|
||||
if ($exist_dir == NULL) {
|
||||
$temp_dir = new CcMusicDirs();
|
||||
$dir = new Application_Model_MusicDir($temp_dir);
|
||||
}else{
|
||||
} else {
|
||||
$dir = $exist_dir;
|
||||
}
|
||||
|
||||
$dir->setType($p_type);
|
||||
$p_path = Application_Common_OsPath::normpath($p_path)."/";
|
||||
|
||||
|
||||
try {
|
||||
/* isPathValid() checks if path is a substring or a superstring of an
|
||||
* existing dir and if not, throws NestedDirectoryException */
|
||||
if(!$nestedWatch){
|
||||
if (!$nestedWatch) {
|
||||
self::isPathValid($p_path);
|
||||
}
|
||||
if($userAddedWatchedDir){
|
||||
if ($userAddedWatchedDir) {
|
||||
$dir->setWatchedFlag(true);
|
||||
}else{
|
||||
if($nestedWatch){
|
||||
} else {
|
||||
if ($nestedWatch) {
|
||||
$dir->setWatchedFlag(false);
|
||||
}
|
||||
$dir->setExistsFlag(true);
|
||||
|
@ -205,10 +210,11 @@ class Application_Model_MusicDir {
|
|||
$dir->setDirectory($p_path);
|
||||
|
||||
return array("code"=>0);
|
||||
} catch (NestedDirectoryException $nde){
|
||||
} catch (NestedDirectoryException $nde) {
|
||||
$msg = $nde->getMessage();
|
||||
|
||||
return array("code"=>1, "error"=>"$msg");
|
||||
} catch(Exception $e){
|
||||
} catch (Exception $e) {
|
||||
return array("code"=>1, "error"=>"'$p_path' is already set as the current storage dir or in the watched folders list");
|
||||
}
|
||||
|
||||
|
@ -228,7 +234,7 @@ class Application_Model_MusicDir {
|
|||
{
|
||||
$res = self::addDir($p_path, "watched", $userAddedWatchedDir, $nestedWatch);
|
||||
|
||||
if ($res['code'] == 0){
|
||||
if ($res['code'] == 0) {
|
||||
|
||||
//convert "linked" files (Airtime <= 1.8.2) to watched files.
|
||||
$propel_link_dir = CcMusicDirsQuery::create()
|
||||
|
@ -271,6 +277,7 @@ class Application_Model_MusicDir {
|
|||
$data["directory"] = $p_path;
|
||||
Application_Model_RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -288,11 +295,11 @@ class Application_Model_MusicDir {
|
|||
$dir = CcMusicDirsQuery::create()
|
||||
->filterByDirectory($p_path)
|
||||
->findOne();
|
||||
if($dir == NULL){
|
||||
if ($dir == NULL) {
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$mus_dir = new Application_Model_MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
}
|
||||
|
@ -309,15 +316,15 @@ class Application_Model_MusicDir {
|
|||
|
||||
$dirs = CcMusicDirsQuery::create()
|
||||
->filterByType("watched");
|
||||
if($exists !== null){
|
||||
if ($exists !== null) {
|
||||
$dirs = $dirs->filterByExists($exists);
|
||||
}
|
||||
if($watched !== null){
|
||||
if ($watched !== null) {
|
||||
$dirs = $dirs->filterByWatched($watched);
|
||||
}
|
||||
$dirs = $dirs->find();
|
||||
|
||||
foreach($dirs as $dir) {
|
||||
foreach ($dirs as $dir) {
|
||||
$result[] = new Application_Model_MusicDir($dir);
|
||||
}
|
||||
|
||||
|
@ -340,23 +347,24 @@ class Application_Model_MusicDir {
|
|||
// we want to be consistent when storing dir path.
|
||||
// path should always ends with trailing '/'
|
||||
$p_dir = Application_Common_OsPath::normpath($p_dir)."/";
|
||||
if(!is_dir($p_dir)){
|
||||
if (!is_dir($p_dir)) {
|
||||
return array("code"=>2, "error"=>"'$p_dir' is not a valid directory.");
|
||||
}else if(Application_Model_Preference::GetImportTimestamp()+10 > time()){
|
||||
} elseif (Application_Model_Preference::GetImportTimestamp()+10 > time()) {
|
||||
return array("code"=>3, "error"=>"Airtime is currently importing files. Please wait until this is complete before changing the storage directory.");
|
||||
}
|
||||
$dir = self::getStorDir();
|
||||
// if $p_dir doesn't exist in DB
|
||||
$exist = $dir->getDirByPath($p_dir);
|
||||
if($exist == NULL){
|
||||
if ($exist == NULL) {
|
||||
$dir->setDirectory($p_dir);
|
||||
$dirId = $dir->getId();
|
||||
$data = array();
|
||||
$data["directory"] = $p_dir;
|
||||
$data["dir_id"] = $dirId;
|
||||
Application_Model_RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
@ -369,10 +377,11 @@ class Application_Model_MusicDir {
|
|||
->filterByWatched(true)
|
||||
->find();
|
||||
|
||||
foreach($dirs as $dir) {
|
||||
foreach ($dirs as $dir) {
|
||||
$directory = $dir->getDirectory();
|
||||
if (substr($p_filepath, 0, strlen($directory)) === $directory) {
|
||||
$mus_dir = new Application_Model_MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
}
|
||||
|
@ -390,11 +399,11 @@ class Application_Model_MusicDir {
|
|||
* 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){
|
||||
|
||||
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 != "/"){
|
||||
if ($real_path != "/") {
|
||||
$p_dir = $real_path;
|
||||
}
|
||||
$dir = Application_Model_MusicDir::getDirByPath($p_dir);
|
||||
|
@ -405,6 +414,7 @@ class Application_Model_MusicDir {
|
|||
$data = array();
|
||||
$data["directory"] = $p_dir;
|
||||
Application_Model_RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
|
||||
|
||||
return array("code"=>0);
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +423,7 @@ class Application_Model_MusicDir {
|
|||
{
|
||||
$mus_dir = self::getWatchedDirFromFilepath($p_filepath);
|
||||
|
||||
if(is_null($mus_dir)) {
|
||||
if (is_null($mus_dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue