Example #1
0
 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) . "/";
     try {
         /* isPathValid() checks if path is a substring or a superstring of an
          * existing dir and if not, throws NestedDirectoryException */
         self::isPathValid($p_path);
         $dir->setDirectory($p_path);
         $dir->save();
         return array("code" => 0);
     } catch (NestedDirectoryException $nde) {
         $msg = $nde->getMessage();
         return array("code" => 1, "error" => "{$msg}");
     } catch (Exception $e) {
         return array("code" => 1, "error" => "'{$p_path}' is already set as the current storage dir or in the watched folders list");
     }
 }