diff --git a/apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php b/apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php index 0bc6b37c35b95..405d9b6396eda 100644 --- a/apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php +++ b/apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php @@ -8,7 +8,7 @@ */ namespace OCA\Files_Trashbin\Events; -use Exception; +use OCP\Exceptions\AbortedEventException; use OCP\Files\Events\Node\AbstractNodesEvent; use OCP\Files\Node; @@ -25,15 +25,10 @@ public function __construct( } /** - * @return never + * @since 28.0.0 + * @deprecated 29.0.0 - use OCP\Exceptions\AbortedEventException instead */ public function abortOperation(?\Throwable $ex = null) { - $this->stopPropagation(); - $this->run = false; - if ($ex !== null) { - throw $ex; - } else { - throw new Exception('Operation aborted'); - } + throw new AbortedEventException($ex?->getMessage() ?? 'Operation aborted'); } } diff --git a/apps/files_trashbin/lib/Listeners/SyncLivePhotosListener.php b/apps/files_trashbin/lib/Listeners/SyncLivePhotosListener.php index 2cb3a94aa1dc8..decd34fbdd5d7 100644 --- a/apps/files_trashbin/lib/Listeners/SyncLivePhotosListener.php +++ b/apps/files_trashbin/lib/Listeners/SyncLivePhotosListener.php @@ -14,10 +14,9 @@ use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Exceptions\AbortedEventException; use OCP\Files\Folder; use OCP\Files\Node; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; use OCP\IUserSession; /** @@ -76,7 +75,7 @@ private function handleRestore(BeforeNodeRestoredEvent $event, Node $peerFile): unset($this->pendingRestores[$peerFile->getId()]); return; } else { - $event->abortOperation(new NotPermittedException('Cannot restore the video part of a live photo')); + throw new AbortedEventException('Cannot restore the video part of a live photo'); } } else { $user = $this->userSession?->getUser(); @@ -94,14 +93,14 @@ private function handleRestore(BeforeNodeRestoredEvent $event, Node $peerFile): $trashItem = $this->getTrashItem($trashRoot, $peerFile->getInternalPath()); if ($trashItem === null) { - $event->abortOperation(new NotFoundException("Couldn't find peer file in trashbin")); + throw new AbortedEventException('Could not find peer file in trashbin'); } $this->pendingRestores[$sourceFile->getId()] = true; try { $this->trashManager->restoreItem($trashItem); } catch (\Throwable $ex) { - $event->abortOperation($ex); + throw new AbortedEventException($ex->getMessage()); } } } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index d578e14238672..ea9d7496c5bbb 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -29,6 +29,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; +use OCP\Exceptions\AbortedEventException; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\Files\File; use OCP\Files\Folder; @@ -515,7 +516,11 @@ public static function restore($file, $filename, $timestamp) { $run = true; $event = new BeforeNodeRestoredEvent($sourceNode, $targetNode, $run); $dispatcher = Server::get(IEventDispatcher::class); - $dispatcher->dispatchTyped($event); + try { + $dispatcher->dispatchTyped($event); + } catch (AbortedEventException) { + $run = false; + } if (!$run) { return false;