mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-22 12:15:32 +00:00
feat: add only-new command option
This commit is contained in:
parent
ff5a2d7d67
commit
ccfd7e0e89
@ -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'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user