summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2012-01-14 13:52:24 +0100
committerBartek Przybylski <bart.p.pl@gmail.com>2012-01-14 13:52:24 +0100
commit06388e13394e026c5dd70b36c1ab65238d1cc254 (patch)
tree62ff3689f9377c43c763dcd6d84f6a33c90598ca
parenta9878dca6d16258ac7ce3d1e7415b88ef30e9491 (diff)
downloadnextcloud-server-06388e13394e026c5dd70b36c1ab65238d1cc254.tar.gz
nextcloud-server-06388e13394e026c5dd70b36c1ab65238d1cc254.zip
handling directory renaming and thumbnail move on gallery name chenge
-rw-r--r--apps/gallery/ajax/galleryOp.php1
-rw-r--r--apps/gallery/js/album_cover.js2
-rw-r--r--apps/gallery/lib/album.php11
-rw-r--r--apps/gallery/lib/hooks_handlers.php85
4 files changed, 63 insertions, 36 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 0224977e633..a62f0fe3f5b 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -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) {
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index 84a89c5a91f..0009eb04e4f 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -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");
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index a94eff3acd7..a708ba83ea4 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -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');
+ }
+
}
?>
diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php
index 65f3faaeeaf..ee17c0df7df 100644
--- a/apps/gallery/lib/hooks_handlers.php
+++ b/apps/gallery/lib/hooks_handlers.php
@@ -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 ($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']);
}
}