diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-09-27 23:22:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 23:22:58 +0200 |
commit | 2dfd59e5bf8858683638f2da9f4a443bec6d81bd (patch) | |
tree | 80b73f1e39fdf5a2adcc4fdce40f48cc9bf72989 /apps/files_versions | |
parent | 38ce082d11bde6984cb9e542a4919982c2a0786c (diff) | |
parent | 0eab20fe02ada03225eb2c01a2d87ec144fadfe7 (diff) | |
download | nextcloud-server-2dfd59e5bf8858683638f2da9f4a443bec6d81bd.tar.gz nextcloud-server-2dfd59e5bf8858683638f2da9f4a443bec6d81bd.zip |
Merge pull request #33970 from nextcloud/backport/33804/stable24
[stable24] always use the default fs owner when storing versions
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/lib/Storage.php | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 3f91e32ef95..4673b4850fa 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -46,6 +46,7 @@ use OC\Files\Search\SearchQuery; use OC_User; use OC\Files\Filesystem; use OC\Files\View; +use OCA\Files_Sharing\SharedMount; use OCA\Files_Versions\AppInfo\Application; use OCA\Files_Versions\Command\Expire; use OCA\Files_Versions\Events\CreateVersionEvent; @@ -188,33 +189,45 @@ class Storage { return false; } - [$uid, $filename] = self::getUidAndFilename($filename); + // since hook paths are always relative to the "default filesystem view" + // we always use the owner from there to get the full node + $uid = Filesystem::getView()->getOwner(''); - $files_view = new View('/'.$uid .'/files'); + /** @var IRootFolder $rootFolder */ + $rootFolder = \OC::$server->get(IRootFolder::class); + $userFolder = $rootFolder->getUserFolder($uid); $eventDispatcher = \OC::$server->get(IEventDispatcher::class); - $fileInfo = $files_view->getFileInfo($filename); - $id = $fileInfo->getId(); - $nodes = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->getById($id); - foreach ($nodes as $node) { - $event = new CreateVersionEvent($node); - $eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event); - if ($event->shouldCreateVersion() === false) { - return false; + try { + $file = $userFolder->get($filename); + } catch (NotFoundException $e) { + return false; + } + + $mount = $file->getMountPoint(); + if ($mount instanceof SharedMount) { + $ownerFolder = $rootFolder->getUserFolder($mount->getShare()->getShareOwner()); + $ownerNodes = $ownerFolder->getById($file->getId()); + if (count($ownerNodes)) { + $file = current($ownerNodes); } } // no use making versions for empty files - if ($fileInfo->getSize() === 0) { + if ($file->getSize() === 0) { + return false; + } + + $event = new CreateVersionEvent($file); + $eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event); + if ($event->shouldCreateVersion() === false) { return false; } /** @var IVersionManager $versionManager */ $versionManager = \OC::$server->get(IVersionManager::class); - $userManager = \OC::$server->get(IUserManager::class); - $user = $userManager->get($uid); - $versionManager->createVersion($user, $fileInfo); + $versionManager->createVersion($file->getOwner(), $file); } |