mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-23 12:45:36 +00:00
feat: add SendNotifWatchListTrigger Message
This commit is contained in:
parent
86aa1d2f3f
commit
17a1cc2938
@ -1,7 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import * as ReactDOM from 'react-dom/client';
|
|
||||||
|
|
||||||
const rootElement = document.getElementById('root');
|
|
||||||
const root = ReactDOM.createRoot(rootElement!);
|
|
||||||
|
|
||||||
root.render(<></>)
|
|
||||||
@ -25,6 +25,7 @@ framework:
|
|||||||
Symfony\Component\Notifier\Message\ChatMessage: async
|
Symfony\Component\Notifier\Message\ChatMessage: async
|
||||||
Symfony\Component\Notifier\Message\SmsMessage: async
|
Symfony\Component\Notifier\Message\SmsMessage: async
|
||||||
App\Message\UpdateRdapServers: async
|
App\Message\UpdateRdapServers: async
|
||||||
|
App\Message\SendNotifWatchListTrigger: async
|
||||||
|
|
||||||
# Route your messages to the transports
|
# Route your messages to the transports
|
||||||
# 'App\Message\YourMessage': async
|
# 'App\Message\YourMessage': async
|
||||||
|
|||||||
16
src/Message/SendNotifWatchListTrigger.php
Normal file
16
src/Message/SendNotifWatchListTrigger.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Message;
|
||||||
|
|
||||||
|
final class SendNotifWatchListTrigger
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Add whatever properties and methods you need
|
||||||
|
* to hold the data for this message class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// public function __construct(
|
||||||
|
// public readonly string $name,
|
||||||
|
// ) {
|
||||||
|
// }
|
||||||
|
}
|
||||||
68
src/MessageHandler/SendNotifWatchListTriggerHandler.php
Normal file
68
src/MessageHandler/SendNotifWatchListTriggerHandler.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\MessageHandler;
|
||||||
|
|
||||||
|
use App\Config\TriggerAction;
|
||||||
|
use App\Entity\Domain;
|
||||||
|
use App\Entity\DomainEvent;
|
||||||
|
use App\Entity\WatchList;
|
||||||
|
use App\Entity\WatchListTrigger;
|
||||||
|
use App\Message\SendNotifWatchListTrigger;
|
||||||
|
use App\Repository\WatchListRepository;
|
||||||
|
use App\Service\RDAPService;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Exception;
|
||||||
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
#[AsMessageHandler]
|
||||||
|
final class SendNotifWatchListTriggerHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private WatchListRepository $watchListRepository,
|
||||||
|
private RDAPService $RDAPService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __invoke(SendNotifWatchListTrigger $message): void
|
||||||
|
{
|
||||||
|
/** @var WatchList $watchList */
|
||||||
|
foreach ($this->watchListRepository->findAll() as $watchList) {
|
||||||
|
|
||||||
|
/** @var Domain $domain */
|
||||||
|
foreach ($watchList->getDomains()
|
||||||
|
->filter(fn($domain) => $domain->getUpdatedAt()
|
||||||
|
->diff(new DateTimeImmutable('now'))->days >= 7) as $domain
|
||||||
|
) {
|
||||||
|
$updatedAt = $domain->getUpdatedAt();
|
||||||
|
try {
|
||||||
|
$domain = $this->RDAPService->registerDomain($domain->getLdhName());
|
||||||
|
} catch (Throwable) {
|
||||||
|
|
||||||
|
}
|
||||||
|
/** @var DomainEvent $event */
|
||||||
|
foreach ($domain->getEvents()->filter(fn($event) => $updatedAt < $event->getDate()) as $event) {
|
||||||
|
|
||||||
|
$watchListTriggers = $watchList->getWatchListTriggers()
|
||||||
|
->filter(fn($trigger) => $trigger->getAction() === $event->getAction());
|
||||||
|
|
||||||
|
/** @var WatchListTrigger $watchListTrigger */
|
||||||
|
foreach ($watchListTriggers->getIterator() as $watchListTrigger) {
|
||||||
|
|
||||||
|
switch ($watchListTrigger->getAction()) {
|
||||||
|
case TriggerAction::SendEmail:
|
||||||
|
//TODO: To be implemented
|
||||||
|
throw new Exception('To be implemented');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Scheduler/SendNotifWatchListTriggerSchedule.php
Normal file
29
src/Scheduler/SendNotifWatchListTriggerSchedule.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Scheduler;
|
||||||
|
|
||||||
|
use App\Message\SendNotifWatchListTrigger;
|
||||||
|
use Symfony\Component\Scheduler\Attribute\AsSchedule;
|
||||||
|
use Symfony\Component\Scheduler\RecurringMessage;
|
||||||
|
use Symfony\Component\Scheduler\Schedule;
|
||||||
|
use Symfony\Component\Scheduler\ScheduleProviderInterface;
|
||||||
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
|
||||||
|
#[AsSchedule('notif_watchlist')]
|
||||||
|
final readonly class SendNotifWatchListTriggerSchedule implements ScheduleProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private CacheInterface $cache,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSchedule(): Schedule
|
||||||
|
{
|
||||||
|
return (new Schedule())
|
||||||
|
->add(
|
||||||
|
RecurringMessage::every('1 week', new SendNotifWatchListTrigger()),
|
||||||
|
)
|
||||||
|
->stateful($this->cache)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,7 +9,7 @@ use Symfony\Component\Scheduler\Schedule;
|
|||||||
use Symfony\Component\Scheduler\ScheduleProviderInterface;
|
use Symfony\Component\Scheduler\ScheduleProviderInterface;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
|
||||||
#[AsSchedule]
|
#[AsSchedule('rdap_udpate')]
|
||||||
final readonly class UpdateRdapServersSchedule implements ScheduleProviderInterface
|
final readonly class UpdateRdapServersSchedule implements ScheduleProviderInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user