From 0c0fb329a60a5b9892ba470e47f0a18992fbe17a Mon Sep 17 00:00:00 2001 From: Flavio Heleno Date: Fri, 25 Mar 2022 14:31:44 -0300 Subject: [PATCH] Add --resync option for packagist:get-list command --- .../Console/Packagist/GetListCommand.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Application/Console/Packagist/GetListCommand.php b/src/Application/Console/Packagist/GetListCommand.php index 4c3adbb7..e88015f3 100644 --- a/src/Application/Console/Packagist/GetListCommand.php +++ b/src/Application/Console/Packagist/GetListCommand.php @@ -3,6 +3,7 @@ namespace App\Application\Console\Packagist; +use App\Application\Message\Command\PackageDiscoveryCommand; use App\Application\Message\Event\Package\PackageCreatedEvent; use App\Application\Message\Event\Package\PackageRemovedEvent; use App\Domain\Package\Package; @@ -37,6 +38,12 @@ final class GetListCommand extends Command { protected function configure(): void { $this ->setDescription('Get the complete list of packages from a Packagist mirror') + ->addOption( + 'resync', + 'r', + InputOption::VALUE_NONE, + 'Resync the list' + ) ->addOption( 'mirror', 'm', @@ -83,6 +90,36 @@ protected function execute(InputInterface $input, OutputInterface $output): int ) ); + if ((bool)$input->getOption('resync')) { + $io->text( + sprintf( + '[%s] Running in resync mode', + date('H:i:s') + ) + ); + + foreach ($packageList as $package) { + if ($this->packageRepository->exists($package)) { + $package = $this->packageRepository->get($package); + } else { + $package = $this->packageRepository->create($package); + } + + $this->producer->sendCommand( + new PackageDiscoveryCommand($package) + ); + } + + $io->text( + sprintf( + '[%s] Done', + date('H:i:s') + ) + ); + + return Command::SUCCESS; + } + $packageCol = $this->packageRepository->all(); $packages = $packageCol->map( static function (Package $package): string {