diff --git a/src/Controller/DomainRefreshController.php b/src/Controller/DomainRefreshController.php index 5c4b353..70358ab 100644 --- a/src/Controller/DomainRefreshController.php +++ b/src/Controller/DomainRefreshController.php @@ -40,17 +40,18 @@ class DomainRefreshController extends AbstractController { /** @var Domain $domain */ $domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]); - if ($domain !== null && $domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) return $domain; + + // If the domain name exists in the database, recently updated and not important, we return the stored Domain + if ($domain !== null && ($domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) && !$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())) return $domain; if (false === $kernel->isDebug()) { $limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier()); if (false === $limiter->consume()->isAccepted()) throw new TooManyRequestsHttpException(); } - if ($domain === null) return $this->RDAPService->registerDomain($ldhName); - - $updatedAt = $domain->getUpdatedAt(); + $updatedAt = $domain === null ? new DateTimeImmutable('now') : $domain->getUpdatedAt(); $domain = $this->RDAPService->registerDomain($ldhName); + /** @var WatchList $watchList */ foreach ($domain->getWatchLists()->getIterator() as $watchList) { $this->bus->dispatch(new ProcessDomainTrigger($watchList->getToken(), $domain->getLdhName(), $updatedAt)); diff --git a/src/MessageHandler/ProcessWatchListTriggerHandler.php b/src/MessageHandler/ProcessWatchListTriggerHandler.php index 3100c81..0dc8899 100644 --- a/src/MessageHandler/ProcessWatchListTriggerHandler.php +++ b/src/MessageHandler/ProcessWatchListTriggerHandler.php @@ -2,9 +2,7 @@ namespace App\MessageHandler; -use App\Config\EventAction; use App\Entity\Domain; -use App\Entity\DomainEvent; use App\Entity\User; use App\Entity\WatchList; use App\Message\ProcessDomainTrigger; @@ -25,7 +23,6 @@ use Throwable; #[AsMessageHandler] final readonly class ProcessWatchListTriggerHandler { - const IMPORTANT_EVENTS = [EventAction::Deletion->value, EventAction::Expiration->value]; public function __construct( private RDAPService $RDAPService, @@ -51,7 +48,7 @@ final readonly class ProcessWatchListTriggerHandler ->filter(fn($domain) => $domain->getUpdatedAt() ->diff( new DateTimeImmutable('now'))->days >= 7 - || self::isToBeWatchClosely($domain, $domain->getUpdatedAt()) + || $this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt()) ) as $domain ) { $updatedAt = $domain->getUpdatedAt(); @@ -66,7 +63,7 @@ final readonly class ProcessWatchListTriggerHandler /** * If the domain name must be consulted regularly, we reschedule an update in one day */ - if (self::isToBeWatchClosely($domain, $updatedAt)) { + if ($this->RDAPService::isToBeWatchClosely($domain, $updatedAt)) { $this->bus->dispatch(new ProcessWatchListTrigger($message->watchListToken), [ new DelayStamp(24 * 60 * 60 * 1e3)]); } @@ -75,22 +72,6 @@ final readonly class ProcessWatchListTriggerHandler } } - /** - * Determines if a domain name needs special attention. - * These domain names are those whose last event was expiration or deletion. - * @throws Exception - */ - public static function isToBeWatchClosely(Domain $domain, DateTimeImmutable $updatedAt): bool - { - if ($updatedAt->diff(new DateTimeImmutable('now'))->days < 1) return false; - - /** @var DomainEvent[] $events */ - $events = $domain->getEvents()->toArray(); - - usort($events, fn(DomainEvent $e1, DomainEvent $e2) => $e2->getDate() - $e1->getDate()); - - return !empty($events) && in_array($events[0]->getAction(), self::IMPORTANT_EVENTS); - } /** * @throws TransportExceptionInterface diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index efe7dab..7deb856 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -72,6 +72,8 @@ readonly class RDAPService 'xn--hlcj6aya9esc7a' ]; + const IMPORTANT_EVENTS = [EventAction::Deletion->value, EventAction::Expiration->value]; + public function __construct(private HttpClientInterface $client, private EntityRepository $entityRepository, private DomainRepository $domainRepository, @@ -88,6 +90,25 @@ readonly class RDAPService } + /** + * Determines if a domain name needs special attention. + * These domain names are those whose last event was expiration or deletion. + * @throws Exception + */ + public static function isToBeWatchClosely(Domain $domain, DateTimeImmutable $updatedAt): bool + { + if ($updatedAt->diff(new DateTimeImmutable('now'))->days < 1) return false; + + /** @var DomainEvent[] $events */ + $events = $domain->getEvents() + ->filter(fn(DomainEvent $e) => $e->getDate() <= new DateTimeImmutable('now')) + ->toArray(); + + usort($events, fn(DomainEvent $e1, DomainEvent $e2) => $e2->getDate() > $e1->getDate()); + + return !empty($events) && in_array($events[0]->getAction(), self::IMPORTANT_EVENTS); + } + /** * @throws HttpExceptionInterface * @throws TransportExceptionInterface @@ -253,7 +274,6 @@ readonly class RDAPService return $domain; } - /** * @throws Exception */ @@ -409,7 +429,6 @@ readonly class RDAPService * @throws ClientExceptionInterface * @throws DecodingExceptionInterface * @throws Exception - * @throws ORMException */ public function updateGTldListICANN(): void {