sender = new Address($mailerSenderEmail, $mailerSenderName); } /** * @throws \Throwable */ public function __invoke(UpdateDomainsFromWatchlist $message): void { /** @var Watchlist $watchlist */ $watchlist = $this->watchlistRepository->findOneBy(['token' => $message->watchlistToken]); $this->logger->debug('Domain names listed in the Watchlist will be updated', [ 'watchlist' => $message->watchlistToken, ]); /** @var AbstractProvider $connectorProvider */ $connectorProvider = $this->getConnectorProvider($watchlist); if ($connectorProvider instanceof CheckDomainProviderInterface) { $this->logger->debug('Watchlist is linked to a connector', [ 'watchlist' => $watchlist->getToken(), 'connector' => $watchlist->getConnector()->getId(), ]); $domainList = array_unique(array_map(fn (Domain $d) => $d->getLdhName(), $watchlist->getDomains()->toArray())); try { $checkedDomains = $connectorProvider->checkDomains(...$domainList); } catch (\Throwable $exception) { $this->logger->warning('Unable to check domain names availability with this connector', [ 'connector' => $watchlist->getConnector()->getId(), 'ldhName' => $domainList, ]); throw $exception; } foreach ($checkedDomains as $domain) { $this->bus->dispatch(new OrderDomain($watchlist->getToken(), $domain)); } return; } /* * A domain name is updated if one or more of these conditions are met: * - was updated more than 7 days ago * - has statuses that suggest it will expire soon AND was updated more than 15 minutes ago * - has specific statuses that suggest there is a dispute between the registrant and the registrar AND was updated more than a day ago */ /** @var Domain $domain */ foreach ($watchlist->getDomains()->filter(fn ($domain) => $this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) as $domain ) { $updatedAt = $domain->getUpdatedAt(); $deleted = $domain->getDeleted(); try { /* * Domain name update * We send messages that correspond to the sending of notifications that will not be processed here. */ $this->RDAPService->registerDomain($domain->getLdhName()); $this->bus->dispatch(new SendDomainEventNotif($watchlist->getToken(), $domain->getLdhName(), $updatedAt)); } catch (DomainNotFoundException) { $newDomain = $this->domainRepository->findOneBy(['ldhName' => $domain->getLdhName()]); if (!$deleted && null !== $newDomain && $newDomain->getDeleted()) { $notification = new DomainDeletedNotification($this->sender, $domain); $this->mailer->send($notification->asEmailMessage(new Recipient($watchlist->getUser()->getEmail()))->getMessage()); $this->chatNotificationService->sendChatNotification($watchlist, $notification); } if ($watchlist->getConnector()) { /* * If the domain name no longer appears in the WHOIS AND a connector is associated with this Watchlist, * this connector is used to purchase the domain name. */ $this->bus->dispatch(new OrderDomain($watchlist->getToken(), $domain->getLdhName())); } } catch (TldNotSupportedException|UnknownRdapServerException) { /* * In this case, the domain name can no longer be updated. Unfortunately, there is nothing more that can be done. */ } } } private function getConnectorProvider(Watchlist $watchlist): ?object { $connector = $watchlist->getConnector(); if (null === $connector || null === $connector->getProvider()) { return null; } $providerClass = $connector->getProvider()->getConnectorProvider(); return $this->locator->get($providerClass); } }