From 7c3c545a4bf770b0e378a945623f3aa0dfe1a8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 6 Jan 2026 13:30:16 +0100 Subject: [PATCH] fix: Correctly filter out current version from expiration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/Versions/ExpireManager.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Versions/ExpireManager.php b/lib/Versions/ExpireManager.php index d323f7e30..161225f3c 100644 --- a/lib/Versions/ExpireManager.php +++ b/lib/Versions/ExpireManager.php @@ -39,8 +39,8 @@ public function __construct( /** * Get list of files we want to expire * - * @param IVersion[] $versions - * @return IVersion[] + * @param GroupVersion[] $versions + * @return GroupVersion[] */ protected function getAutoExpireList(int $time, array $versions): array { if (!$versions) { @@ -49,14 +49,20 @@ protected function getAutoExpireList(int $time, array $versions): array { $toDelete = []; // versions we want to delete - // ensure the versions are sorted newest first - usort($versions, fn (IVersion $a, IVersion $b): int => $b->getTimestamp() <=> $a->getTimestamp()); + // Ensure the versions are sorted current first, then newest first + usort($versions, function (GroupVersion $a, GroupVersion $b): int { + if ($a->isCurrentVersion()) { + return 1; + } elseif ($b->isCurrentVersion()) { + return -1; + } + return $b->getTimestamp() <=> $a->getTimestamp(); + }); $interval = 1; $step = self::MAX_VERSIONS_PER_INTERVAL[$interval]['step']; $nextInterval = $time - self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; - /** @var IVersion $firstVersion */ $firstVersion = array_shift($versions); $prevTimestamp = $firstVersion->getTimestamp(); $nextVersion = $firstVersion->getTimestamp() - $step; @@ -67,7 +73,7 @@ protected function getAutoExpireList(int $time, array $versions): array { if ($nextInterval === -1 || $prevTimestamp > $nextInterval) { if ($version->getTimestamp() > $nextVersion) { // Do not expire versions with a label. - if (!($version instanceof IMetadataVersion) || $version->getMetadataValue('label') === null || $version->getMetadataValue('label') === '') { + if ((!($version instanceof IMetadataVersion) || $version->getMetadataValue('label') === null || $version->getMetadataValue('label') === '') && !$version->isCurrentVersion()) { //distance between two version too small, mark to delete $toDelete[] = $version; } @@ -110,9 +116,9 @@ public function getExpiredVersion(array $versions, int $time, bool $quotaExceede $versionsLeft = array_udiff($versions, $autoExpire, fn (IVersion $a, IVersion $b): int => ($a->getRevisionId() <=> $b->getRevisionId()) * ($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId())); - $expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded): bool { + $expired = array_filter($versionsLeft, function (GroupVersion $version) use ($quotaExceeded): bool { // Do not expire current version. - if ($version->getTimestamp() === $version->getSourceFile()->getMtime()) { + if ($version->isCurrentVersion()) { return false; }