summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2022-11-28 16:18:06 +0100
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>2023-01-26 10:12:23 +0000
commitad469969bf48e0997096878042e3f03228f8f833 (patch)
tree01e47cd0e7c1002042521a465a8317c366b3fb58 /apps
parent1adc9d2aabeb773c291f718f508a15ecfb1c4d85 (diff)
downloadnextcloud-server-ad469969bf48e0997096878042e3f03228f8f833.tar.gz
nextcloud-server-ad469969bf48e0997096878042e3f03228f8f833.zip
Prevent expiration of named versions
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_versions/lib/Storage.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 2f56397ebb8..2fd208cd364 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -49,6 +49,7 @@ 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\Db\VersionsMapper;
use OCA\Files_Versions\Events\CreateVersionEvent;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\FileInfo;
@@ -573,19 +574,39 @@ class Storage {
[]
));
+ /** @var VersionsMapper $versionsMapper */
+ $versionsMapper = \OC::$server->get(VersionsMapper::class);
+ $userFolder = $root->getUserFolder($uid);
+ $versionEntities = [];
+
/** @var Node[] $versions */
- $versions = array_filter($allVersions, function (Node $info) use ($threshold) {
+ $versions = array_filter($allVersions, function (Node $info) use ($threshold, $userFolder, $versionsMapper, $versionsRoot, &$versionEntities) {
+ // Check that the file match '*.v*'
$versionsBegin = strrpos($info->getName(), '.v');
if ($versionsBegin === false) {
return false;
}
+
$version = (int)substr($info->getName(), $versionsBegin + 2);
+
+ // Check that the version does not have a label.
+ $path = $versionsRoot->getRelativePath($info->getPath());
+ $node = $userFolder->get(substr($path, 0, -strlen('.v'.$version)));
+ $versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
+ $versionEntities[$info->getId()] = $versionEntity;
+
+ if ($versionEntity->getLabel() !== '') {
+ return false;
+ }
+
+ // Check that the version's timestamp is lower than $threshold
return $version < $threshold;
});
foreach ($versions as $version) {
$internalPath = $version->getInternalPath();
\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $internalPath, 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT]);
+ $versionsMapper->delete($versionEntities[$version->getId()]);
$version->delete();
\OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $internalPath, 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT]);
}