|
12 | 12 | use Symfony\Component\Console\Command\Command; |
13 | 13 | use Symfony\Component\Console\Input\InputInterface; |
14 | 14 | use Symfony\Component\Console\Output\OutputInterface; |
| 15 | +use Symfony\Component\Mime\Exception\RfcComplianceException; |
15 | 16 | use Symfony\Component\Routing\RouterInterface; |
16 | 17 | use Webgriffe\SyliusBackInStockNotificationPlugin\Entity\SubscriptionInterface; |
17 | 18 | use Webgriffe\SyliusBackInStockNotificationPlugin\Repository\SubscriptionRepositoryInterface; |
@@ -44,27 +45,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
44 | 45 | //I think that this load in the long time can be a bottle necklace |
45 | 46 | $subscriptions = $this->backInStockNotificationRepository->findBy(['notify' => false]); |
46 | 47 | foreach ($subscriptions as $subscription) { |
47 | | - $channel = $subscription->getChannel(); |
48 | | - $productVariant = $subscription->getProductVariant(); |
49 | | - if ($productVariant === null || $channel === null) { |
50 | | - $this->backInStockNotificationRepository->remove($subscription); |
51 | | - $this->logger->warning( |
52 | | - 'The back in stock subscription for the product does not have all the information required', |
53 | | - ['subscription' => var_export($subscription, true)], |
54 | | - ); |
| 48 | + try { |
| 49 | + $channel = $subscription->getChannel(); |
| 50 | + $productVariant = $subscription->getProductVariant(); |
| 51 | + if ($productVariant === null || $channel === null) { |
| 52 | + $this->backInStockNotificationRepository->remove($subscription); |
| 53 | + $this->logger->warning( |
| 54 | + 'The back in stock subscription for the product does not have all the information required', |
| 55 | + ['subscription' => var_export($subscription, true)], |
| 56 | + ); |
55 | 57 |
|
56 | | - continue; |
57 | | - } |
| 58 | + continue; |
| 59 | + } |
58 | 60 |
|
59 | | - if ( |
60 | | - $this->availabilityChecker->isStockAvailable($productVariant) && |
61 | | - $productVariant->isEnabled() && |
62 | | - $productVariant->getProduct()?->isEnabled() === true |
63 | | - ) { |
64 | | - $this->router->getContext()->setHost($channel->getHostname() ?? 'localhost'); |
65 | | - $this->sendEmail($subscription, $productVariant, $channel); |
66 | | - $subscription->setNotify(true); |
67 | | - $this->backInStockNotificationRepository->add($subscription); |
| 61 | + if ( |
| 62 | + $this->availabilityChecker->isStockAvailable($productVariant) && |
| 63 | + $productVariant->isEnabled() && |
| 64 | + $productVariant->getProduct()?->isEnabled() === true |
| 65 | + ) { |
| 66 | + $this->router->getContext()->setHost($channel->getHostname() ?? 'localhost'); |
| 67 | + $this->sendEmail($subscription, $productVariant, $channel); |
| 68 | + $subscription->setNotify(true); |
| 69 | + $this->backInStockNotificationRepository->add($subscription); |
| 70 | + } |
| 71 | + } catch (RfcComplianceException $e) { |
| 72 | + // Invalid email address, continue to the next one |
| 73 | + $this->logger->warning($e->getMessage()); |
68 | 74 | } |
69 | 75 | } |
70 | 76 |
|
|
0 commit comments