private static function isPhoto($filename) {
OC_Log::write(self::$APP_TAG, "Checking file ".$filename." with mimetype ".OC_Filesystem::getMimeType($filename), OC_Log::DEBUG);
if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
- return 1;
- return 0;
+ return true;
+ return false;
+ }
+
+ private static function directoryContainsPhotos($dirpath) {
+ $dirhandle = opendir(OC::$CONFIG_DATADIRECTORY.$dirpath);
+ if ($dirhandle != FALSE) {
+ while (($filename = readdir($dirhandle)) != FALSE) {
+ if ($filename[0] == '.') continue;
+ if (self::isPhoto($dirpath.'/'.$filename)) return true;
+ }
+ }
+ return false;
}
private static function createAlbum($path) {
}
public static function renamePhoto($params) {
- $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
- $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
- if ($olddir == '') $olddir = '/';
- if ($newdir == '') $newdir = '/';
- if (!self::isPhoto($params['newpath'])) return;
- OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
- $album;
- $newAlbumId;
- $oldAlbumId;
- if ($olddir == $newdir) {
- // album changing is not needed
- $album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
- if ($album->numRows() == 0) {
- $album = self::createAlbum($newdir);
- }
- $album = $album->fetchRow();
- $newAlbumId = $oldAlbumId = $album['album_id'];
- } else {
- $newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
- $oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
-
- if ($newalbum->numRows() == 0) {
- $newalbum = self::createAlbum($newdir);
- }
- $newalbum = $newalbum->fetchRow();
- if ($oldalbum->numRows() == 0) {
- OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
- return;
- }
- $oldalbum = $oldalbum->fetchRow();
- $newAlbumId = $newalbum['album_id'];
- $oldAlbumId = $oldalbum['album_id'];
+ if (OC_Filesystem::is_dir($params['newpath']) && self::directoryContainsPhotos($params['newpath'])) {
+ OC_Gallery_Album::changePath($params['oldpath'], $params['newpath'], OC_User::getUser());
+ } elseif (!self::isPhoto($params['newpath'])) {
+ $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
+ $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
+ if ($olddir == '') $olddir = '/';
+ if ($newdir == '') $newdir = '/';
+ if (!self::isPhoto($params['newpath'])) return;
+ OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
+ $album;
+ $newAlbumId;
+ $oldAlbumId;
+ if ($olddir == $newdir) {
+ // album changing is not needed
+ $album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
+ if ($album->numRows() == 0) {
+ $album = self::createAlbum($newdir);
+ }
+ $album = $album->fetchRow();
+ $newAlbumId = $oldAlbumId = $album['album_id'];
+ } else {
+ $newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
+ $oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
+
+ if ($newalbum->numRows() == 0) {
+ $newalbum = self::createAlbum($newdir);
+ }
+ $newalbum = $newalbum->fetchRow();
+ if ($oldalbum->numRows() == 0) {
+ OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
+ return;
+ }
+ $oldalbum = $oldalbum->fetchRow();
+ $newAlbumId = $newalbum['album_id'];
+ $oldAlbumId = $oldalbum['album_id'];
+ }
+ OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
}
- OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
}
}