Pause sending tasks for inactive notifications

[MAILPOET-1376]
This commit is contained in:
Pavel Dohnal
2018-05-15 16:40:31 +01:00
parent d44c275790
commit 941b88495a
6 changed files with 134 additions and 0 deletions

View File

@ -30,12 +30,35 @@ class ScheduledTask extends Model {
return ($this->getErrors() === false && $this->id() > 0);
}
static function pauseAllByNewsletter(Newsletter $newsletter) {
ScheduledTask::rawExecute(
'UPDATE `' . ScheduledTask::$_table . '` t ' .
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
'SET t.`status` = "' . self::STATUS_PAUSED . '" ' .
'WHERE ' .
'q.`newsletter_id` = ' . $newsletter->id() .
' AND t.`status` = "' . self::STATUS_SCHEDULED . '" '
);
}
function resume() {
$this->setExpr('status', 'NULL');
$this->save();
return ($this->getErrors() === false && $this->id() > 0);
}
static function setScheduledAllByNewsletter(Newsletter $newsletter) {
ScheduledTask::rawExecute(
'UPDATE `' . ScheduledTask::$_table . '` t ' .
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
'SET t.`status` = "' . self::STATUS_SCHEDULED . '" ' .
'WHERE ' .
'q.`newsletter_id` = ' . $newsletter->id() .
' AND t.`status` = "' . self::STATUS_PAUSED . '" ' .
' AND t.`scheduled_at` > NOW()'
);
}
function complete() {
$this->processed_at = WPFunctions::currentTime('mysql');
$this->set('status', self::STATUS_COMPLETED);