diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 855bb173d5663..a051480859543 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -14,6 +14,7 @@ use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Sharing\SharedStorage; use OCA\ShareByMail\ShareByMailProvider; +use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\Folder; @@ -717,7 +718,7 @@ public function createShare(IShare $share) { // Pre share event $event = new Share\Events\BeforeShareCreatedEvent($share); - $this->dispatcher->dispatchTyped($event); + $this->dispatchEvent($event, 'before share created'); if ($event->isPropagationStopped() && $event->getError()) { throw new \Exception($event->getError()); } @@ -744,7 +745,7 @@ public function createShare(IShare $share) { } // Post share event - $this->dispatcher->dispatchTyped(new ShareCreatedEvent($share)); + $this->dispatchEvent(new ShareCreatedEvent($share), 'share created'); // Send email if needed if ($this->config->getSystemValueBool('sharing.enable_share_mail', true)) { @@ -934,7 +935,7 @@ public function acceptShare(IShare $share, string $recipientId): IShare { $provider->acceptShare($share, $recipientId); $event = new ShareAcceptedEvent($share); - $this->dispatcher->dispatchTyped($event); + $this->dispatchEvent($event, 'share accepted'); return $share; } @@ -1016,13 +1017,13 @@ protected function deleteChildren(IShare $share) { $provider = $this->factory->getProviderForType($share->getShareType()); foreach ($provider->getChildren($share) as $child) { - $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($child)); + $this->dispatchEvent(new BeforeShareDeletedEvent($child), 'before share deleted'); $deletedChildren = $this->deleteChildren($child); $deletedShares = array_merge($deletedShares, $deletedChildren); $provider->delete($child); - $this->dispatcher->dispatchTyped(new ShareDeletedEvent($child)); + $this->dispatchEvent(new ShareDeletedEvent($child), 'share deleted'); $deletedShares[] = $child; } @@ -1131,7 +1132,7 @@ public function deleteShare(IShare $share) { throw new \InvalidArgumentException($this->l->t('Share does not have a full ID')); } - $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($share)); + $this->dispatchEvent(new BeforeShareDeletedEvent($share), 'before share deleted'); // Get all children and delete them as well $this->deleteChildren($share); @@ -1140,7 +1141,7 @@ public function deleteShare(IShare $share) { $provider = $this->factory->getProviderForType($share->getShareType()); $provider->delete($share); - $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); + $this->dispatchEvent(new ShareDeletedEvent($share), 'share deleted'); // Promote reshares of the deleted share $this->promoteReshares($share); @@ -1162,7 +1163,7 @@ public function deleteFromSelf(IShare $share, $recipientId) { $provider->deleteFromSelf($share, $recipientId); $event = new ShareDeletedFromSelfEvent($share); - $this->dispatcher->dispatchTyped($event); + $this->dispatchEvent($event, 'leave share'); } public function restoreShare(IShare $share, string $recipientId): IShare { @@ -2063,4 +2064,12 @@ public function generateToken(): string { return $token; } + + private function dispatchEvent(Event $event, string $name): void { + try { + $this->dispatcher->dispatchTyped($event); + } catch (\Exception $e) { + $this->logger->error("Error while sending ' . $name . ' event", ['exception' => $e]); + } + } }