summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2023-03-10 17:10:06 +0100
committerJulius Härtl <jus@bitgrid.net>2023-03-13 10:52:37 +0100
commit62e6a32899dcd079b1ff3623d7363241892011ca (patch)
treefc4ed3e204c2a8602ca991c91914c258b7410b40 /apps/files_versions
parentc22d51c1ad939e1bf2a2b78f8fb3329a5269c9e7 (diff)
downloadnextcloud-server-62e6a32899dcd079b1ff3623d7363241892011ca.tar.gz
nextcloud-server-62e6a32899dcd079b1ff3623d7363241892011ca.zip
don't re-get fileinfo for versioned file if it's not shared
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/Versions/LegacyVersionsBackend.php30
-rw-r--r--apps/files_versions/tests/VersioningTest.php1
2 files changed, 17 insertions, 14 deletions
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
index cbfbc001e0c..0ad0eb8a439 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -69,13 +69,17 @@ class LegacyVersionsBackend implements IVersionBackend, INameableVersionBackend,
if ($storage->instanceOfStorage(SharedStorage::class)) {
$owner = $storage->getOwner('');
$user = $this->userManager->get($owner);
- }
- $userFolder = $this->rootFolder->getUserFolder($user->getUID());
- $nodes = $userFolder->getById($file->getId());
- $file2 = array_pop($nodes);
+ $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $nodes = $userFolder->getById($file->getId());
+ $file = array_pop($nodes);
+
+ if (!$file) {
+ throw new NotFoundException("version file not found for share owner");
+ }
+ }
- $versions = $this->getVersionsForFileFromDB($file2, $user);
+ $versions = $this->getVersionsForFileFromDB($file, $user);
if (count($versions) > 0) {
return $versions;
@@ -83,18 +87,18 @@ class LegacyVersionsBackend implements IVersionBackend, INameableVersionBackend,
// Insert the entry in the DB for the current version.
$versionEntity = new VersionEntity();
- $versionEntity->setFileId($file2->getId());
- $versionEntity->setTimestamp($file2->getMTime());
- $versionEntity->setSize($file2->getSize());
- $versionEntity->setMimetype($this->mimeTypeLoader->getId($file2->getMimetype()));
+ $versionEntity->setFileId($file->getId());
+ $versionEntity->setTimestamp($file->getMTime());
+ $versionEntity->setSize($file->getSize());
+ $versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setMetadata([]);
$this->versionsMapper->insert($versionEntity);
// Insert entries in the DB for existing versions.
- $versionsOnFS = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file2->getPath()));
+ $versionsOnFS = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file->getPath()));
foreach ($versionsOnFS as $version) {
$versionEntity = new VersionEntity();
- $versionEntity->setFileId($file2->getId());
+ $versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp((int)$version['version']);
$versionEntity->setSize((int)$version['size']);
$versionEntity->setMimetype($this->mimeTypeLoader->getId($version['mimetype']));
@@ -102,13 +106,13 @@ class LegacyVersionsBackend implements IVersionBackend, INameableVersionBackend,
$this->versionsMapper->insert($versionEntity);
}
- return $this->getVersionsForFileFromDB($file2, $user);
+ return $this->getVersionsForFileFromDB($file, $user);
}
/**
* @return IVersion[]
*/
- private function getVersionsForFileFromDB(Node $file, IUser $user): array {
+ private function getVersionsForFileFromDB(FileInfo $file, IUser $user): array {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
return array_map(
diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php
index 547f1eca4a6..f454ba30b86 100644
--- a/apps/files_versions/tests/VersioningTest.php
+++ b/apps/files_versions/tests/VersioningTest.php
@@ -662,7 +662,6 @@ class VersioningTest extends \Test\TestCase {
public function testRestoreCrossStorage() {
$storage2 = new Temporary([]);
\OC\Files\Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub');
- \OC\Files\Filesystem::tearDown();
$this->doTestRestore();
}