]> source.dussan.org Git - nextcloud-server.git/commitdiff
handle gallery remove when removing dir via webinterface
authorBartek Przybylski <bart.p.pl@gmail.com>
Sat, 14 Jan 2012 13:59:18 +0000 (14:59 +0100)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sat, 14 Jan 2012 14:01:57 +0000 (15:01 +0100)
apps/gallery/lib/album.php
apps/gallery/lib/hooks_handlers.php
apps/gallery/lib/photo.php

index a708ba83ea4f92aec859c2c949270242d984f93f..6adff196071742a83f981bfc73e3b041ad3bd8c1 100644 (file)
@@ -42,6 +42,13 @@ class OC_Gallery_Album {
                $stmt = OC_DB::prepare($sql);
                return $stmt->execute($args);
        }
+
+  public static function removeByPath($path, $owner) {
+    $album = self::find($owner, null, $path);
+    $album = $album->fetchRow();
+    self::remove($owner, $album['album_name']);
+    OC_Gallery_Photo::removeByAlbumId($album['album_id']);
+  }
        
   public static function find($owner, $name=null, $path=null){
                $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
index ee17c0df7dfc81ed3e0c14e1a2f84aea4a411030..534f76896d788cb2835f1b6b7869a2f7a76922ed 100644 (file)
@@ -83,8 +83,11 @@ class OC_Gallery_Hooks_Handlers {
 
   public static function removePhoto($params) {
     $path = $params['path'];
-    if (!self::isPhoto($path)) return;
-    OC_Gallery_Photo::removeByPath($path);
+    if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
+      OC_Gallery_Album::removeByPath($path, OC_User::getUser());
+    } elseif (self::isPhoto($path)) {
+      OC_Gallery_Photo::removeByPath($path);
+    }
   }
 
   public static function renamePhoto($params) {
index 23887098e0fe87c5d2b27dc43cf933634550c0d8..14b0c4b2a070ffd22be4e07ba8b70dc8d85d62a0 100644 (file)
@@ -56,6 +56,11 @@ class OC_Gallery_Photo{
     $stmt->execute(array($id));
   }
 
+  public static function removeByAlbumId($albumid) {
+    $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE album_id = ?');
+    $stmt->execute(array($albumid));
+  }
+
   public static function changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath) {
     $stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
     $stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));