summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2025-02-19 11:55:56 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2025-02-25 15:02:08 +0000
commit25d92c4e67e356b2f7a305c0bbbe50be3984486b (patch)
tree177d3329dbfd0459e5745ddedbf162f3974b9ca3 /apps
parent662492b83af3f0559f1f71b995c4925ab80830d4 (diff)
downloadnextcloud-server-25d92c4e67e356b2f7a305c0bbbe50be3984486b.tar.gz
nextcloud-server-25d92c4e67e356b2f7a305c0bbbe50be3984486b.zip
fix(files_versions): Do not expire versions newer than min agebackport/50903/stable29
The auto expire logic does not take into account the min retention age set by the admin. So versions were eagerly deleted. Fix https://github.com/nextcloud/server/issues/19791 Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_versions/lib/Expiration.php14
-rw-r--r--apps/files_versions/lib/Storage.php10
2 files changed, 23 insertions, 1 deletions
diff --git a/apps/files_versions/lib/Expiration.php b/apps/files_versions/lib/Expiration.php
index f18a577d80e..ba7eb3139a7 100644
--- a/apps/files_versions/lib/Expiration.php
+++ b/apps/files_versions/lib/Expiration.php
@@ -121,6 +121,20 @@ class Expiration {
}
/**
+ * Get minimal retention obligation as a timestamp
+ *
+ * @return int|false
+ */
+ public function getMinAgeAsTimestamp() {
+ $minAge = false;
+ if ($this->isEnabled() && $this->minAge !== self::NO_OBLIGATION) {
+ $time = $this->timeFactory->getTime();
+ $minAge = $time - ($this->minAge * 86400);
+ }
+ return $minAge;
+ }
+
+ /**
* Get maximal retention obligation as a timestamp
*
* @return int|false
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 48513675d63..3ef297a6046 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -726,7 +726,15 @@ class Storage {
$expiration = self::getExpiration();
if ($expiration->shouldAutoExpire()) {
- [$toDelete, $size] = self::getAutoExpireList($time, $versions);
+ // Exclude versions that are newer than the minimum age from the auto expiration logic.
+ $minAge = $expiration->getMinAgeAsTimestamp();
+ if ($minAge !== false) {
+ $versionsToAutoExpire = array_filter($versions, fn ($version) => $version['version'] < $minAge);
+ } else {
+ $versionsToAutoExpire = $versions;
+ }
+
+ [$toDelete, $size] = self::getAutoExpireList($time, $versionsToAutoExpire);
} else {
$size = 0;
$toDelete = []; // versions we want to delete