Skip to content

Commit 633712a

Browse files
committed
Handle empty DB while expiring versions
Version on the FS can have no equivalent in the DB if they were created before the version naming feature. This makes sure that we catch the resulting exception and proceed as usual. Fix #36541 Signed-off-by: Louis Chemineau <[email protected]>
1 parent bbd3e2b commit 633712a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

apps/files_versions/lib/Storage.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCA\Files_Versions\Db\VersionsMapper;
5353
use OCA\Files_Versions\Events\CreateVersionEvent;
5454
use OCA\Files_Versions\Versions\IVersionManager;
55+
use OCP\AppFramework\Db\DoesNotExistException;
5556
use OCP\Files\FileInfo;
5657
use OCP\Files\Folder;
5758
use OCP\Files\IRootFolder;
@@ -592,11 +593,16 @@ public static function expireOlderThanMaxForUser($uid) {
592593
// Check that the version does not have a label.
593594
$path = $versionsRoot->getRelativePath($info->getPath());
594595
$node = $userFolder->get(substr($path, 0, -strlen('.v'.$version)));
595-
$versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
596-
$versionEntities[$info->getId()] = $versionEntity;
596+
try {
597+
$versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
598+
$versionEntities[$info->getId()] = $versionEntity;
597599

598-
if ($versionEntity->getLabel() !== '') {
599-
return false;
600+
if ($versionEntity->getLabel() !== '') {
601+
return false;
602+
}
603+
} catch (DoesNotExistException $ex) {
604+
// Version on FS can have no equivalent in the DB if they were created before the version naming feature.
605+
// So we ignore DoesNotExistException.
600606
}
601607

602608
// Check that the version's timestamp is lower than $threshold

0 commit comments

Comments
 (0)