feat: add only-new command option

This commit is contained in:
Maël Gangloff 2025-11-01 13:59:52 +01:00
parent ff5a2d7d67
commit ccfd7e0e89
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
3 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,7 @@ use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Messenger\Exception\ExceptionInterface; use Symfony\Component\Messenger\Exception\ExceptionInterface;
@ -28,7 +29,9 @@ class BatchRegisterDomainCommand extends Command
protected function configure(): void protected function configure(): void
{ {
$this $this
->addArgument('file', InputArgument::REQUIRED, 'Path to a file containing a list of domain names'); ->addArgument('file', InputArgument::REQUIRED, 'Path to a file containing a list of domain names')
->addOption('only-new', 'on', InputOption::VALUE_NEGATABLE, 'Do not update domain names if they are already in the database', false)
;
} }
/** /**
@ -38,6 +41,7 @@ class BatchRegisterDomainCommand extends Command
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$file = $input->getArgument('file'); $file = $input->getArgument('file');
$onlyNew = (bool) $input->getOption('only-new');
if (!file_exists($file) || !is_readable($file)) { if (!file_exists($file) || !is_readable($file)) {
$io->error(sprintf('File "%s" does not exist or is not readable.', $file)); $io->error(sprintf('File "%s" does not exist or is not readable.', $file));
@ -55,7 +59,7 @@ class BatchRegisterDomainCommand extends Command
$io->title('Registering domains'); $io->title('Registering domains');
/** @var string $ldhName */ /** @var string $ldhName */
foreach ($domains as $ldhName) { foreach ($domains as $ldhName) {
$this->messageBus->dispatch(new UpdateDomain($ldhName, null), [ $this->messageBus->dispatch(new UpdateDomain($ldhName, null, $onlyNew), [
new TransportNamesStamp('rdap_low'), new TransportNamesStamp('rdap_low'),
]); ]);
} }

View File

@ -7,6 +7,7 @@ final class UpdateDomain
public function __construct( public function __construct(
public string $ldhName, public string $ldhName,
public ?string $watchlistToken, public ?string $watchlistToken,
public bool $onlyNew = false,
) { ) {
} }
} }

View File

@ -69,6 +69,14 @@ final readonly class UpdateDomainHandler
{ {
$domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]); $domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]);
if (null !== $domain && $message->onlyNew) {
$this->logger->debug('The domain name is already present in the database', [
'ldhName' => $domain->getLdhName(),
]);
return;
}
if (null === $domain) { if (null === $domain) {
$this->RDAPService->registerDomain($message->ldhName); $this->RDAPService->registerDomain($message->ldhName);