Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
artonge committed Feb 19, 2025
commit 4561a0a870eae144ce337b466e4c5e42c356f5f3
14 changes: 14 additions & 0 deletions apps/files_versions/lib/Expiration.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ public function isExpired(int $timestamp, bool $quotaExceeded = false): bool {
return $isOlderThanMax || $isMinReached;
}

/**
* 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
*
Expand Down
10 changes: 9 additions & 1 deletion apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,15 @@ protected static function getExpireList($time, $versions, $quotaExceeded = false
$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
Expand Down
Loading