From c5d1715f39b83877eb73851ca65e44f960f3bee5 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 30 Nov 2023 15:58:13 -0300 Subject: [PATCH] Deprecate ScheduledTask model as it is not used anymore [MAILPOET-5763] --- mailpoet/lib/Models/ScheduledTask.php | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/mailpoet/lib/Models/ScheduledTask.php b/mailpoet/lib/Models/ScheduledTask.php index 8c4cb85ae3..d44133af88 100644 --- a/mailpoet/lib/Models/ScheduledTask.php +++ b/mailpoet/lib/Models/ScheduledTask.php @@ -17,6 +17,9 @@ use MailPoetVendor\Idiorm\ORM; * @property bool|null $inProgress * @property int $rescheduleCount * @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 { public static $_table = MP_SCHEDULED_TASKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration @@ -34,12 +37,20 @@ class ScheduledTask extends Model { private $wp; + /** + * @deprecated + */ public function __construct() { + self::deprecationError(__METHOD__); parent::__construct(); $this->wp = WPFunctions::get(); } + /** + * @deprecated + */ public function subscribers() { + self::deprecationError(__METHOD__); return $this->hasManyThrough( __NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\ScheduledTaskSubscriber', @@ -48,13 +59,21 @@ class ScheduledTask extends Model { ); } + /** + * @deprecated + */ public function pause() { + self::deprecationError(__METHOD__); $this->set('status', self::STATUS_PAUSED); $this->save(); return ($this->getErrors() === false && $this->id() > 0); } + /** + * @deprecated + */ public static function pauseAllByNewsletter(Newsletter $newsletter) { + self::deprecationError(__METHOD__); ScheduledTask::rawExecute( 'UPDATE `' . ScheduledTask::$_table . '` t ' . 'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' . @@ -65,13 +84,21 @@ class ScheduledTask extends Model { ); } + /** + * @deprecated + */ public function resume() { + self::deprecationError(__METHOD__); $this->setExpr('status', 'NULL'); $this->save(); return ($this->getErrors() === false && $this->id() > 0); } + /** + * @deprecated + */ public static function setScheduledAllByNewsletter(Newsletter $newsletter) { + self::deprecationError(__METHOD__); ScheduledTask::rawExecute( 'UPDATE `' . ScheduledTask::$_table . '` t ' . 'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' . @@ -83,14 +110,22 @@ class ScheduledTask extends Model { ); } + /** + * @deprecated + */ public function complete() { + self::deprecationError(__METHOD__); $this->processedAt = $this->wp->currentTime('mysql'); $this->set('status', self::STATUS_COMPLETED); $this->save(); return ($this->getErrors() === false && $this->id() > 0); } + /** + * @deprecated + */ public function save() { + self::deprecationError(__METHOD__); // set the default priority to medium if (!$this->priority) { $this->priority = self::PRIORITY_MEDIUM; @@ -105,18 +140,30 @@ class ScheduledTask extends Model { return $this; } + /** + * @deprecated + */ public function asArray() { + self::deprecationError(__METHOD__); $model = parent::asArray(); $model['meta'] = $this->getMeta(); return $model; } + /** + * @deprecated + */ public function getMeta() { + self::deprecationError(__METHOD__); $meta = (Helpers::isJson($this->meta) && is_string($this->meta)) ? json_decode($this->meta, true) : $this->meta; return !empty($meta) ? (array)$meta : []; } + /** + * @deprecated + */ public function delete() { + self::deprecationError(__METHOD__); try { ORM::get_db()->beginTransaction(); ScheduledTaskSubscriber::where('task_id', $this->id)->deleteMany(); @@ -131,8 +178,10 @@ class ScheduledTask extends Model { /** * @return ScheduledTask|null + * @deprecated */ public static function findOneScheduledByNewsletterIdAndSubscriberId($newsletterId, $subscriberId) { + self::deprecationError(__METHOD__); return ScheduledTask::tableAlias('tasks') ->select('tasks.*') ->innerJoin(SendingQueue::$_table, 'queues.task_id = tasks.id', 'queues') @@ -144,4 +193,27 @@ class ScheduledTask extends Model { ->whereNull('tasks.deleted_at') ->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 + ); + } }