handling directory renaming and thumbnail move on gallery name chenge
This commit is contained in:
parent
a9878dca6d
commit
06388e1339
|
@ -29,6 +29,7 @@ OC_JSON::checkAppEnabled('gallery');
|
|||
function handleRename($oldname, $newname) {
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_Gallery_Album::rename($oldname, $newname, OC_User::getUser());
|
||||
OC_Gallery_Album::changeThumbnailPath($oldname, $newname);
|
||||
}
|
||||
|
||||
function handleRemove($name) {
|
||||
|
|
|
@ -58,7 +58,7 @@ function galleryRemove(albumName) {
|
|||
}
|
||||
|
||||
function galleryRename(name) {
|
||||
var result = window.prompt("Input new gallery name", "");
|
||||
var result = window.prompt("Input new gallery name", name);
|
||||
if (result) {
|
||||
if (Albums.find(result)) {
|
||||
alert("Album named '" + result + "' already exists");
|
||||
|
|
|
@ -58,6 +58,17 @@ class OC_Gallery_Album {
|
|||
return $stmt->execute($args);
|
||||
}
|
||||
|
||||
public static function changePath($oldname, $newname, $owner) {
|
||||
$stmt = OC_DB::prepare('UPDATE OR IGNORE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?');
|
||||
$stmt->execute(array($newname, $owner, $oldname));
|
||||
}
|
||||
|
||||
public static function changeThumbnailPath($oldname, $newname) {
|
||||
require_once('../../../lib/base.php');
|
||||
$thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/';
|
||||
rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -34,8 +34,19 @@ class OC_Gallery_Hooks_Handlers {
|
|||
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) {
|
||||
|
@ -77,41 +88,45 @@ class OC_Gallery_Hooks_Handlers {
|
|||
}
|
||||
|
||||
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 (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'];
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue