Skip to content

Commit

Permalink
Add --resync option for packagist:get-list command
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Mar 25, 2022
1 parent 9d8dc8d commit 0c0fb32
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Application/Console/Packagist/GetListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0c0fb32

Please sign in to comment.