summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-21 16:57:09 +0100
committerGitHub <noreply@github.com>2017-03-21 16:57:09 +0100
commit348d97dfd65f8bc6f1fcdc22476adef27db959f4 (patch)
treef4ee97836950588430a41e5ee8a342750bf051ad /lib
parent60d45ec2ccd1401e0e3e2469cd94b43c2b7e7528 (diff)
parent57fc7f60d3c86a91b82a2f675082f82724b24f8b (diff)
downloadnextcloud-server-348d97dfd65f8bc6f1fcdc22476adef27db959f4.tar.gz
nextcloud-server-348d97dfd65f8bc6f1fcdc22476adef27db959f4.zip
Merge pull request #3844 from nextcloud/unshare_event
Unshare event
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Share20/LegacyHooks.php100
-rw-r--r--lib/private/Share20/Manager.php45
4 files changed, 109 insertions, 38 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index d0d0898d0bd..d211b0792ee 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -776,6 +776,7 @@ return array(
'OC\\Share20\\Exception\\InvalidShare' => $baseDir . '/lib/private/Share20/Exception/InvalidShare.php',
'OC\\Share20\\Exception\\ProviderException' => $baseDir . '/lib/private/Share20/Exception/ProviderException.php',
'OC\\Share20\\Hooks' => $baseDir . '/lib/private/Share20/Hooks.php',
+ 'OC\\Share20\\LegacyHooks' => $baseDir . '/lib/private/Share20/LegacyHooks.php',
'OC\\Share20\\Manager' => $baseDir . '/lib/private/Share20/Manager.php',
'OC\\Share20\\ProviderFactory' => $baseDir . '/lib/private/Share20/ProviderFactory.php',
'OC\\Share20\\Share' => $baseDir . '/lib/private/Share20/Share.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 7b937bd132c..00f1e9fdf1c 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -806,6 +806,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Share20\\Exception\\InvalidShare' => __DIR__ . '/../../..' . '/lib/private/Share20/Exception/InvalidShare.php',
'OC\\Share20\\Exception\\ProviderException' => __DIR__ . '/../../..' . '/lib/private/Share20/Exception/ProviderException.php',
'OC\\Share20\\Hooks' => __DIR__ . '/../../..' . '/lib/private/Share20/Hooks.php',
+ 'OC\\Share20\\LegacyHooks' => __DIR__ . '/../../..' . '/lib/private/Share20/LegacyHooks.php',
'OC\\Share20\\Manager' => __DIR__ . '/../../..' . '/lib/private/Share20/Manager.php',
'OC\\Share20\\ProviderFactory' => __DIR__ . '/../../..' . '/lib/private/Share20/ProviderFactory.php',
'OC\\Share20\\Share' => __DIR__ . '/../../..' . '/lib/private/Share20/Share.php',
diff --git a/lib/private/Share20/LegacyHooks.php b/lib/private/Share20/LegacyHooks.php
new file mode 100644
index 00000000000..728ea78a8a6
--- /dev/null
+++ b/lib/private/Share20/LegacyHooks.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OC\Share20;
+
+use OCP\Share\IShare;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\GenericEvent;
+
+class LegacyHooks {
+ /** @var EventDispatcher */
+ private $eventDispatcher;
+
+ /**
+ * LegacyHooks constructor.
+ *
+ * @param EventDispatcher $eventDispatcher
+ */
+ public function __construct(EventDispatcher $eventDispatcher) {
+ $this->eventDispatcher = $eventDispatcher;
+
+ $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
+ $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']);
+ }
+
+ /**
+ * @param GenericEvent $e
+ */
+ public function preUnshare(GenericEvent $e) {
+ /** @var IShare $share */
+ $share = $e->getSubject();
+
+ $formatted = $this->formatHookParams($share);
+ \OC_Hook::emit('OCP\Share', 'pre_unshare', $formatted);
+ }
+
+ /**
+ * @param GenericEvent $e
+ */
+ public function postUnshare(GenericEvent $e) {
+ /** @var IShare $share */
+ $share = $e->getSubject();
+
+ $formatted = $this->formatHookParams($share);
+
+ /** @var IShare[] $deletedShares */
+ $deletedShares = $e->getArgument('deletedShares');
+
+ $formattedDeletedShares = array_map(function($share) {
+ return $this->formatHookParams($share);
+ }, $deletedShares);
+
+ $formatted['deletedShares'] = $formattedDeletedShares;
+
+ \OC_Hook::emit('OCP\Share', 'pre_unshare', $formatted);
+ }
+
+ private function formatHookParams(IShare $share) {
+ // Prepare hook
+ $shareType = $share->getShareType();
+ $sharedWith = '';
+ if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
+ $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
+ $shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
+ $sharedWith = $share->getSharedWith();
+ }
+
+ $hookParams = [
+ 'id' => $share->getId(),
+ 'itemType' => $share->getNodeType(),
+ 'itemSource' => $share->getNodeId(),
+ 'shareType' => $shareType,
+ 'shareWith' => $sharedWith,
+ 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '',
+ 'uidOwner' => $share->getSharedBy(),
+ 'fileSource' => $share->getNodeId(),
+ 'fileTarget' => $share->getTarget()
+ ];
+ return $hookParams;
+ }
+}
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index e0457bba437..a02eb9205d0 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -81,6 +81,8 @@ class Manager implements IManager {
private $sharingDisabledForUsersCache;
/** @var EventDispatcher */
private $eventDispatcher;
+ /** @var LegacyHooks */
+ private $legacyHooks;
/**
@@ -123,6 +125,7 @@ class Manager implements IManager {
$this->rootFolder = $rootFolder;
$this->eventDispatcher = $eventDispatcher;
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
+ $this->legacyHooks = new LegacyHooks($this->eventDispatcher);
}
/**
@@ -810,36 +813,8 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Share does not have a full id');
}
- $formatHookParams = function(\OCP\Share\IShare $share) {
- // Prepare hook
- $shareType = $share->getShareType();
- $sharedWith = '';
- if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $share->getSharedWith();
- } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $share->getSharedWith();
- } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
- $sharedWith = $share->getSharedWith();
- }
-
- $hookParams = [
- 'id' => $share->getId(),
- 'itemType' => $share->getNodeType(),
- 'itemSource' => $share->getNodeId(),
- 'shareType' => $shareType,
- 'shareWith' => $sharedWith,
- 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '',
- 'uidOwner' => $share->getSharedBy(),
- 'fileSource' => $share->getNodeId(),
- 'fileTarget' => $share->getTarget()
- ];
- return $hookParams;
- };
-
- $hookParams = $formatHookParams($share);
-
- // Emit pre-hook
- \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);
+ $event = new GenericEvent($share);
+ $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
// Get all children and delete them as well
$deletedShares = $this->deleteChildren($share);
@@ -851,15 +826,9 @@ class Manager implements IManager {
// All the deleted shares caused by this delete
$deletedShares[] = $share;
- //Format hook info
- $formattedDeletedShares = array_map(function($share) use ($formatHookParams) {
- return $formatHookParams($share);
- }, $deletedShares);
-
- $hookParams['deletedShares'] = $formattedDeletedShares;
-
// Emit post hook
- \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams);
+ $event->setArgument('deletedShares', $deletedShares);
+ $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
}