Skip to content

Commit 0771906

Browse files
committed
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 c71bc06 commit 0771906

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

apps/files_versions/lib/Expiration.php

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

101+
/**
102+
* Get minimal retention obligation as a timestamp
103+
*
104+
* @return int|false
105+
*/
106+
public function getMinAgeAsTimestamp() {
107+
$minAge = false;
108+
if ($this->isEnabled() && $this->minAge !== self::NO_OBLIGATION) {
109+
$time = $this->timeFactory->getTime();
110+
$minAge = $time - ($this->minAge * 86400);
111+
}
112+
return $minAge;
113+
}
114+
101115
/**
102116
* Get maximal retention obligation as a timestamp
103117
*

apps/files_versions/lib/Storage.php

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

698698
if ($expiration->shouldAutoExpire()) {
699-
[$toDelete, $size] = self::getAutoExpireList($time, $versions);
699+
// Exclude versions that are newer than the minimum age from the auto expiration logic.
700+
$minAge = $expiration->getMinAgeAsTimestamp();
701+
if ($minAge !== false) {
702+
$versionsToAutoExpire = array_filter($versions, fn ($version) => $version['version'] < $minAge);
703+
} else {
704+
$versionsToAutoExpire = $versions;
705+
}
706+
707+
[$toDelete, $size] = self::getAutoExpireList($time, $versionsToAutoExpire);
700708
} else {
701709
$size = 0;
702710
$toDelete = []; // versions we want to delete

0 commit comments

Comments
 (0)