diff --git a/lib/Versions/ExpireManager.php b/lib/Versions/ExpireManager.php index 02c9f19d4..e0d65d978 100644 --- a/lib/Versions/ExpireManager.php +++ b/lib/Versions/ExpireManager.php @@ -41,9 +41,8 @@ public function __construct(Expiration $expiration) { /** * Get list of files we want to expire * - * @param integer $time - * @param IVersion[] $versions - * @return IVersion[] + * @param GroupVersion[] $versions + * @return GroupVersion[] */ protected function getAutoExpireList(int $time, array $versions): array { if (!$versions) { @@ -51,8 +50,13 @@ protected function getAutoExpireList(int $time, array $versions): array { } $toDelete = []; // versions we want to delete - // ensure the versions are sorted newest first - usort($versions, function (IVersion $a, IVersion $b) { + // 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(); }); @@ -64,7 +68,6 @@ protected function getAutoExpireList(int $time, array $versions): array { $nextInterval = $time - self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; } - /** @var IVersion $firstVersion */ $firstVersion = array_shift($versions); $prevTimestamp = $firstVersion->getTimestamp(); $nextVersion = $firstVersion->getTimestamp() - $step; @@ -75,7 +78,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; } @@ -118,9 +121,9 @@ public function getExpiredVersion(array $versions, int $time, bool $quotaExceede ($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId()); }); - $expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded) { + $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; }