Skip to content
Open
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
44 changes: 25 additions & 19 deletions src/Command/AlertCommand.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just try/catch the line that throw the exception and do a continue with a log before it. Please remove also the comment, if you want you can add the line Invalid email address, continue to the next one to the log with the exception message

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 @@ -44,27 +45,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
//I think that this load in the long time can be a bottle necklace
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling/wording: "bottle necklace" should be "bottleneck" (and add a space after //) to keep the inline comment understandable.

Suggested change
//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

Copilot uses AI. Check for mistakes.
$subscriptions = $this->backInStockNotificationRepository->findBy(['notify' => false]);
foreach ($subscriptions as $subscription) {
$channel = $subscription->getChannel();
$productVariant = $subscription->getProductVariant();
if ($productVariant === null || $channel === null) {
$this->backInStockNotificationRepository->remove($subscription);
$this->logger->warning(
'The back in stock subscription for the product does not have all the information required',
['subscription' => var_export($subscription, true)],
);
try {
$channel = $subscription->getChannel();
$productVariant = $subscription->getProductVariant();
if ($productVariant === null || $channel === null) {
$this->backInStockNotificationRepository->remove($subscription);
$this->logger->warning(
'The back in stock subscription for the product does not have all the information required',
['subscription' => var_export($subscription, true)],
);

continue;
}
continue;
}

if (
$this->availabilityChecker->isStockAvailable($productVariant) &&
$productVariant->isEnabled() &&
$productVariant->getProduct()?->isEnabled() === true
) {
$this->router->getContext()->setHost($channel->getHostname() ?? 'localhost');
$this->sendEmail($subscription, $productVariant, $channel);
$subscription->setNotify(true);
$this->backInStockNotificationRepository->add($subscription);
if (
$this->availabilityChecker->isStockAvailable($productVariant) &&
$productVariant->isEnabled() &&
$productVariant->getProduct()?->isEnabled() === true
) {
$this->router->getContext()->setHost($channel->getHostname() ?? 'localhost');
$this->sendEmail($subscription, $productVariant, $channel);
$subscription->setNotify(true);
$this->backInStockNotificationRepository->add($subscription);
}
} catch (RfcComplianceException $e) {
// Invalid email address, continue to the next one
$this->logger->warning($e->getMessage());
}
Comment on lines +71 to 74
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the RfcComplianceException handler, the subscription remains with notify=false, so the command will hit the same invalid address on every run (repeated exceptions + noisy logs). Consider either removing the invalid subscription (as is done when channel/productVariant is missing) or marking it as notified/failed so it won’t be retried, and log with structured context (e.g., subscription id/email) instead of only the raw exception message.

Copilot uses AI. Check for mistakes.
}

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']),
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the email validation behavior (strict RFC mode). Since the repo already has Behat coverage around guest subscription flows, it would be good to add a scenario that submits a clearly invalid/malicious email (like the one from the PR description) and asserts the form shows a validation error and no subscription/success email is created, to prevent regressions.

Copilot uses AI. Check for mistakes.
],
])
->add('product_variant_code', HiddenType::class)
Expand Down