Skip to content

Commit

Permalink
Merge pull request #3099 from nextcloud/backport/3089/stable29
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 28, 2024
2 parents d532d1d + 492f68a commit 3c189b3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace OCA\GroupFolders\Versions;

use Exception;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\Files_Versions\Versions\IDeletableVersionBackend;
use OCA\Files_Versions\Versions\IMetadataVersion;
Expand All @@ -32,6 +31,7 @@
use OCA\Files_Versions\Versions\IVersion;
use OCA\Files_Versions\Versions\IVersionBackend;
use OCA\Files_Versions\Versions\IVersionsImporterBackend;
use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\GroupFolders\Mount\MountProvider;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -66,13 +66,18 @@ public function useBackendForStorage(IStorage $storage): bool {
}

private function getFolderIdForFile(FileInfo $file): int {
$mount = $file->getMountPoint();

if (!($mount instanceof GroupMountPoint)) {
throw new Exception('Trying to get the folder id for a file not in a group folder');
$storage = $file->getStorage();
$mountPoint = $file->getMountPoint();

// getting it from the mountpoint is more efficient
if ($mountPoint instanceof GroupMountPoint) {
return $mountPoint->getFolderId();
} elseif ($storage->instanceOfStorage(GroupFolderStorage::class)) {
/** @var GroupFolderStorage $storage */
return $storage->getFolderId();
} else {
throw new \LogicException("groupfolder version backend called for non groupfolder file");
}

return $mount->getFolderId();
}

public function getVersionFolderForFile(FileInfo $file): Folder {
Expand Down Expand Up @@ -323,7 +328,7 @@ public function deleteVersion(IVersion $version): void {
return;
}

$versionsFolder = $this->getVersionsFolder($mount->getFolderId())->get((string)$sourceFile->getId());
$versionsFolder = $this->getVersionsFolder($this->getFolderIdForFile($sourceFile))->get((string)$sourceFile->getId());
/** @var Folder $versionsFolder */
$versionsFolder->get((string)$version->getRevisionId())->delete();

Expand Down

0 comments on commit 3c189b3

Please sign in to comment.