mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
feat: add notif option in app:register-domain command
This commit is contained in:
parent
1c52ad1573
commit
17a7eb9f0c
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Entity\WatchList;
|
||||||
|
use App\Message\SendDomainEventNotif;
|
||||||
use App\Repository\DomainRepository;
|
use App\Repository\DomainRepository;
|
||||||
use App\Service\RDAPService;
|
use App\Service\RDAPService;
|
||||||
|
use Random\Randomizer;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
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;
|
||||||
@ -11,6 +14,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||||||
use Symfony\Component\Console\Input\InputOption;
|
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\MessageBusInterface;
|
||||||
|
|
||||||
#[AsCommand(
|
#[AsCommand(
|
||||||
name: 'app:register-domain',
|
name: 'app:register-domain',
|
||||||
@ -21,6 +25,7 @@ class RegisterDomainCommand extends Command
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly DomainRepository $domainRepository,
|
private readonly DomainRepository $domainRepository,
|
||||||
private readonly RDAPService $rdapService,
|
private readonly RDAPService $rdapService,
|
||||||
|
private readonly MessageBusInterface $bus,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -29,7 +34,8 @@ class RegisterDomainCommand extends Command
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->addArgument('domain', InputArgument::REQUIRED, 'The domain name to register')
|
->addArgument('domain', InputArgument::REQUIRED, 'The domain name to register')
|
||||||
->addOption('force', 'f', InputOption::VALUE_NEGATABLE, 'Do not check the freshness of the data and still make the query', false);
|
->addOption('force', 'f', InputOption::VALUE_NEGATABLE, 'Do not check the freshness of the data and still make the query', false)
|
||||||
|
->addOption('notif', null, InputOption::VALUE_NEGATABLE, 'Send notifications to users if a change is detected', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
@ -37,6 +43,7 @@ class RegisterDomainCommand extends Command
|
|||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$ldhName = strtolower(idn_to_ascii($input->getArgument('domain')));
|
$ldhName = strtolower(idn_to_ascii($input->getArgument('domain')));
|
||||||
$force = (bool) $input->getOption('force');
|
$force = (bool) $input->getOption('force');
|
||||||
|
$notif = (bool) $input->getOption('notif');
|
||||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
|
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -47,7 +54,19 @@ class RegisterDomainCommand extends Command
|
|||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$updatedAt = null === $domain ? new \DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||||
$this->rdapService->registerDomain($ldhName);
|
$this->rdapService->registerDomain($ldhName);
|
||||||
|
|
||||||
|
if ($notif) {
|
||||||
|
$randomizer = new Randomizer();
|
||||||
|
$watchLists = $randomizer->shuffleArray($domain->getWatchLists()->toArray());
|
||||||
|
|
||||||
|
/** @var WatchList $watchList */
|
||||||
|
foreach ($watchLists as $watchList) {
|
||||||
|
$this->bus->dispatch(new SendDomainEventNotif($watchList->getToken(), $domain->getLdhName(), $updatedAt));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$io->error($e->getMessage());
|
$io->error($e->getMessage());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user