Allow sending an email multiple times

[MAILPOET-4966]
This commit is contained in:
David Remer
2023-02-03 10:05:33 +02:00
committed by Aschepikov
parent fcf6e738c7
commit 93cfffe295
2 changed files with 0 additions and 44 deletions

View File

@@ -14,7 +14,6 @@ use MailPoet\Entities\SubscriberEntity;
use MailPoet\InvalidStateException;
use MailPoet\Newsletter\NewslettersRepository;
use MailPoet\Newsletter\Scheduler\AutomationEmailScheduler;
use MailPoet\Newsletter\Sending\ScheduledTasksRepository;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscribers\SubscriberSegmentRepository;
use MailPoet\Validator\Builder;
@@ -30,9 +29,6 @@ class SendEmailAction implements Action {
/** @var NewslettersRepository */
private $newslettersRepository;
/** @var ScheduledTasksRepository */
private $scheduledTasksRepository;
/** @var SubscriberSegmentRepository */
private $subscriberSegmentRepository;
@@ -42,13 +38,11 @@ class SendEmailAction implements Action {
public function __construct(
SettingsController $settings,
NewslettersRepository $newslettersRepository,
ScheduledTasksRepository $scheduledTasksRepository,
SubscriberSegmentRepository $subscriberSegmentRepository,
AutomationEmailScheduler $automationEmailScheduler
) {
$this->settings = $settings;
$this->newslettersRepository = $newslettersRepository;
$this->scheduledTasksRepository = $scheduledTasksRepository;
$this->subscriberSegmentRepository = $subscriberSegmentRepository;
$this->automationEmailScheduler = $automationEmailScheduler;
}
@@ -138,11 +132,6 @@ class SendEmailAction implements Action {
throw InvalidStateException::create()->withMessage(sprintf("Cannot schedule a newsletter for subscriber ID '%s' because their status is '%s'.", $subscriberId, $subscriberStatus));
}
$previouslyScheduledNotification = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($newsletter, $subscriberId);
if (!empty($previouslyScheduledNotification)) {
throw InvalidStateException::create()->withMessage(sprintf("Subscriber ID '%s' was already scheduled to receive newsletter ID '%s'.", $subscriberId, $newsletter->getId()));
}
try {
$this->automationEmailScheduler->createSendingTask($newsletter, $subscriber);
} catch (Throwable $e) {

View File

@@ -22,7 +22,6 @@ use MailPoet\Entities\SendingQueueEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Entities\SubscriberSegmentEntity;
use MailPoet\Exception;
use MailPoet\InvalidStateException;
use MailPoet\Newsletter\Sending\ScheduledTasksRepository;
use MailPoet\Segments\SegmentsRepository;
use MailPoet\Subscribers\SubscribersRepository;
@@ -119,38 +118,6 @@ class SendEmailActionTest extends \MailPoetTest {
expect($scheduled)->count(1);
}
public function testItDoesNotScheduleDuplicates(): void {
$segment = (new Segment())->create();
$subscriber = (new Subscriber())
->withStatus(SubscriberEntity::STATUS_SUBSCRIBED)
->withSegments([$segment])
->create();
$subjects = $this->getSubjectData($subscriber, $segment);
$email = (new Newsletter())->withAutomationType()->create();
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', ['email_id' => $email->getId()], []);
$automation = new Automation('some-automation', [$step->getId() => $step], new \WP_User());
$run = new AutomationRun(1, 1, 'trigger-key', $subjects);
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
expect($scheduled)->count(0);
$action = ContainerWrapper::getInstance()->get(SendEmailAction::class);
$action->run(new StepRunArgs($automation, $run, $step, $this->getSubjectEntries($subjects)));
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
expect($scheduled)->count(1);
try {
$action->run(new StepRunArgs($automation, $run, $step, $this->getSubjectEntries($subjects)));
} catch (InvalidStateException $exception) {
// The exception itself isn't as important as the outcome
}
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
expect($scheduled)->count(1);
}
public function testNothingScheduledIfSegmentDeleted(): void {
$segment = (new Segment())->create();
$subscriber = (new Subscriber())