From 2441eb29258437d0ea645d4ddcdcc083f3851ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Tue, 14 Jan 2025 22:00:45 +0100 Subject: [PATCH] feat: be faster on the last day --- src/Entity/Domain.php | 54 ++++++++++++------- .../SendNotifWatchListTriggerSchedule.php | 2 +- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index a7dd11d..72429ff 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -381,22 +381,35 @@ class Domain */ public function isToBeUpdated(bool $fromUser = true): bool { - return $this->getUpdatedAt()->diff(new \DateTimeImmutable())->days >= 7 - || $this->getDeleted() - ? $fromUser - : ( - ($fromUser || ($this->getUpdatedAt() - ->diff(new \DateTimeImmutable())->h * 60 + $this->getUpdatedAt() - ->diff(new \DateTimeImmutable())->i) >= 12 - ) - && $this->isToBeWatchClosely() - ) - || ( - false == $this->getDeleted() && ( - count(array_intersect($this->getStatus(), ['auto renew period', 'client hold', 'server hold'])) > 0 - && $this->getUpdatedAt()->diff(new \DateTimeImmutable())->days >= 1 - ) - ); + $updatedAtDiff = $this->getUpdatedAt()->diff(new \DateTimeImmutable()); + + if ($updatedAtDiff->days >= 7) { + return true; + } + + if ($this->getDeleted()) { + return $fromUser; + } + + $expiresIn = $this->getExpiresInDays(); + + if (0 === $expiresIn) { + return true; + } + + $minutesDiff = $updatedAtDiff->h * 60 + $updatedAtDiff->i; + if (($minutesDiff >= 12 || $fromUser) && $this->isToBeWatchClosely()) { + return true; + } + + if ( + count(array_intersect($this->getStatus(), ['auto renew period', 'client hold', 'server hold'])) > 0 + && $updatedAtDiff->days >= 1 + ) { + return true; + } + + return false; } /** @@ -471,7 +484,7 @@ class Domain $daysToExpiration = null; if ($lastStatus) { - if (in_array('pending delete', $lastStatus->getAddStatus()) && !in_array('redemption period', $this->getStatus())) { + if (in_array('pending delete', $lastStatus->getAddStatus()) && !$this->isRedemptionPeriod()) { $daysToExpiration = self::daysBetween($now, $lastStatus->getCreatedAt()->add(new \DateInterval('P5D'))); } if (in_array('redemption period', $lastStatus->getAddStatus())) { @@ -483,7 +496,7 @@ class Domain $deletedAt = null; foreach ($this->getEvents()->getIterator() as $event) { $expiredAt = !$event->getDeleted() && 'expiration' === $event->getAction() ? $event->getDate() : $expiredAt; - $deletedAt = !$event->getDeleted() && 'deletion' === $event->getAction() && in_array('redemption period', $this->getStatus()) ? $event->getDate() : $deletedAt; + $deletedAt = !$event->getDeleted() && 'deletion' === $event->getAction() && $this->isRedemptionPeriod() ? $event->getDate() : $deletedAt; } if ($deletedAt) { @@ -499,4 +512,9 @@ class Domain return null; } + + public function isRedemptionPeriod(): bool + { + return in_array('redemption period', $this->getStatus()); + } } diff --git a/src/Scheduler/SendNotifWatchListTriggerSchedule.php b/src/Scheduler/SendNotifWatchListTriggerSchedule.php index 2c80ca3..2d90651 100644 --- a/src/Scheduler/SendNotifWatchListTriggerSchedule.php +++ b/src/Scheduler/SendNotifWatchListTriggerSchedule.php @@ -21,7 +21,7 @@ final readonly class SendNotifWatchListTriggerSchedule implements ScheduleProvid { return (new Schedule()) ->add( - RecurringMessage::every('15 minutes', new ProcessWatchListsTrigger()), + RecurringMessage::every('5 minutes', new ProcessWatchListsTrigger()), ) ->stateful($this->cache); }