From d36a9053c4ead68622a3b9ce6cd2f68cf47c6606 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Jul 2025 17:01:49 +0200 Subject: [PATCH] fix: fix trashbin restore events Signed-off-by: Robin Appelman [skip ci] --- apps/files_trashbin/lib/Trashbin.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 3bd5ffa0d1eb3..7823eb5a19816 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -6,7 +6,6 @@ */ namespace OCA\Files_Trashbin; -use Exception; use OC\Files\Cache\Cache; use OC\Files\Cache\CacheEntry; use OC\Files\Cache\CacheQueryBuilder; @@ -454,6 +453,9 @@ private static function copy(View $view, $source, $target) { */ public static function restore($file, $filename, $timestamp) { $user = OC_User::getUser(); + if (!$user) { + throw new \Exception('Tried to restore a file while not logged in'); + } $view = new View('/' . $user); $location = ''; @@ -490,8 +492,8 @@ public static function restore($file, $filename, $timestamp) { $sourcePath = Filesystem::normalizePath($file); $targetPath = Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename); - $sourceNode = self::getNodeForPath($sourcePath); - $targetNode = self::getNodeForPath($targetPath); + $sourceNode = self::getNodeForPath($user, $sourcePath); + $targetNode = self::getNodeForPath($user, $targetPath, 'files'); $run = true; $event = new BeforeNodeRestoredEvent($sourceNode, $targetNode, $run); $dispatcher = \OC::$server->get(IEventDispatcher::class); @@ -511,8 +513,8 @@ public static function restore($file, $filename, $timestamp) { $view->chroot($fakeRoot); Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', ['filePath' => $targetPath, 'trashPath' => $sourcePath]); - $sourceNode = self::getNodeForPath($sourcePath); - $targetNode = self::getNodeForPath($targetPath); + $sourceNode = self::getNodeForPath($user, $sourcePath); + $targetNode = self::getNodeForPath($user, $targetPath, 'files'); $event = new NodeRestoredEvent($sourceNode, $targetNode); $dispatcher = \OC::$server->get(IEventDispatcher::class); $dispatcher->dispatchTyped($event); @@ -1162,14 +1164,12 @@ private static function getNodeForPath(string $path): Node { $user = OC_User::getUser(); $rootFolder = \OC::$server->get(IRootFolder::class); - if ($user !== false) { - $userFolder = $rootFolder->getUserFolder($user); - /** @var Folder */ - $trashFolder = $userFolder->getParent()->get('files_trashbin/files'); - try { - return $trashFolder->get($path); - } catch (NotFoundException $ex) { - } + $userFolder = $rootFolder->getUserFolder($user); + /** @var Folder $trashFolder */ + $trashFolder = $userFolder->getParent()->get($baseDir); + try { + return $trashFolder->get($path); + } catch (NotFoundException $ex) { } $view = \OC::$server->get(View::class);