Emit hooks in OC_Share when sharing a file and forward hooks for deletion and writing of source file
This commit is contained in:
parent
1f35c94242
commit
de16537231
|
@ -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");
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue