Remove usages of MailPoet\Tasks\Sending from welcome scheduler

[MAILPOET-4375]
This commit is contained in:
Jan Jakes
2023-10-24 09:58:25 +02:00
committed by Aschepikov
parent 728e1781c6
commit b42d579b67
4 changed files with 69 additions and 58 deletions

View File

@@ -19,7 +19,6 @@ use MailPoet\Subscribers\SubscriberListingRepository;
use MailPoet\Subscribers\SubscriberSaveController;
use MailPoet\Subscribers\SubscriberSegmentRepository;
use MailPoet\Subscribers\SubscribersRepository;
use MailPoet\Tasks\Sending;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions;
use MailPoetVendor\Carbon\Carbon;
@@ -314,17 +313,14 @@ class Subscribers {
* @throws APIException
*/
protected function _scheduleWelcomeNotification(SubscriberEntity $subscriber, array $segments) {
$result = $this->welcomeScheduler->scheduleSubscriberWelcomeNotification($subscriber->getId(), $segments);
if (is_array($result)) {
foreach ($result as $queue) {
if ($queue instanceof Sending && $queue->getErrors()) {
throw new APIException(
// translators: %s is a comma-separated list of errors
sprintf(__('Subscriber added, but welcome email failed to send: %s', 'mailpoet'), strtolower(implode(', ', $queue->getErrors()))),
APIException::WELCOME_FAILED_TO_SEND
);
}
}
try {
$this->welcomeScheduler->scheduleSubscriberWelcomeNotification($subscriber->getId(), $segments);
} catch (\Throwable $e) {
throw new APIException(
// translators: %s is an error message
sprintf(__('Subscriber added, but welcome email failed to send: %s', 'mailpoet'), $e->getMessage()),
APIException::WELCOME_FAILED_TO_SEND
);
}
}