Fix acceptance tests, update counters [MAILPOET-903]

This commit is contained in:
stoletniy
2018-02-14 19:57:14 +03:00
parent 606177baaf
commit b9546b61a8
5 changed files with 17 additions and 12 deletions

View File

@ -166,13 +166,16 @@ class Newsletters extends APIEndpoint {
// if there are past due notifications, reschedule them for the next send date
if($newsletter->type === Newsletter::TYPE_NOTIFICATION && $status === Newsletter::STATUS_ACTIVE) {
$next_run_date = Scheduler::getNextRunDate($newsletter->schedule);
$newsletter->queue()->findOne()->task()
$queue = $newsletter->queue()->findOne();
if($queue) {
$queue->task()
->whereLte('scheduled_at', Carbon::createFromTimestamp(current_time('timestamp')))
->where('status', SendingQueue::STATUS_SCHEDULED)
->findResultSet()
->set('scheduled_at', $next_run_date)
->save();
}
}
return $this->successResponse(
Newsletter::findOne($newsletter->id)->asArray()

View File

@ -47,6 +47,7 @@ class SendingQueue extends APIEndpoint {
// add newsletter to the sending queue
$queue = SendingQueueModel::joinWithTasks()
->where('queues.newsletter_id', $newsletter->id)
->whereNull('tasks.status')
->findOne();
@ -84,6 +85,7 @@ class SendingQueue extends APIEndpoint {
APIError::UNKNOWN => __('There are no subscribers in that list!', 'mailpoet')
));
}
$queue->updateCount();
$queue->status = null;
$queue->scheduled_at = null;

View File

@ -102,6 +102,7 @@ class Scheduler {
$finder = new SubscribersFinder();
$subscribers_count = $finder->addSubscribersToTaskFromSegments($queue->task(), $segments);
// update current queue
$queue->updateCount();
$queue->status = null;
$queue->save();
// update newsletter status

View File

@ -315,6 +315,9 @@ CREATE TABLE `mp_mailpoet_scheduled_tasks` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
INSERT INTO `mp_mailpoet_scheduled_tasks` (`id`, `type`, `status`, `created_at`, `updated_at`) VALUES
(1, 'migration', 'completed', '2017-03-02 11:20:00', '2017-03-02 16:21:00');
DROP TABLE IF EXISTS `mp_mailpoet_scheduled_task_subscribers`;
CREATE TABLE `mp_mailpoet_scheduled_task_subscribers` (
@ -346,18 +349,14 @@ INSERT INTO `mp_mailpoet_segments` (`id`, `name`, `type`, `description`, `create
DROP TABLE IF EXISTS `mp_mailpoet_sending_queues`;
CREATE TABLE `mp_mailpoet_sending_queues` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(90) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`task_id` int(11) unsigned NOT NULL,
`newsletter_id` int(11) unsigned NOT NULL,
`newsletter_rendered_body` longtext COLLATE utf8mb4_unicode_520_ci,
`newsletter_rendered_subject` varchar(250) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`subscribers` longtext COLLATE utf8mb4_unicode_520_ci,
`status` varchar(12) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`priority` mediumint(9) NOT NULL DEFAULT '0',
`count_total` int(11) unsigned NOT NULL DEFAULT '0',
`count_processed` int(11) unsigned NOT NULL DEFAULT '0',
`count_to_process` int(11) unsigned NOT NULL DEFAULT '0',
`scheduled_at` timestamp NULL DEFAULT NULL,
`processed_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,

View File

@ -40,7 +40,7 @@ class ManageSubscriptionLinkCest {
$I->fillField($search_field_element, 'WordPress Users');
$I->pressKey($search_field_element, \WebDriverKeys::ENTER);
$I->click('Send');
$I->waitForText('Sent to 1 of 1', 20);
$I->waitForText('Sent to 1 of 1', 60);
}
function manageSubscriptionLink(\AcceptanceTester $I) {