Skip to content
Draft
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
26 changes: 13 additions & 13 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down