mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add app:batch-register-domains command
This commit is contained in:
64
src/Command/BatchRegisterDomainCommand.php
Normal file
64
src/Command/BatchRegisterDomainCommand.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Message\UpdateDomain;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:batch-register-domains',
|
||||||
|
description: 'Register a domain list',
|
||||||
|
)]
|
||||||
|
class BatchRegisterDomainCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly MessageBusInterface $messageBus,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addArgument('file', InputArgument::REQUIRED, 'Path to a file containing a list of domain names');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ExceptionInterface
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
$file = $input->getArgument('file');
|
||||||
|
|
||||||
|
if (!file_exists($file) || !is_readable($file)) {
|
||||||
|
$io->error(sprintf('File "%s" does not exist or is not readable.', $file));
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
$domains = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
|
||||||
|
if (empty($domains)) {
|
||||||
|
$io->warning('The list is empty.');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->title('Registering domains');
|
||||||
|
/** @var string $ldhName */
|
||||||
|
foreach ($domains as $ldhName) {
|
||||||
|
$this->messageBus->dispatch(new UpdateDomain($ldhName, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->success(sprintf('Imported %d domain names.', count($domains)));
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ final class UpdateDomain
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $ldhName,
|
public string $ldhName,
|
||||||
public string $watchlistToken,
|
public ?string $watchlistToken,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ final readonly class UpdateDomainHandler
|
|||||||
public function __invoke(UpdateDomain $message): void
|
public function __invoke(UpdateDomain $message): void
|
||||||
{
|
{
|
||||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]);
|
$domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]);
|
||||||
|
|
||||||
|
if (null === $domain) {
|
||||||
|
$this->RDAPService->registerDomain($message->ldhName);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var ?RdapServer $rdapServer */
|
/** @var ?RdapServer $rdapServer */
|
||||||
$rdapServer = $domain->getTld()->getRdapServers()->first();
|
$rdapServer = $domain->getTld()->getRdapServers()->first();
|
||||||
if (null === $rdapServer) {
|
if (null === $rdapServer) {
|
||||||
@@ -79,6 +86,15 @@ final readonly class UpdateDomainHandler
|
|||||||
|
|
||||||
$watchlist = $this->watchlistRepository->findOneBy(['token' => $message->watchlistToken]);
|
$watchlist = $this->watchlistRepository->findOneBy(['token' => $message->watchlistToken]);
|
||||||
|
|
||||||
|
if (null === $watchlist) {
|
||||||
|
/** @var Watchlist $wl */
|
||||||
|
foreach ($domain->getWatchlists()->getIterator() as $wl) {
|
||||||
|
$this->bus->dispatch(new UpdateDomain($message->ldhName, $wl->getToken()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) {
|
if (!$this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) {
|
||||||
$this->logger->debug('The domain name is already present in the database and does not need to be updated at this time', [
|
$this->logger->debug('The domain name is already present in the database and does not need to be updated at this time', [
|
||||||
'ldhName' => $domain->getLdhName(),
|
'ldhName' => $domain->getLdhName(),
|
||||||
|
|||||||
Reference in New Issue
Block a user