fix: isToBeWatchClosely function

This commit is contained in:
Maël Gangloff
2024-07-25 20:21:57 +02:00
parent d153d3af78
commit 8ede04cfa6
3 changed files with 28 additions and 27 deletions

View File

@@ -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