66 */
77namespace OCA \Files_Trashbin ;
88
9- use Exception ;
109use OC \Files \Cache \Cache ;
1110use OC \Files \Cache \CacheEntry ;
1211use OC \Files \Cache \CacheQueryBuilder ;
@@ -454,6 +453,9 @@ private static function copy(View $view, $source, $target) {
454453 */
455454 public static function restore ($ file , $ filename , $ timestamp ) {
456455 $ user = OC_User::getUser ();
456+ if (!$ user ) {
457+ throw new \Exception ('Tried to restore a file while not logged in ' );
458+ }
457459 $ view = new View ('/ ' . $ user );
458460
459461 $ location = '' ;
@@ -490,8 +492,8 @@ public static function restore($file, $filename, $timestamp) {
490492 $ sourcePath = Filesystem::normalizePath ($ file );
491493 $ targetPath = Filesystem::normalizePath ('/ ' . $ location . '/ ' . $ uniqueFilename );
492494
493- $ sourceNode = self ::getNodeForPath ($ sourcePath );
494- $ targetNode = self ::getNodeForPath ($ targetPath );
495+ $ sourceNode = self ::getNodeForPath ($ user , $ sourcePath );
496+ $ targetNode = self ::getNodeForPath ($ user , $ targetPath, ' files ' );
495497 $ run = true ;
496498 $ event = new BeforeNodeRestoredEvent ($ sourceNode , $ targetNode , $ run );
497499 $ dispatcher = \OC ::$ server ->get (IEventDispatcher::class);
@@ -511,8 +513,8 @@ public static function restore($file, $filename, $timestamp) {
511513 $ view ->chroot ($ fakeRoot );
512514 Util::emitHook ('\OCA\Files_Trashbin\Trashbin ' , 'post_restore ' , ['filePath ' => $ targetPath , 'trashPath ' => $ sourcePath ]);
513515
514- $ sourceNode = self ::getNodeForPath ($ sourcePath );
515- $ targetNode = self ::getNodeForPath ($ targetPath );
516+ $ sourceNode = self ::getNodeForPath ($ user , $ sourcePath );
517+ $ targetNode = self ::getNodeForPath ($ user , $ targetPath, ' files ' );
516518 $ event = new NodeRestoredEvent ($ sourceNode , $ targetNode );
517519 $ dispatcher = \OC ::$ server ->get (IEventDispatcher::class);
518520 $ dispatcher ->dispatchTyped ($ event );
@@ -1162,14 +1164,12 @@ private static function getNodeForPath(string $path): Node {
11621164 $ user = OC_User::getUser ();
11631165 $ rootFolder = \OC ::$ server ->get (IRootFolder::class);
11641166
1165- if ($ user !== false ) {
1166- $ userFolder = $ rootFolder ->getUserFolder ($ user );
1167- /** @var Folder */
1168- $ trashFolder = $ userFolder ->getParent ()->get ('files_trashbin/files ' );
1169- try {
1170- return $ trashFolder ->get ($ path );
1171- } catch (NotFoundException $ ex ) {
1172- }
1167+ $ userFolder = $ rootFolder ->getUserFolder ($ user );
1168+ /** @var Folder $trashFolder */
1169+ $ trashFolder = $ userFolder ->getParent ()->get ($ baseDir );
1170+ try {
1171+ return $ trashFolder ->get ($ path );
1172+ } catch (NotFoundException $ ex ) {
11731173 }
11741174
11751175 $ view = \OC ::$ server ->get (View::class);
0 commit comments