Skip to content

Commit 25d92c4

Browse files
artongebackportbot[bot]
authored andcommitted
fix(files_versions): Do not expire versions newer than min age
The auto expire logic does not take into account the min retention age set by the admin. So versions were eagerly deleted. Fix #19791 Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 662492b commit 25d92c4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

apps/files_versions/lib/Expiration.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ public function isExpired(int $timestamp, bool $quotaExceeded = false): bool {
120120
return $isOlderThanMax || $isMinReached;
121121
}
122122

123+
/**
124+
* Get minimal retention obligation as a timestamp
125+
*
126+
* @return int|false
127+
*/
128+
public function getMinAgeAsTimestamp() {
129+
$minAge = false;
130+
if ($this->isEnabled() && $this->minAge !== self::NO_OBLIGATION) {
131+
$time = $this->timeFactory->getTime();
132+
$minAge = $time - ($this->minAge * 86400);
133+
}
134+
return $minAge;
135+
}
136+
123137
/**
124138
* Get maximal retention obligation as a timestamp
125139
*

apps/files_versions/lib/Storage.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,15 @@ protected static function getExpireList($time, $versions, $quotaExceeded = false
726726
$expiration = self::getExpiration();
727727

728728
if ($expiration->shouldAutoExpire()) {
729-
[$toDelete, $size] = self::getAutoExpireList($time, $versions);
729+
// Exclude versions that are newer than the minimum age from the auto expiration logic.
730+
$minAge = $expiration->getMinAgeAsTimestamp();
731+
if ($minAge !== false) {
732+
$versionsToAutoExpire = array_filter($versions, fn ($version) => $version['version'] < $minAge);
733+
} else {
734+
$versionsToAutoExpire = $versions;
735+
}
736+
737+
[$toDelete, $size] = self::getAutoExpireList($time, $versionsToAutoExpire);
730738
} else {
731739
$size = 0;
732740
$toDelete = []; // versions we want to delete

0 commit comments

Comments
 (0)