]> source.dussan.org Git - nextcloud-server.git/commitdiff
add/remove handlers
authorBartek Przybylski <bart.p.pl@gmail.com>
Tue, 1 May 2012 08:06:40 +0000 (10:06 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Tue, 1 May 2012 08:07:48 +0000 (10:07 +0200)
apps/gallery/lib/hooks_handlers.php
apps/gallery/lib/photo.php

index 2788337bbe84a657a920fe7372d17a54d7f83ce1..178d8f3da155af6ddc680c0711425bef3da2d8f6 100644 (file)
@@ -21,8 +21,8 @@
 * 
 */
 
-//OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
-//OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto");
+OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
+OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto");
 //OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, "OC_Gallery_Hooks_Handlers", "renamePhoto");
 
 require_once(OC::$CLASSPATH['OC_Gallery_Album']);
@@ -65,22 +65,37 @@ class OC_Gallery_Hooks_Handlers {
 
   public static function addPhotoFromPath($params) {
     $fullpath = $params[OC_Filesystem::signal_param_path];
+    $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath);
 
     if (!self::isPhoto($fullpath)) return;
 
-    $path = dirname($fullpath);
-    if (!self::pathInRoot($path)) return;
-    OC_Gallery_Scanner::scanDir($path, $albums);
-
+    $a = OC_Gallery_Album::find(OC_User::getUser(), null, dirname($fullpath));
+    if (!($r = $a->fetchRow())) {
+      OC_Gallery_Album::create(OC_User::getUser(), basename(dirname($fullpath)), dirname($fullpath));
+      $a = OC_Gallery_Album::find(OC_User::getUser(), null, dirname($fullpath));
+      $r = $a->fetchRow();
+    }
+    $albumId = $r['album_id'];
+    $p = OC_Gallery_Album::find($albumId, $fullpath);
+    if (!($p->fetchRow()))
+      OC_Gallery_Photo::create($albumId, $fullpath);
   }
 
   public static function removePhoto($params) {
-    $path = $params[OC_Filesystem::signal_param_path];
-    if (OC_Filesystem::is_dir($path.'/') && self::directoryContainsPhotos($path)) {
-      if(!self::pathInRoot($path)) return;
-      OC_Gallery_Album::removeByPath($path, OC_User::getUser());
-    } elseif (self::isPhoto($path)) {
-      OC_Gallery_Photo::removeByPath($path);
+    $fullpath = $params[OC_Filesystem::signal_param_path];
+    $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath);
+
+    if (OC_Filesystem::is_dir($fullpath)) {
+      OC_Gallery_Album::remove(OC_User::getUser(), null, $fullpath);
+    } elseif (self::isPhoto($fullpath)) {
+      $a = OC_Gallery_Album::find(OC_User::getUser(), null, rtrim(dirname($fullpath),'/'));
+      if (($r = $a->fetchRow())) {
+        OC_Gallery_Photo::removeByPath($fullpath, $r['album_id']);
+        $p = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $r['album_name']);
+        if (!($p->fetchRow())) {
+          OC_Gallery_Album::remove(OC_User::getUser(), null, dirname($fullpath));
+        }
+      }
     }
   }
 
index 3bb6f9129fa51184b930e167b4e8d5edacc2d885..5098e1a2ed2aa3b42dacaded8c4049ea19be8de7 100644 (file)
@@ -46,9 +46,9 @@ class OC_Gallery_Photo {
                return $stmt->execute(array($owner, $album_name));
        }
 
-       public static function removeByPath($path) {
-               $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ?');
-               $stmt->execute(array($path));
+  public static function removeByPath($path, $album_id) {
+    $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ? and album_id = ?');
+               $stmt->execute(array($path, $album_id));
        }
 
        public static function removeById($id) {