sender = new Address($mailerSenderEmail, $mailerSenderName); } /** * @throws ExceptionInterface * @throws TransportExceptionInterface * @throws ClientExceptionInterface * @throws DecodingExceptionInterface * @throws RedirectionExceptionInterface * @throws ServerExceptionInterface * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface * @throws \Throwable */ public function __invoke(UpdateDomainsFromWatchlist $message): void { /** @var WatchList $watchList */ $watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]); $this->logger->info('Domain names from Watchlist {token} will be processed.', [ 'token' => $message->watchListToken, ]); $connector = $watchList->getConnector(); if (null !== $connector && null !== $connector->getProvider()) { $provider = $connector->getProvider(); $connectorProviderClass = $provider->getConnectorProvider(); /** @var AbstractProvider $connectorProvider */ /** @var EppClientProvider $connectorProvider */ $connectorProvider = $this->locator->get($connectorProviderClass); } if (isset($connectorProvider) && $connectorProvider instanceof CheckDomainProviderInterface) { $this->logger->notice('Watchlist {watchlist} is linked to connector {connector}.', [ 'watchlist' => $message->watchListToken, 'connector' => $connector->getId(), ]); try { $checkedDomains = $connectorProvider->checkDomains( ...array_unique(array_map(fn (Domain $d) => $d->getLdhName(), $watchList->getDomains()->toArray())) ); } catch (\Throwable $exception) { $this->logger->warning('Unable to check domain names availability with connector {connector}.', [ 'connector' => $connector->getId(), ]); throw $exception; } foreach ($checkedDomains as $domain) { try { $connectorProvider->orderDomain($this->em->getReference(Domain::class, $domain), $this->kernel->isDebug()); $this->logger->notice('Watchlist {watchlist} is linked to connector {connector}. A purchase was successfully made for domain {ldhName}.', [ 'watchlist' => $message->watchListToken, 'connector' => $connector->getId(), 'ldhName' => $domain, ]); // TODO : remove dupcode $this->statService->incrementStat('stats.domain.purchased'); if ($this->influxdbEnabled) { $this->influxdbService->addDomainOrderPoint($connector, $domain, true); } $notification = (new DomainOrderNotification($this->sender, $domain, $connector)); $this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage()); $this->chatNotificationService->sendChatNotification($watchList, $notification); } catch (\Throwable $exception) { // TODO : remove dupcode $this->logger->warning('Unable to complete purchase. An error message is sent to user {username}.', [ 'username' => $watchList->getUser()->getUserIdentifier(), ]); $this->statService->incrementStat('stats.domain.purchase.failed'); if ($this->influxdbEnabled) { $this->influxdbService->addDomainOrderPoint($connector, $domain, false); } $notification = (new DomainOrderErrorNotification($this->sender, $domain)); $this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage()); $this->chatNotificationService->sendChatNotification($watchList, $notification); throw $exception; } } 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) => $domain->isToBeUpdated(false)) as $domain ) { $updatedAt = $domain->getUpdatedAt(); 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 (NotFoundHttpException) { if (!$domain->getDeleted()) { $notification = (new DomainDeletedNotification($this->sender, $domain)); $this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage()); $this->chatNotificationService->sendChatNotification($watchList, $notification); } if (null !== $connector) { /* * 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(), $updatedAt)); } } catch (\Throwable $e) { /* * In case of another unknown error, * the owner of the Watchlist is informed that an error occurred in updating the domain name. */ $this->logger->error('An update error email is sent to user {username}.', [ 'username' => $watchList->getUser()->getUserIdentifier(), 'error' => $e, ]); $email = (new DomainUpdateErrorNotification($this->sender, $domain)) ->asEmailMessage(new Recipient($watchList->getUser()->getEmail())); $this->mailer->send($email->getMessage()); throw $e; } } } }