Use a separate table instead of sending_queue
[MAILPOET-1571]
This commit is contained in:
@ -132,6 +132,8 @@ class Migrator {
|
||||
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
|
||||
'newsletter_id int(11) unsigned NOT NULL,',
|
||||
'task_id int(11) unsigned NOT NULL,',
|
||||
'created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,',
|
||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id),',
|
||||
'KEY newsletter_id (newsletter_id),',
|
||||
'KEY task_id (task_id)',
|
||||
|
@ -6,13 +6,12 @@ use Carbon\Carbon;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\StatsNotification;
|
||||
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* - finish stats_notifications table, test if it is working and the migration is creating the table
|
||||
* - remove all the SendingQueue from here
|
||||
* - in schedule method add a row to stats_notifications table
|
||||
* - when sending of post notification or a standard newsletter is finished call schedule
|
||||
* - add processing of this task to Daemon
|
||||
* - check JIRA what to do next and how to send the newsletter
|
||||
@ -41,10 +40,10 @@ class StatsNotifications {
|
||||
$task->scheduled_at = $this->getNextRunDate();
|
||||
$task->save();
|
||||
|
||||
$queue = SendingQueue::create();
|
||||
$queue->newsletter_id = $newsletter_id;
|
||||
$queue->task_id = $task->id;
|
||||
$queue->save();
|
||||
$stats_notifications = StatsNotification::create();
|
||||
$stats_notifications->newsletter_id = $newsletter_id;
|
||||
$stats_notifications->task_id = $task->id;
|
||||
$stats_notifications->save();
|
||||
}
|
||||
|
||||
function process() {
|
||||
@ -80,9 +79,9 @@ class StatsNotifications {
|
||||
|
||||
private function isTaskScheduled($newsletter_id) {
|
||||
$existing = ScheduledTask::table_alias('tasks')
|
||||
->join(SendingQueue::$_table, 'tasks.id = queues.task_id', 'queues')
|
||||
->join(StatsNotification::$_table, 'tasks.id = notification.task_id', 'notification')
|
||||
->where('tasks.type', self::TASK_TYPE)
|
||||
->where('queues.newsletter_id', $newsletter_id)
|
||||
->where('notification.newsletter_id', $newsletter_id)
|
||||
->findMany();
|
||||
return (bool) $existing;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use MailPoet\Cron\Workers\StatsNotifications;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\StatsNotification;
|
||||
|
||||
class StatsNotificationsTest extends \MailPoetTest {
|
||||
|
||||
@ -24,9 +25,9 @@ class StatsNotificationsTest extends \MailPoetTest {
|
||||
function testShouldSchedule() {
|
||||
$newsletter_id = 5;
|
||||
$this->stats_notifications->schedule($newsletter_id);
|
||||
$queue = SendingQueue::where('newsletter_id', $newsletter_id)->findOne();
|
||||
expect($queue)->isInstanceOf(SendingQueue::class);
|
||||
$task = ScheduledTask::where('id', $queue->task_id)->findOne();
|
||||
$notification = StatsNotification::where('newsletter_id', $newsletter_id)->findOne();
|
||||
expect($notification)->isInstanceOf(StatsNotification::class);
|
||||
$task = ScheduledTask::where('id', $notification->task_id)->findOne();
|
||||
expect($task)->isInstanceOf(ScheduledTask::class);
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,6 @@
|
||||
} else {
|
||||
$('#settings_subscriber_email_notification_error').hide();
|
||||
}
|
||||
console.log("whatever");
|
||||
// if new subscriber notification is enabled but sender is empty, show error
|
||||
var stats_notifications_enabled = $('input[name="stats_notifications[enabled]"]:checked').val(),
|
||||
stats_notifications_address = $('input[name="stats_notifications[address]"]').val().trim();
|
||||
if (stats_notifications_enabled && stats_notifications_address == '') {
|
||||
|
Reference in New Issue
Block a user