From: Michael Gapczynski Date: Tue, 17 Jan 2012 01:16:32 +0000 (-0500) Subject: Emit hooks in OC_Share when sharing a file and forward hooks for deletion and writing... X-Git-Tag: v3.0~38^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=de165372315a0e00ae84f3104ff3ff905f942b05;p=nextcloud-server.git Emit hooks in OC_Share when sharing a file and forward hooks for deletion and writing of source file --- diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index c175142319f..8d589ea5e2e 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -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"); diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index cde33fd1dc5..0eb0e5bf85d 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -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)); + } + } + } ?>