Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 4 additions & 9 deletions apps/files_trashbin/lib/Events/BeforeNodeRestoredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading