Deprecate ScheduledTask model as it is not used anymore
[MAILPOET-5763]
This commit is contained in:
@@ -17,6 +17,9 @@ use MailPoetVendor\Idiorm\ORM;
|
|||||||
* @property bool|null $inProgress
|
* @property bool|null $inProgress
|
||||||
* @property int $rescheduleCount
|
* @property int $rescheduleCount
|
||||||
* @property string|array|null $meta
|
* @property string|array|null $meta
|
||||||
|
*
|
||||||
|
* @deprecated This model is deprecated. Use \MailPoet\Newsletter\Sending\ScheduledTasksRepository
|
||||||
|
* and \MailPoet\Entities\ScheduledTaskEntity instead. This class can be removed after 2024-05-30.
|
||||||
*/
|
*/
|
||||||
class ScheduledTask extends Model {
|
class ScheduledTask extends Model {
|
||||||
public static $_table = MP_SCHEDULED_TASKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
public static $_table = MP_SCHEDULED_TASKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
||||||
@@ -34,12 +37,20 @@ class ScheduledTask extends Model {
|
|||||||
|
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->wp = WPFunctions::get();
|
$this->wp = WPFunctions::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function subscribers() {
|
public function subscribers() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
return $this->hasManyThrough(
|
return $this->hasManyThrough(
|
||||||
__NAMESPACE__ . '\Subscriber',
|
__NAMESPACE__ . '\Subscriber',
|
||||||
__NAMESPACE__ . '\ScheduledTaskSubscriber',
|
__NAMESPACE__ . '\ScheduledTaskSubscriber',
|
||||||
@@ -48,13 +59,21 @@ class ScheduledTask extends Model {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function pause() {
|
public function pause() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$this->set('status', self::STATUS_PAUSED);
|
$this->set('status', self::STATUS_PAUSED);
|
||||||
$this->save();
|
$this->save();
|
||||||
return ($this->getErrors() === false && $this->id() > 0);
|
return ($this->getErrors() === false && $this->id() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static function pauseAllByNewsletter(Newsletter $newsletter) {
|
public static function pauseAllByNewsletter(Newsletter $newsletter) {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
ScheduledTask::rawExecute(
|
ScheduledTask::rawExecute(
|
||||||
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
||||||
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
||||||
@@ -65,13 +84,21 @@ class ScheduledTask extends Model {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function resume() {
|
public function resume() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$this->setExpr('status', 'NULL');
|
$this->setExpr('status', 'NULL');
|
||||||
$this->save();
|
$this->save();
|
||||||
return ($this->getErrors() === false && $this->id() > 0);
|
return ($this->getErrors() === false && $this->id() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static function setScheduledAllByNewsletter(Newsletter $newsletter) {
|
public static function setScheduledAllByNewsletter(Newsletter $newsletter) {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
ScheduledTask::rawExecute(
|
ScheduledTask::rawExecute(
|
||||||
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
||||||
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
||||||
@@ -83,14 +110,22 @@ class ScheduledTask extends Model {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function complete() {
|
public function complete() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$this->processedAt = $this->wp->currentTime('mysql');
|
$this->processedAt = $this->wp->currentTime('mysql');
|
||||||
$this->set('status', self::STATUS_COMPLETED);
|
$this->set('status', self::STATUS_COMPLETED);
|
||||||
$this->save();
|
$this->save();
|
||||||
return ($this->getErrors() === false && $this->id() > 0);
|
return ($this->getErrors() === false && $this->id() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
// set the default priority to medium
|
// set the default priority to medium
|
||||||
if (!$this->priority) {
|
if (!$this->priority) {
|
||||||
$this->priority = self::PRIORITY_MEDIUM;
|
$this->priority = self::PRIORITY_MEDIUM;
|
||||||
@@ -105,18 +140,30 @@ class ScheduledTask extends Model {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function asArray() {
|
public function asArray() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$model = parent::asArray();
|
$model = parent::asArray();
|
||||||
$model['meta'] = $this->getMeta();
|
$model['meta'] = $this->getMeta();
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function getMeta() {
|
public function getMeta() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$meta = (Helpers::isJson($this->meta) && is_string($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
$meta = (Helpers::isJson($this->meta) && is_string($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
||||||
return !empty($meta) ? (array)$meta : [];
|
return !empty($meta) ? (array)$meta : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
try {
|
try {
|
||||||
ORM::get_db()->beginTransaction();
|
ORM::get_db()->beginTransaction();
|
||||||
ScheduledTaskSubscriber::where('task_id', $this->id)->deleteMany();
|
ScheduledTaskSubscriber::where('task_id', $this->id)->deleteMany();
|
||||||
@@ -131,8 +178,10 @@ class ScheduledTask extends Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ScheduledTask|null
|
* @return ScheduledTask|null
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public static function findOneScheduledByNewsletterIdAndSubscriberId($newsletterId, $subscriberId) {
|
public static function findOneScheduledByNewsletterIdAndSubscriberId($newsletterId, $subscriberId) {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
return ScheduledTask::tableAlias('tasks')
|
return ScheduledTask::tableAlias('tasks')
|
||||||
->select('tasks.*')
|
->select('tasks.*')
|
||||||
->innerJoin(SendingQueue::$_table, 'queues.task_id = tasks.id', 'queues')
|
->innerJoin(SendingQueue::$_table, 'queues.task_id = tasks.id', 'queues')
|
||||||
@@ -144,4 +193,27 @@ class ScheduledTask extends Model {
|
|||||||
->whereNull('tasks.deleted_at')
|
->whereNull('tasks.deleted_at')
|
||||||
->findOne() ?: null;
|
->findOne() ?: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here for displaying the deprecation warning for properties.
|
||||||
|
*/
|
||||||
|
public function __get($key) {
|
||||||
|
self::deprecationError('property "' . $key . '"');
|
||||||
|
return parent::__get($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here for displaying the deprecation warning for static calls.
|
||||||
|
*/
|
||||||
|
public static function __callStatic($name, $arguments) {
|
||||||
|
self::deprecationError($name);
|
||||||
|
return parent::__callStatic($name, $arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function deprecationError($methodName) {
|
||||||
|
trigger_error(
|
||||||
|
'Calling ' . esc_html($methodName) . ' is deprecated and will be removed. Use \MailPoet\Newsletter\Sending\ScheduledTasksRepository and \MailPoet\Entities\ScheduledTaskEntity instead.',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user