Merge pull request #59043 from nextcloud/jtr/chore-trashbin-drop-abortOperation-usage

chore(trashbin): deprecate abortOperation on BeforeNodeRestoredEvent / switch to AbortedEventException
pull/59207/head
Ferdinand Thiessen 2 months ago committed by GitHub
commit 2ae66ff888
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php
  2. 9
      apps/files_trashbin/lib/Listeners/SyncLivePhotosListener.php
  3. 7
      apps/files_trashbin/lib/Trashbin.php

@ -8,7 +8,7 @@ declare(strict_types=1);
*/
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 @@ class BeforeNodeRestoredEvent extends AbstractNodesEvent {
}
/**
* @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');
}
}

@ -14,10 +14,9 @@ use OCA\Files_Trashbin\Trash\ITrashItem;
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 @@ class SyncLivePhotosListener implements IEventListener {
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 @@ class SyncLivePhotosListener implements IEventListener {
$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());
}
}
}

@ -29,6 +29,7 @@ use OCP\Config\IUserConfig;
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 @@ class Trashbin implements IEventListener {
$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;

Loading…
Cancel
Save