Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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]);
}
}
}
Loading