Skip to content

Commit c3f61df

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

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-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

+20
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,18 @@ 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+
$this->snapshotedLatestVersion = $newVersion . '&' . $version->getReleasedAt()->format('Y-m-d');
550+
}
551+
552+
$actualVersion = explode('&', $this->snapshotedLatestVersion)[0];
553+
554+
if (version_compare($newVersion, $actualVersion, '>=')) {
555+
$this->snapshotedLatestVersion = $newVersion . '&' . $version->getReleasedAt()->format('Y-m-d')
556+
}
542557
}
543558

544559
/**
@@ -565,6 +580,11 @@ public function getVersion(string $normalizedVersion): Version|null
565580
return null;
566581
}
567582

583+
public function getSnapshotedLatestVersion(): ?string
584+
{
585+
return $this->snapshotedLatestVersion;
586+
}
587+
568588
public function setUpdatedAt(DateTimeInterface $updatedAt): void
569589
{
570590
$this->updatedAt = $updatedAt;

0 commit comments

Comments
 (0)