Skip to content

Commit

Permalink
feat(search): add snapshoted latest version and date of a package
Browse files Browse the repository at this point in the history
  • Loading branch information
94noni committed Jan 8, 2024
1 parent f1c5a5a commit f912db6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ search.addWidget(
<div class="col-sm-3 col-lg-2">
{{#meta}}
<p class="metadata">
<span class="metadata-block"><i class="glyphicon glyphicon-tags"></i> {{ meta.latest_version }}</span>
<span class="metadata-block"><i class="glyphicon glyphicon-calendar"></i> {{ meta.latest_date }}</span>
<span class="metadata-block"><i class="glyphicon glyphicon-download"></i> {{ meta.downloads_formatted }}</span>
<span class="metadata-block"><i class="glyphicon glyphicon-star"></i> {{ meta.favers_formatted }}</span>
</p>
Expand Down
8 changes: 8 additions & 0 deletions src/Command/IndexPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ private function packageToSearchableArray(Package $package, array $tags): array
$record['replacementPackage'] = '';
}

if (null !== $snapshotedLatestVersion = $package->getSnapshotedLatestVersion()) {
$snapshotedLatestVersion = \exploded('&', $snapshotedLatestVersion);

Check failure on line 237 in src/Command/IndexPackagesCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Function exploded not found.
$record['meta'] = [
'latest_version' => $snapshotedLatestVersion[1],
'latest_date' => $snapshotedLatestVersion[0],
];
}

$record['tags'] = $tags;

return $record;
Expand Down
17 changes: 17 additions & 0 deletions src/Entity/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -539,6 +542,15 @@ public function getBrowsableRepository(): string
public function addVersion(Version $version): void
{
$this->versions[] = $version;

$newVersion = strtolower($version->getNormalizedVersion());
$now = (new \DateTime('now'))->format('Y-m-d\TH:i:sP');

if (null === $this->snapshotedLatestVersion
||
version_compare($newVersion, $this->snapshotedLatestVersion, '>=')) {
$this->snapshotedLatestVersion = $newVersion . '&' . $now;
}
}

/**
Expand All @@ -565,6 +577,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;
Expand Down

0 comments on commit f912db6

Please sign in to comment.