diff --git a/lib/Cron/Workers/SendingQueue/SendingQueue.php b/lib/Cron/Workers/SendingQueue/SendingQueue.php index 5f083cb972..94858fed25 100644 --- a/lib/Cron/Workers/SendingQueue/SendingQueue.php +++ b/lib/Cron/Workers/SendingQueue/SendingQueue.php @@ -165,7 +165,14 @@ class SendingQueue { ); } // update processed/to process list - $queue->updateProcessedSubscribers($prepared_subscribers_ids); + if(!$queue->updateProcessedSubscribers($prepared_subscribers_ids)) { + MailerLog::processError( + 'processed_list_update', + sprintf('QUEUE-%d-PROCESSED-LIST-UPDATE', $queue->id), + null, + true + ); + } // log statistics StatisticsNewslettersModel::createMultiple($statistics); // update the sent count diff --git a/lib/Models/SendingQueue.php b/lib/Models/SendingQueue.php index d14b91c341..912d7e62b2 100644 --- a/lib/Models/SendingQueue.php +++ b/lib/Models/SendingQueue.php @@ -151,7 +151,7 @@ class SendingQueue extends Model { ) ); $this->subscribers = $subscribers; - $this->updateCount(); + return $this->updateCount()->getErrors() === false; } function updateCount() { @@ -175,5 +175,4 @@ class SendingQueue extends Model { } return $rendered_body; } - } \ No newline at end of file diff --git a/tests/unit/Cron/Workers/SendingQueue/SendingQueueTest.php b/tests/unit/Cron/Workers/SendingQueue/SendingQueueTest.php index 73daf38f57..6db76930e9 100644 --- a/tests/unit/Cron/Workers/SendingQueue/SendingQueueTest.php +++ b/tests/unit/Cron/Workers/SendingQueue/SendingQueueTest.php @@ -1,6 +1,7 @@ count_total)->equals(0); } + function testItPausesSendingWhenProcessedSubscriberListCannotBeUpdated() { + $queue = Mock::double(new \stdClass(), array( + 'updateProcessedSubscribers' => false + )); + $queue->id = 100; + $sending_queue_worker = Stub::make(new SendingQueueWorker()); + $sending_queue_worker->__construct( + $timer = false, + Stub::make( + new MailerTask(), + array( + 'send' => true + ) + ) + ); + try { + $sending_queue_worker->sendNewsletters( + $queue, + $prepared_subscribers = array(), + $prepared_newsletters = false, + $prepared_subscribers = false, + $statistics = false + ); + $this->fail('Paused sending exception was not thrown.'); + } catch(\Exception $e) { + expect($e->getMessage())->equals('Sending has been paused.'); + } + $mailer_log = MailerLog::getMailerLog(); + expect($mailer_log['status'])->equals(MailerLog::STATUS_PAUSED); + expect($mailer_log['error'])->equals( + array( + 'operation' => 'processed_list_update', + 'error_message' => 'QUEUE-100-PROCESSED-LIST-UPDATE' + ) + ); + } + function _after() { \ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); \ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table); @@ -585,4 +624,4 @@ class SendingQueueTest extends \MailPoetTest { \ORM::raw_execute('TRUNCATE ' . NewsletterSegment::$_table); \ORM::raw_execute('TRUNCATE ' . StatisticsNewsletters::$_table); } -} +} \ No newline at end of file