summaryrefslogtreecommitdiffstats
path: root/lib/private/Share20/Manager.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-08-03 15:14:29 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-08-03 15:14:29 +0200
commit4633717f0494a05a921a30066e47dc71d6002129 (patch)
tree87ce72d754e3821e5fb091be1a2db1ac59c18b2e /lib/private/Share20/Manager.php
parent8fecc336ac78719777c1a11ee62c14f084b56d51 (diff)
downloadnextcloud-server-4633717f0494a05a921a30066e47dc71d6002129.tar.gz
nextcloud-server-4633717f0494a05a921a30066e47dc71d6002129.zip
Move pre_shared and post_shared events to EventDispatcher
* Now listeners for those events get proper share objects. * Legacy hooks still fired * Updated tests Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Share20/Manager.php')
-rw-r--r--lib/private/Share20/Manager.php46
1 files changed, 8 insertions, 38 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 9eee9a505ee..ad78a0db745 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -636,27 +636,11 @@ class Manager implements IManager {
$target = \OC\Files\Filesystem::normalizePath($target);
$share->setTarget($target);
- // Pre share hook
- $run = true;
- $error = '';
- $preHookData = [
- 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getNode()->getId(),
- 'shareType' => $share->getShareType(),
- 'uidOwner' => $share->getSharedBy(),
- 'permissions' => $share->getPermissions(),
- 'fileSource' => $share->getNode()->getId(),
- 'expiration' => $share->getExpirationDate(),
- 'token' => $share->getToken(),
- 'itemTarget' => $share->getTarget(),
- 'shareWith' => $share->getSharedWith(),
- 'run' => &$run,
- 'error' => &$error,
- ];
- \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
-
- if ($run === false) {
- throw new \Exception($error);
+ // Pre share event
+ $event = new GenericEvent($share);
+ $a = $this->eventDispatcher->dispatch('OCP\Share::preShare', $event);
+ if ($event->isPropagationStopped() && $event->hasArgument('error')) {
+ throw new \Exception($event->getArgument('error'));
}
$oldShare = $share;
@@ -665,23 +649,9 @@ class Manager implements IManager {
//reuse the node we already have
$share->setNode($oldShare->getNode());
- // Post share hook
- $postHookData = [
- 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getNode()->getId(),
- 'shareType' => $share->getShareType(),
- 'uidOwner' => $share->getSharedBy(),
- 'permissions' => $share->getPermissions(),
- 'fileSource' => $share->getNode()->getId(),
- 'expiration' => $share->getExpirationDate(),
- 'token' => $share->getToken(),
- 'id' => $share->getId(),
- 'shareWith' => $share->getSharedWith(),
- 'itemTarget' => $share->getTarget(),
- 'fileTarget' => $share->getTarget(),
- ];
-
- \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
+ // Post share event
+ $event = new GenericEvent($share);
+ $this->eventDispatcher->dispatch('OCP\Share::postShare', $event);
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$user = $this->userManager->get($share->getSharedWith());