]> source.dussan.org Git - nextcloud-server.git/commitdiff
Emit hooks in OC_Share when sharing a file and forward hooks for deletion and writing...
authorMichael Gapczynski <GapczynskiM@gmail.com>
Tue, 17 Jan 2012 01:16:32 +0000 (20:16 -0500)
committerMichael Gapczynski <GapczynskiM@gmail.com>
Tue, 17 Jan 2012 01:16:32 +0000 (20:16 -0500)
apps/files_sharing/appinfo/app.php
apps/files_sharing/lib_share.php

index c175142319f1d41e4097a0718af2656d143f18d5..8d589ea5e2e315dd433a9d955126682b8414fc36 100644 (file)
@@ -5,6 +5,7 @@ require_once('apps/files_sharing/sharedstorage.php');
 OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
 OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem");
 OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem");
+OC_Hook::connect("OC_Filesystem", "post_write", "OC_Share", "updateItem");
 OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string"));
 OC_Util::addScript("files_sharing", "share");
 OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min");
index cde33fd1dc58fd11906f11e53bed17134854c1fd..0eb0e5bf85d5bb74563b9c08b8b1b288a90cbe8c 100644 (file)
@@ -91,6 +91,9 @@ class OC_Share {
                                // Clear the folder size cache for the 'Shared' folder
                                $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
                                $clearFolderSize->execute(array($sharedFolder));
+                               // Emit post_create and post_write hooks to notify of a new file in the user's filesystem
+                               OC_Hook::emit("OC_Filesystem", "post_create", array('path' => $target));
+                               OC_Hook::emit("OC_Filesystem", "post_write", array('path' => $target));
                        }
                }
        }
@@ -263,6 +266,18 @@ class OC_Share {
                }
        }
 
+       public static function getTarget($source) {
+               $source = self::cleanPath($source);
+               $query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ? LIMIT 1");
+               $result = $query->execute(array($source, OC_User::getUser()))->fetchAll();
+               if (count($result) > 0) {
+                       return $result[0]['target'];
+               } else {
+                       // TODO Check in folders
+                       return false;
+               }
+       }
+
        /**
         * Get the user's permissions for the item at the specified target location
         * @param $target The target location of the item
@@ -380,8 +395,13 @@ class OC_Share {
        */
        public static function deleteItem($arguments) {
                $source = "/".OC_User::getUser()."/files".self::cleanPath($arguments['path']);
-               $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?");
-               $query->execute(array(strlen($source), $source, OC_User::getUser()));
+               if ($target = self::getTarget($source)) {
+                       // Forward hook to notify of changes to target file
+                       OC_Hook::emit("OC_Filesystem", "post_delete", array('path' => $target));
+                       $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?");
+                       $query->execute(array(strlen($source), $source, OC_User::getUser()));
+               }
+               
        }
 
        /**
@@ -395,6 +415,14 @@ class OC_Share {
                $query->execute(array($oldSource, $newSource, OC_User::getUser()));
        }
 
+       public static function updateItem($arguments) {
+               $source = "/".OC_User::getUser()."/files".self::cleanPath($arguments['path']);
+               if ($target = self::getTarget($source)) {
+                       // Forward hook to notify of changes to target file
+                       OC_Hook::emit("OC_Filesystem", "post_write", array('path' => $target));
+               }
+       }
+
 }
 
 ?>