Skip to content

Commit

Permalink
Restore --resync option of packagist:get-list console command
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Apr 22, 2022
1 parent 590af55 commit e0bdf2e
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions src/Application/Console/Packagist/GetListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;

final class GetListCommand extends Command implements SignalableCommandInterface {
/**
* File cache lifetime (12 hour TTL)
*/
private const FILE_TIMEOUT = 43200;

protected static $defaultName = 'packagist:get-list';
private PackageRepositoryInterface $packageRepository;
private ProducerInterface $producer;
Expand All @@ -38,6 +33,12 @@ final class GetListCommand extends Command implements SignalableCommandInterface
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(
'offline',
null,
Expand Down Expand Up @@ -73,6 +74,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

$resync = (bool)$input->getOption('resync');

if ($resync) {
$io->text(
sprintf(
'[%s] Running in resync mode',
date('H:i:s')
)
);
}

$workOffline = (bool)$input->getOption('offline');

if ($workOffline) {
Expand All @@ -83,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

$this->packagist->setOffline();
$this->packagist->workOffline();
}

$mirror = $input->getOption('mirror');
Expand All @@ -108,26 +120,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

$packageCol = $this->packageRepository->all();
$packages = $packageCol->map(
static function (Package $package): string {
return $package->getName();
}
)->toArray();
$packages = [];
if ($resync === false) {
$packageCol = $this->packageRepository->all();
$packages = $packageCol->map(
static function (Package $package): string {
return $package->getName();
}
)->toArray();

$storedCount = count($packages);
$io->text(
sprintf(
'[%s] Local storage has <options=bold;fg=cyan>%s</> package(s)',
date('H:i:s'),
number_format(
$storedCount,
0,
',',
'.'
$storedCount = count($packages);
$io->text(
sprintf(
'[%s] Local storage has <options=bold;fg=cyan>%s</> package(s)',
date('H:i:s'),
number_format(
$storedCount,
0,
',',
'.'
)
)
)
);
);
}

$addList = array_diff($packageList, $packages);
$io->text(
Expand Down

0 comments on commit e0bdf2e

Please sign in to comment.