diff --git a/js/search.js b/js/search.js index 45836c4a5..04e6a2094 100644 --- a/js/search.js +++ b/js/search.js @@ -174,6 +174,8 @@ search.addWidget(
{{#meta}}

+ +

diff --git a/src/Command/IndexPackagesCommand.php b/src/Command/IndexPackagesCommand.php index 2dc48b44e..b2d9c4b15 100644 --- a/src/Command/IndexPackagesCommand.php +++ b/src/Command/IndexPackagesCommand.php @@ -233,6 +233,14 @@ private function packageToSearchableArray(Package $package, array $tags): array $record['replacementPackage'] = ''; } + if (null !== $snapshotedLatestVersion = $package->getSnapshotedLatestVersion()) { + $snapshotedLatestVersion = \exploded('&', $snapshotedLatestVersion); + $record['meta'] = [ + 'latest_version' => $snapshotedLatestVersion[0], + 'latest_date' => $snapshotedLatestVersion[1], + ]; + } + $record['tags'] = $tags; return $record; diff --git a/src/Entity/Package.php b/src/Entity/Package.php index 8f718d15a..7a5ee81f1 100644 --- a/src/Entity/Package.php +++ b/src/Entity/Package.php @@ -178,6 +178,9 @@ class Package */ private array|null $cachedVersions = null; + #[ORM\Column(type: 'string', length: 255, nullable: true)] + private string|null $snapshotedLatestVersion = null; + public function __construct() { $this->versions = new ArrayCollection(); @@ -539,6 +542,18 @@ public function getBrowsableRepository(): string public function addVersion(Version $version): void { $this->versions[] = $version; + + $newVersion = strtolower($version->getNormalizedVersion()); + + if (null === $this->snapshotedLatestVersion) { + $this->snapshotedLatestVersion = $newVersion . '&' . $version->getReleasedAt()->format('Y-m-d'); + } + + $actualVersion = explode('&', $this->snapshotedLatestVersion)[0]; + + if (version_compare($newVersion, $actualVersion, '>=')) { + $this->snapshotedLatestVersion = $newVersion . '&' . $version->getReleasedAt()->format('Y-m-d') + } } /** @@ -565,6 +580,11 @@ public function getVersion(string $normalizedVersion): Version|null return null; } + public function getSnapshotedLatestVersion(): ?string + { + return $this->snapshotedLatestVersion; + } + public function setUpdatedAt(DateTimeInterface $updatedAt): void { $this->updatedAt = $updatedAt;