Skip to content

Commit

Permalink
Allow archive a package to make it not visible for composer
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Mar 2, 2024
1 parent 13b40de commit c9c0ea7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/Entity/PackageSerializedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,17 @@ public function setDisabledUpdate(?bool $flag): void
{
$this->setSerialized('disabled_update', $flag);
}

public function isArchived(): bool
{
return (bool) ($this->serializedFields['archived'] ?? false);
}

public function setArchived(?bool $flag): void
{
$this->setSerialized('archived', $flag);
if (true === $flag) {
$this->setAbandoned(true);
}
}
}
4 changes: 4 additions & 0 deletions src/Form/Type/Package/SettingsPackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('fullVisibility', CheckboxType::class, [
'required' => false,
'label' => 'Visible for all users',
])
->add('archived', CheckboxType::class, [
'required' => false,
'label' => 'Mark package as archived',
]);

if ($options['has_active_integration']) {
Expand Down
8 changes: 6 additions & 2 deletions src/Package/InMemoryDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function dumpPackage(?UserInterface $user, $package, array $versionData =
$package = $this->getPackageRepo()->findOneByName($package);
}

if (!$package instanceof Package) {
if (!$package instanceof Package || $package->isArchived()) {
return [];
}

Expand Down Expand Up @@ -143,6 +143,8 @@ private function dumpUserPackages(UserInterface $user = null, int $apiVersion =

$availablePackages = $this->getPackageRepo()->getPackageNames($allowed);
$availablePackages = $subRepo ? $subRepo->filterAllowed($availablePackages) : $availablePackages;
$availablePackages = $this->getPackageRepo()->filterByJson($availablePackages, static fn($data) => !($data['archived'] ?? false));

return [null, [], $availablePackages];
}

Expand All @@ -151,10 +153,12 @@ private function dumpUserPackages(UserInterface $user = null, int $apiVersion =
->getAllowedPackagesForUser($user) :
$this->getPackageRepo()->findAll();

$packages = array_values(array_filter($packages, static fn(Package $pkg) => !$pkg->isArchived()));

$providers = $packagesData = [];
$versionData = $this->getVersionData($packages);

$availablePackages = array_map(fn(Package $pkg) => $pkg->getName(), $packages);
$availablePackages = array_map(static fn(Package $pkg) => $pkg->getName(), $packages);
$availablePackages = $subRepo ? $subRepo->filterAllowed($availablePackages) : $availablePackages;
$keys = array_flip($availablePackages);

Expand Down
17 changes: 12 additions & 5 deletions src/Repository/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,18 @@ public function filterByJson(array $packagesIds, callable $filter): array
return [];
}

$packages = $this->getConn()->fetchAllAssociative(
"SELECT p.id, p.serialized_data FROM package p WHERE p.id IN (:ids)",
['ids' => $packagesIds],
['ids' => ArrayParameterType::INTEGER]
);
$needUseIntegerIdentifier = is_numeric(reset($packagesIds));
$packages = $needUseIntegerIdentifier ?
$this->getConn()->fetchAllAssociative(
"SELECT p.id, p.serialized_data FROM package p WHERE p.id IN (:ids)",
['ids' => $packagesIds],
['ids' => ArrayParameterType::INTEGER]
) :
$this->getConn()->fetchAllAssociative(
"SELECT p.name as id, p.serialized_data FROM package p WHERE p.name IN (:ids)",
['ids' => $packagesIds],
['ids' => ArrayParameterType::STRING]
);

$packages = PacketonUtils::buildChoices($packages, 'id', 'serialized_data');
foreach ($packagesIds as $i => $packageId) {
Expand Down
6 changes: 6 additions & 0 deletions templates/package/viewPackage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
{% endif %}
{% endif %}

{% if package.archived %}
<div class="alert alert-danger">
This package is <strong>ARCHIVED</strong> and will not be available in metadata.
</div>
{% endif %}

{% if package.abandoned %}
<div class="alert alert-danger">
This package is <strong>abandoned</strong> and no longer maintained.
Expand Down

0 comments on commit c9c0ea7

Please sign in to comment.