Skip to content

Commit 31c510b

Browse files
committed
feat(search): add snapshoted latest version and date of a package
1 parent f1c5a5a commit 31c510b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

js/search.js

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ search.addWidget(
174174
<div class="col-sm-3 col-lg-2">
175175
{{#meta}}
176176
<p class="metadata">
177+
<span class="metadata-block"><i class="glyphicon glyphicon-tags"></i> {{ meta.latest_version }}</span>
178+
<span class="metadata-block"><i class="glyphicon glyphicon-calendar"></i> {{ meta.latest_date }}</span>
177179
<span class="metadata-block"><i class="glyphicon glyphicon-download"></i> {{ meta.downloads_formatted }}</span>
178180
<span class="metadata-block"><i class="glyphicon glyphicon-star"></i> {{ meta.favers_formatted }}</span>
179181
</p>

src/Command/IndexPackagesCommand.php

+8
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ private function packageToSearchableArray(Package $package, array $tags): array
233233
$record['replacementPackage'] = '';
234234
}
235235

236+
if (null !== $snapshotedLatestVersion = $package->getSnapshotedLatestVersion()) {
237+
$snapshotedLatestVersion = \exploded('&', $snapshotedLatestVersion);
238+
$record['meta'] = [
239+
'latest_version' => $snapshotedLatestVersion[0],
240+
'latest_date' => $snapshotedLatestVersion[1],
241+
];
242+
}
243+
236244
$record['tags'] = $tags;
237245

238246
return $record;

src/Entity/Package.php

+16
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ class Package
178178
*/
179179
private array|null $cachedVersions = null;
180180

181+
#[ORM\Column(type: 'string', length: 255, nullable: true)]
182+
private string|null $snapshotedLatestVersion = null;
183+
181184
public function __construct()
182185
{
183186
$this->versions = new ArrayCollection();
@@ -539,6 +542,14 @@ public function getBrowsableRepository(): string
539542
public function addVersion(Version $version): void
540543
{
541544
$this->versions[] = $version;
545+
546+
$newVersion = strtolower($version->getNormalizedVersion());
547+
548+
if (null === $this->snapshotedLatestVersion
549+
||
550+
version_compare($newVersion, $this->snapshotedLatestVersion, '>=')) {
551+
$this->snapshotedLatestVersion = $newVersion . '&' . (new \DateTime('now'))->format('Y-m-d');
552+
}
542553
}
543554

544555
/**
@@ -565,6 +576,11 @@ public function getVersion(string $normalizedVersion): Version|null
565576
return null;
566577
}
567578

579+
public function getSnapshotedLatestVersion(): ?string
580+
{
581+
return $this->snapshotedLatestVersion;
582+
}
583+
568584
public function setUpdatedAt(DateTimeInterface $updatedAt): void
569585
{
570586
$this->updatedAt = $updatedAt;

0 commit comments

Comments
 (0)