Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Command/AlertCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mime\Exception\RfcComplianceException;
use Symfony\Component\Routing\RouterInterface;
use Webgriffe\SyliusBackInStockNotificationPlugin\Entity\SubscriptionInterface;
use Webgriffe\SyliusBackInStockNotificationPlugin\Repository\SubscriptionRepositoryInterface;
Expand Down Expand Up @@ -41,10 +42,10 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
//I think that this load in the long time can be a bottle necklace
// I think that this load in the long time can be a bottleneck
$subscriptions = $this->backInStockNotificationRepository->findBy(['notify' => false]);
foreach ($subscriptions as $subscription) {
$channel = $subscription->getChannel();
$channel = $subscription->getChannel();
$productVariant = $subscription->getProductVariant();
if ($productVariant === null || $channel === null) {
$this->backInStockNotificationRepository->remove($subscription);
Expand All @@ -62,7 +63,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$productVariant->getProduct()?->isEnabled() === true
) {
$this->router->getContext()->setHost($channel->getHostname() ?? 'localhost');
$this->sendEmail($subscription, $productVariant, $channel);

try {
$this->sendEmail($subscription, $productVariant, $channel);
} catch (RfcComplianceException $e) {
$this->logger->warning('Invalid email address, continue to the next one: ' . $e->getMessage());
continue;
}
$subscription->setNotify(true);
$this->backInStockNotificationRepository->add($subscription);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/SubscriptionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('email', EmailType::class, [
'constraints' => [
new NotBlank([], null, null, null, ['webgriffe_sylius_back_in_stock_notification_plugin']),
new Email([], null, null, null, ['webgriffe_sylius_back_in_stock_notification_plugin']),
new Email(['mode' => Email::VALIDATION_MODE_STRICT], null, null, null, ['webgriffe_sylius_back_in_stock_notification_plugin']),
],
])
->add('product_variant_code', HiddenType::class)
Expand Down
Loading