Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f912db6

Browse files
committedJan 8, 2024
feat(search): add snapshoted latest version and date of a package
1 parent f1c5a5a commit f912db6

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-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[1],
240+
'latest_date' => $snapshotedLatestVersion[0],
241+
];
242+
}
243+
236244
$record['tags'] = $tags;
237245

238246
return $record;

‎src/Entity/Package.php

+17
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,15 @@ public function getBrowsableRepository(): string
539542
public function addVersion(Version $version): void
540543
{
541544
$this->versions[] = $version;
545+
546+
$newVersion = strtolower($version->getNormalizedVersion());
547+
$now = (new \DateTime('now'))->format('Y-m-d\TH:i:sP');
548+
549+
if (null === $this->snapshotedLatestVersion
550+
||
551+
version_compare($newVersion, $this->snapshotedLatestVersion, '>=')) {
552+
$this->snapshotedLatestVersion = $newVersion . '&' . $now;
553+
}
542554
}
543555

544556
/**
@@ -565,6 +577,11 @@ public function getVersion(string $normalizedVersion): Version|null
565577
return null;
566578
}
567579

580+
public function getSnapshotedLatestVersion(): ?string
581+
{
582+
return $this->snapshotedLatestVersion;
583+
}
584+
568585
public function setUpdatedAt(DateTimeInterface $updatedAt): void
569586
{
570587
$this->updatedAt = $updatedAt;

0 commit comments

Comments
 (0)
Please sign in to comment.