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 https://github.com/nextcloud/server/issues/19791

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/51023/head
Louis Chemineau 2025-02-19 11:55:56 +07:00 committed by backportbot[bot]
parent 662492b83a
commit 25d92c4e67
2 changed files with 23 additions and 1 deletions

@ -120,6 +120,20 @@ class Expiration {
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
*

@ -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