41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Actions\Registries\CreateManagedRegistryMaintenanceOperation;
|
|
use App\Enums\RegistryType;
|
|
use App\Models\Registry;
|
|
use Illuminate\Console\Command;
|
|
|
|
class PruneManagedRegistry extends Command
|
|
{
|
|
protected $signature = 'keystone:managed-registry:prune
|
|
{registry? : Managed registry id}
|
|
{--dispatch : Dispatch the first operation step immediately}';
|
|
|
|
protected $description = 'Create managed registry manifest deletion and garbage-collection operations.';
|
|
|
|
public function handle(CreateManagedRegistryMaintenanceOperation $operations): int
|
|
{
|
|
$registries = Registry::query()
|
|
->where('type', RegistryType::MANAGED->value)
|
|
->when($this->argument('registry'), fn ($query) => $query->whereKey((int) $this->argument('registry')))
|
|
->get();
|
|
|
|
$count = 0;
|
|
|
|
foreach ($registries as $registry) {
|
|
$operation = $operations->execute($registry);
|
|
$count++;
|
|
|
|
if ($this->option('dispatch')) {
|
|
$operation->steps()->orderBy('order')->first()?->dispatchJob();
|
|
}
|
|
}
|
|
|
|
$this->info("Created {$count} managed registry maintenance operation(s).");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|