Example #1
0
 /**
  * Move this album to the location specified by $newfolder, copying all
  * metadata, subalbums, and subalbums' metadata with it.
  * @param $newfolder string the folder to move to, including the name of the current folder (possibly renamed).
  * @return int 0 on success and error indicator on failure.
  *
  */
 function move($newfolder)
 {
     return parent::move(array('folder' => $newfolder));
 }
Example #2
0
 /**
  * Moves an image to a new album and/or filename (rename).
  * Returns  0 on success and error indicator on failure.
  * @param Album $newalbum the album to move this file to. Must be a valid Album object.
  * @param string $newfilename the new file name of the image in the specified album.
  * @return int
  */
 function move($newalbum, $newfilename = null)
 {
     if (is_string($newalbum)) {
         $newalbum = newAlbum($newalbum, false);
     }
     if ($newfilename == null) {
         $newfilename = $this->filename;
     } else {
         if (getSuffix($this->filename) != getSuffix($newfilename)) {
             // that is a no-no
             return 6;
         }
     }
     if ($newalbum->getID() == $this->album->getID() && $newfilename == $this->filename) {
         // Nothing to do - moving the file to the same place.
         return 2;
     }
     $newpath = $newalbum->localpath . internalToFilesystem($newfilename);
     if (file_exists($newpath)) {
         // If the file exists, don't overwrite it.
         if (!(CASE_INSENSITIVE && strtolower($newpath) == strtolower($this->localpath))) {
             return 2;
         }
     }
     $filename = basename($this->localpath);
     @chmod($filename, 0777);
     $result = @rename($this->localpath, $newpath);
     @chmod($filename, FILE_MOD);
     clearstatcache();
     if ($result) {
         $filestomove = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*');
         foreach ($filestomove as $file) {
             if (in_array(strtolower(getSuffix($file)), $this->sidecars)) {
                 $result = $result && @rename($file, stripSuffix($newpath) . '.' . getSuffix($file));
             }
         }
         //purge the cache as it is easier than figuring out what the new cache name should be
         $filestodelete = safe_glob(SERVERCACHE . '/' . substr(dirname($this->localpath), strlen(ALBUM_FOLDER_SERVERPATH)) . '/*' . stripSuffix(basename($this->localpath)) . '*');
         foreach ($filestodelete as $file) {
             @chmod($file, 0777);
             @unlink($file);
         }
     }
     $this->localpath = $newpath;
     if ($result) {
         if (parent::move(array('filename' => $newfilename, 'albumid' => $newalbum->getID()))) {
             $this->set('mtime', filemtime($newpath));
             $this->save();
             return 0;
         }
     }
     return 1;
 }