Use a meta field to store the in-progress flag [MAILPOET-1983]

This commit is contained in:
wxa
2019-04-22 21:23:33 +03:00
committed by M. Shull
parent 02020b8271
commit 6c13bc3104
6 changed files with 63 additions and 37 deletions

View File

@@ -1,6 +1,8 @@
<?php
namespace MailPoet\Models;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
@@ -12,6 +14,7 @@ if (!defined('ABSPATH')) exit;
* @property string|null $type
* @property int $priority
* @property string|null $scheduled_at
* @property string|array|null $meta
*/
class ScheduledTask extends Model {
public static $_table = MP_SCHEDULED_TASKS_TABLE;
@@ -96,10 +99,26 @@ class ScheduledTask extends Model {
if (!$this->priority) {
$this->priority = self::PRIORITY_MEDIUM;
}
if (!Helpers::isJson($this->meta)) {
$this->set(
'meta',
json_encode($this->meta)
);
}
parent::save();
return $this;
}
function asArray() {
$model = parent::asArray();
$model['meta'] = $this->getMeta();
return $model;
}
function getMeta() {
return (Helpers::isJson($this->meta)) ? json_decode($this->meta, true) : $this->meta;
}
function delete() {
try {
\ORM::get_db()->beginTransaction();