From 3940335da73d905983f6f01810488b8c91d6c337 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 4 Dec 2019 16:13:14 +0100 Subject: [PATCH] Fix restoring shared versions Signed-off-by: Roeland Jago Douma --- apps/files_versions/lib/Storage.php | 17 +++++++---------- .../lib/Versions/LegacyVersionsBackend.php | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index c42083ff352..daf610dd1d7 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -50,6 +50,7 @@ use OCA\Files_Versions\Command\Expire; use OCA\Files_Versions\Events\CreateVersionEvent; use OCA\Files_Versions\Versions\IVersionManager; use OCP\Files\NotFoundException; +use OCP\IUser; use OCP\Lock\ILockingProvider; use OCP\User; @@ -325,20 +326,16 @@ class Storage { * @param int $revision revision timestamp * @return bool */ - public static function rollback($file, $revision) { + public static function rollback(string $file, int $revision, IUser $user) { // add expected leading slash - $file = '/' . ltrim($file, '/'); - list($uid, $filename) = self::getUidAndFilename($file); - if ($uid === null || trim($filename, '/') === '') { - return false; - } + $filename = '/' . ltrim($file, '/'); // Fetch the userfolder to trigger view hooks - $userFolder = \OC::$server->getUserFolder($uid); + $userFolder = \OC::$server->getUserFolder($user->getUID()); - $users_view = new View('/'.$uid); - $files_view = new View('/'. User::getUser().'/files'); + $users_view = new View('/'.$user->getUID()); + $files_view = new View('/'. $user->getUID().'/files'); $versionCreated = false; @@ -374,7 +371,7 @@ class Storage { // rollback if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) { $files_view->touch($file, $revision); - Storage::scheduleExpire($uid, $file); + Storage::scheduleExpire($user->getUID(), $file); $node = $userFolder->get($file); diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php index 99424f54564..2594b51994e 100644 --- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php +++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php @@ -86,7 +86,7 @@ class LegacyVersionsBackend implements IVersionBackend { } public function rollback(IVersion $version) { - return Storage::rollback($version->getVersionPath(), $version->getRevisionId()); + return Storage::rollback($version->getVersionPath(), $version->getRevisionId(), $version->getUser()); } private function getVersionFolder(IUser $user): Folder { -- 2.39.5