if($name=='' or $path==''){
return 0;
}
- $uid=$_SESSION['user_id'];
+ $uid=OC_User::getUser();
//check if the song is already in the database
$songId=self::getSongId($name,$artist,$album);
if($songId!=0){
+ $songInfo=self::getSong($songId);
+ self::moveSong($songInfo['song_path'],$path);
return $songId;
}else{
if(!isset(self::$queries['addsong'])){
*/
public static function getSongByPath($path){
$query=OC_DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_path = ?");
- $result=$query->execute(array($path))->fetchAll();
- if(count($result)>0){
- return $result[0]['song_id'];
+ $result=$query->execute(array($path));
+ if($row=$result->fetchRow()){
+ return $row['song_id'];
}else{
return 0;
}
}
+
+ /**
+ * set the path of a song
+ * @param string $oldPath
+ * @param string $newPath
+ */
+ public static function moveSong($oldPath,$newPath){
+ $query=OC_DB::prepare("UPDATE *PREFIX*media_songs SET song_path = ? WHERE song_path = ?");
+ $query->execute(array($newPath,$oldPath));
+ }
}
?>
\ No newline at end of file
//listen for file deletions to clean the database if a song is deleted
OC_Hook::connect('OC_Filesystem','delete','OC_MEDIA','deleteFile');
+//list for file moves to update the database
+OC_Hook::connect('OC_Filesystem','post_rename','OC_MEDIA','moveFile');
+
class OC_MEDIA{
/**
* get the sha256 hash of the password needed for ampache
$path=substr($path,1);
}
$path='/'.$path;
+ error_log("$path was updated");
OC_MEDIA_SCANNER::scanFile($path);
}
require_once 'lib_collection.php';
OC_MEDIA_COLLECTION::deleteSongByPath($path);
}
+
+ public static function moveFile($params){
+ require_once 'lib_collection.php';
+ OC_MEDIA_COLLECTION::moveSong($params['oldpath'],$params['newpath']);
+ }
}
class OC_MediaSearchProvider extends OC_Search_Provider{