aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Share20/LegacyHooks.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Share20/LegacyHooks.php')
-rw-r--r--lib/private/Share20/LegacyHooks.php73
1 files changed, 27 insertions, 46 deletions
diff --git a/lib/private/Share20/LegacyHooks.php b/lib/private/Share20/LegacyHooks.php
index 688b2273384..24d07167fbd 100644
--- a/lib/private/Share20/LegacyHooks.php
+++ b/lib/private/Share20/LegacyHooks.php
@@ -29,8 +29,12 @@ namespace OC\Share20;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Share;
+use OCP\Share\Events\BeforeShareCreatedEvent;
+use OCP\Share\Events\BeforeShareDeletedEvent;
+use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\Events\ShareDeletedEvent;
+use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\Share\IShare;
-use Symfony\Component\EventDispatcher\GenericEvent;
class LegacyHooks {
/** @var IEventDispatcher */
@@ -39,62 +43,41 @@ class LegacyHooks {
public function __construct(IEventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
- $this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->preUnshare($event);
- }
+ $this->eventDispatcher->addListener(BeforeShareDeletedEvent::class, function (BeforeShareDeletedEvent $event) {
+ $this->preUnshare($event);
});
- $this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->postUnshare($event);
- }
+ $this->eventDispatcher->addListener(ShareDeletedEvent::class, function (ShareDeletedEvent $event) {
+ $this->postUnshare($event);
});
- $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->postUnshareFromSelf($event);
- }
+ $this->eventDispatcher->addListener(ShareDeletedFromSelfEvent::class, function (ShareDeletedFromSelfEvent $event) {
+ $this->postUnshareFromSelf($event);
});
- $this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->preShare($event);
- }
+ $this->eventDispatcher->addListener(BeforeShareCreatedEvent::class, function (BeforeShareCreatedEvent $event) {
+ $this->preShare($event);
});
- $this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->postShare($event);
- }
+ $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
+ $this->postShare($event);
});
}
- public function preUnshare(GenericEvent $e) {
- /** @var IShare $share */
- $share = $e->getSubject();
+ public function preUnshare(BeforeShareDeletedEvent $e) {
+ $share = $e->getShare();
$formatted = $this->formatHookParams($share);
\OC_Hook::emit(Share::class, 'pre_unshare', $formatted);
}
- public function postUnshare(GenericEvent $e) {
- /** @var IShare $share */
- $share = $e->getSubject();
+ public function postUnshare(ShareDeletedEvent $e) {
+ $share = $e->getShare();
$formatted = $this->formatHookParams($share);
-
- /** @var IShare[] $deletedShares */
- $deletedShares = $e->getArgument('deletedShares');
-
- $formattedDeletedShares = array_map(function ($share) {
- return $this->formatHookParams($share);
- }, $deletedShares);
-
- $formatted['deletedShares'] = $formattedDeletedShares;
+ $formatted['deletedShares'] = [$formatted];
\OC_Hook::emit(Share::class, 'post_unshare', $formatted);
}
- public function postUnshareFromSelf(GenericEvent $e) {
- /** @var IShare $share */
- $share = $e->getSubject();
+ public function postUnshareFromSelf(ShareDeletedFromSelfEvent $e) {
+ $share = $e->getShare();
$formatted = $this->formatHookParams($share);
$formatted['itemTarget'] = $formatted['fileTarget'];
@@ -127,9 +110,8 @@ class LegacyHooks {
return $hookParams;
}
- public function preShare(GenericEvent $e) {
- /** @var IShare $share */
- $share = $e->getSubject();
+ public function preShare(BeforeShareCreatedEvent $e) {
+ $share = $e->getShare();
// Pre share hook
$run = true;
@@ -151,16 +133,15 @@ class LegacyHooks {
\OC_Hook::emit(Share::class, 'pre_shared', $preHookData);
if ($run === false) {
- $e->setArgument('error', $error);
+ $e->setError($error);
$e->stopPropagation();
}
return $e;
}
- public function postShare(GenericEvent $e) {
- /** @var IShare $share */
- $share = $e->getSubject();
+ public function postShare(ShareCreatedEvent $e) {
+ $share = $e->getShare();
$postHookData = [
'itemType' => $share->getNode() instanceof File ? 'file' : 'folder',