diff --git a/php/access/Admin.php b/php/access/Admin.php index d7705cc..2ce9122 100644 --- a/php/access/Admin.php +++ b/php/access/Admin.php @@ -22,6 +22,7 @@ class Admin extends Access { case 'Album::setDescription': $this->setAlbumDescription(); break; case 'Album::setPublic': $this->setAlbumPublic(); break; case 'Album::delete': $this->deleteAlbum(); break; + case 'Album::merge': $this->mergeAlbums(); break; # Photo functions case 'Photo::get': $this->getPhoto(); break; @@ -123,6 +124,12 @@ class Admin extends Access { } + private function mergeAlbums() { + Module::dependencies(isset($_POST['albumIDs'])); + $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']); + echo $album->merge(); + } + # Photo functions private function getPhoto() { diff --git a/php/modules/Album.php b/php/modules/Album.php index 645eb9d..c8eb572 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -715,6 +715,40 @@ class Album extends Module { } + public function merge() { + + # Check dependencies + self::dependencies(isset($this->database, $this->albumIDs)); + + # Call plugins + $this->plugins(__METHOD__, 0, func_get_args()); + + $albumID = reset($this->albumIDs); + $mergable_albumIDs = array_slice($this->albumIDs, 1); + + $inQuery = implode(',', array_fill(0, count($this->albumIDs) - 1, '?')); + $data = array(LYCHEE_TABLE_PHOTOS, $albumID) + $mergable_albumIDs; + + $merge_query = Database::prepare($this->database, "UPDATE ? SET album = ? WHERE album IN ($inQuery)", $data); + $merge_result = $this->database->query($merge_query); + + if (!$merge_result) { + Log::error($this->database, __METHOD__, __LINE__, $this->database->error); + return false; + } + + $data = array(LYCHEE_TABLE_ALBUMS) + $mergable_albumIDs; + $delete_query = Database::prepare($this->database, "DELETE FROM ? WHERE id IN ($inQuery)", $data); + $delete_result = $this->database->query($delete_query); + + if (!$delete_result) { + Log::error($this->database, __METHOD__, __LINE__, $this->database->error); + return false; + } + + return true; + } + } ?> \ No newline at end of file diff --git a/src/scripts/album.js b/src/scripts/album.js index 5eac22b..cf0967c 100644 --- a/src/scripts/album.js +++ b/src/scripts/album.js @@ -567,4 +567,14 @@ album.getArchive = function(albumID) { location.href = link; +} + +album.merge = function(albumIDs) { + var params = { + albumIDs: albumIDs.join() + } + + api.post('Album::merge', params, function(data) { + if (data!==true) lychee.error(null, params, data); + }) } \ No newline at end of file diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index 3bf612d..07ae17f 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -61,6 +61,7 @@ contextMenu.albumMulti = function(albumIDs, e) { multiselect.stopResize(); var items = [ + { type: 'item', title: 'Merge All', fn: function () { album.merge(albumIDs) } }, { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } }, { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } } ];