Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2012-01-17 05:16:32 +0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2012-01-17 05:16:32 +0400
commitde165372315a0e00ae84f3104ff3ff905f942b05 (patch)
treef9b4c8df05e7ccbeb1fa4402721a40a0f7dc7135 /apps/files_sharing
parent1f35c94242b1d533f94ab911aecf0f05facebe43 (diff)
Emit hooks in OC_Share when sharing a file and forward hooks for deletion and writing of source file
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/app.php1
-rw-r--r--apps/files_sharing/lib_share.php32
2 files changed, 31 insertions, 2 deletions
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));
+ }
+ }
+
}
?>