aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis <louis@chmn.me>2025-02-25 17:22:16 +0100
committerGitHub <noreply@github.com>2025-02-25 17:22:16 +0100
commitff494f56dc344c790d87cae52740bd364e3b252c (patch)
treec91d2d20212aead85d71a76b381c2fdaf9cbf8fd
parent5c0af8565c3721db2f1b8bfb3c73008f3fda9f67 (diff)
parent28959970dc1693a03db1aa453df93e958da2947c (diff)
downloadnextcloud-server-ff494f56dc344c790d87cae52740bd364e3b252c.tar.gz
nextcloud-server-ff494f56dc344c790d87cae52740bd364e3b252c.zip
Merge pull request #51024 from nextcloud/backport/50903/stable30
[stable30] fix(files_versions): Do not expire versions newer than min age
-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 26088aa9838..50b9c02dc38 100644
--- a/apps/files_versions/lib/Expiration.php
+++ b/apps/files_versions/lib/Expiration.php
@@ -103,6 +103,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 cd111da3ee7..34d57416274 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -693,7 +693,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