From c4e3ac436b124ee46519b47f517abadd30f9ac91 Mon Sep 17 00:00:00 2001 From: zero-24 Date: Sat, 20 Jul 2024 20:28:57 +0200 Subject: [PATCH 01/13] backport the changes from #43490 to 5.2-dev --- .../language/en-GB/com_scheduler.ini | 2 +- .../src/Extension/ScheduleRunner.php | 51 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/administrator/language/en-GB/com_scheduler.ini b/administrator/language/en-GB/com_scheduler.ini index f5eee988a7c2c..18c442f67e2f6 100644 --- a/administrator/language/en-GB/com_scheduler.ini +++ b/administrator/language/en-GB/com_scheduler.ini @@ -9,7 +9,7 @@ COM_SCHEDULER_CONFIG_FIELDSET_LAZY_SCHEDULER_DESC="Configure how site visits tri COM_SCHEDULER_CONFIG_FIELDSET_LAZY_SCHEDULER_LABEL="Lazy Scheduler" COM_SCHEDULER_CONFIG_GENERATE_WEBCRON_KEY_DESC="The webcron needs a protection key before it is functional. Saving this configuration will autogenerate the key." COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_KEY_LABEL="Global Key" -COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_DESC="By default, requesting this base link will only run tasks due for execution. To execute a specific task, use the task's ID as a query parameter appended to the URL: BASE_URL&id=<taskId>" +COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_DESC="By default, requesting this base link will only run tasks due for execution. To execute a specific task, use the task's ID as a query parameter appended to the URL: BASE_URL&taskid=<taskId>" COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_LABEL="Webcron Link (Base)" COM_SCHEDULER_CONFIG_HASH_PROTECTION_DESC="If enabled, tasks will only be triggered when URLs have the scheduler hash as a parameter." COM_SCHEDULER_CONFIG_LAZY_SCHEDULER_ENABLED_DESC="If disabled, scheduled tasks will not be triggered by visitors on the site.
It is recommended to DISABLE the Lazy Scheduler, if triggering with native cron." diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 65438995db52b..c27081ef58839 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -202,12 +202,55 @@ public function runWebCron(Event $event) throw new \Exception($this->getApplication()->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } - $id = (int) $this->getApplication()->getInput()->getInt('id', 0); + $input = $this->getApplication()->getInput(); - $task = $this->runScheduler($id); + // The "id" parameter will be removed with 6.0 as that behavior is broken + $id = (int) $input->getInt('id', 0); + $taskId = (int) $input->getInt('taskid', $id); - if (!empty($task) && !empty($task->getContent()['exception'])) { - throw $task->getContent()['exception']; + /** + * Yes we are aware that the current behavior is broken meaning as long as there is no ID passed via + * the URL the current code will still fail. But we need to keep that behavior for B/C reasons. Starting + * with 6.0 only taskid will be supported and when the cron is triggered without taskid it will trigger + * the next item available the broken behavior with will be removed. + */ + + $scheduler = new Scheduler(); + + if ($id) + { + // Only trigger a deprecation notice when there is an id found + @trigger_error( + 'The use of the id= parameter within the webcron scheduler is deprecated and will be replaced by the taskid= parameter starting with 6.0.0' + . 'You should already upgrade to the new taskid= parameter starting with __DEPLOY_VERSION__', + E_USER_DEPRECATED + ); + } + + if ($taskId) { + $records[] = $scheduler->fetchTaskRecord($taskId); + } else { + $filters = $scheduler::TASK_QUEUE_FILTERS; + $listConfig = $scheduler::TASK_QUEUE_LIST_CONFIG; + + // Make sure we only get one task at the time + $listConfig['limit'] = 1; + + // Get tasks to run + $records = $scheduler->fetchTaskRecords($filters, $listConfig); + } + + if (\count($records) === 0) { + // No tasks to run + return; + } + + foreach ($records as $record) { + $task = $this->runScheduler($record->id); + + if (!empty($task) && !empty($task->getContent()['exception'])) { + throw $task->getContent()['exception']; + } } } From 1341045521aaa1b70045971ca5b3791bc823db56 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Sat, 20 Jul 2024 21:31:32 +0200 Subject: [PATCH 02/13] Update ScheduleRunner.php --- .../schedulerunner/src/Extension/ScheduleRunner.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index c27081ef58839..815adaf0f02da 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -217,16 +217,6 @@ public function runWebCron(Event $event) $scheduler = new Scheduler(); - if ($id) - { - // Only trigger a deprecation notice when there is an id found - @trigger_error( - 'The use of the id= parameter within the webcron scheduler is deprecated and will be replaced by the taskid= parameter starting with 6.0.0' - . 'You should already upgrade to the new taskid= parameter starting with __DEPLOY_VERSION__', - E_USER_DEPRECATED - ); - } - if ($taskId) { $records[] = $scheduler->fetchTaskRecord($taskId); } else { From 54d0643f6caeb63bbba0f181ce69e6cb90b0ed91 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Sun, 21 Jul 2024 11:58:23 +0200 Subject: [PATCH 03/13] Update ScheduleRunner.php --- .../src/Extension/ScheduleRunner.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 815adaf0f02da..8be1d03838bd2 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -204,17 +204,20 @@ public function runWebCron(Event $event) $input = $this->getApplication()->getInput(); - // The "id" parameter will be removed with 6.0 as that behavior is broken + // The "id" parameter will be removed with 6.0 $id = (int) $input->getInt('id', 0); $taskId = (int) $input->getInt('taskid', $id); - /** - * Yes we are aware that the current behavior is broken meaning as long as there is no ID passed via - * the URL the current code will still fail. But we need to keep that behavior for B/C reasons. Starting - * with 6.0 only taskid will be supported and when the cron is triggered without taskid it will trigger - * the next item available the broken behavior with will be removed. - */ - + if ($id) + { + // Only trigger a deprecation notice when there is an id found + @trigger_error( + 'The use of the id= parameter within the webcron scheduler is deprecated and will be replaced by the taskid= parameter starting with 6.0.0' + . 'You should already upgrade to the new taskid= parameter starting with __DEPLOY_VERSION__', + E_USER_DEPRECATED + ); + } + $scheduler = new Scheduler(); if ($taskId) { From 342d463055cae6be5e4d42eeb8a52617dc69c47c Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Thu, 25 Jul 2024 22:12:55 +0200 Subject: [PATCH 04/13] Apply suggestions from code review PHP CS --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 8be1d03838bd2..3885ba1ce36d6 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -208,8 +208,7 @@ public function runWebCron(Event $event) $id = (int) $input->getInt('id', 0); $taskId = (int) $input->getInt('taskid', $id); - if ($id) - { + if ($id) { // Only trigger a deprecation notice when there is an id found @trigger_error( 'The use of the id= parameter within the webcron scheduler is deprecated and will be replaced by the taskid= parameter starting with 6.0.0' From ae57aed352a6af74e56f57c9e72930120ba6f08a Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Thu, 25 Jul 2024 22:18:04 +0200 Subject: [PATCH 05/13] revert id -> taskid change as discssed with @hackwar --- .../src/Extension/ScheduleRunner.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 3885ba1ce36d6..18121a783bf4b 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -202,21 +202,9 @@ public function runWebCron(Event $event) throw new \Exception($this->getApplication()->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } - $input = $this->getApplication()->getInput(); - - // The "id" parameter will be removed with 6.0 - $id = (int) $input->getInt('id', 0); - $taskId = (int) $input->getInt('taskid', $id); - - if ($id) { - // Only trigger a deprecation notice when there is an id found - @trigger_error( - 'The use of the id= parameter within the webcron scheduler is deprecated and will be replaced by the taskid= parameter starting with 6.0.0' - . 'You should already upgrade to the new taskid= parameter starting with __DEPLOY_VERSION__', - E_USER_DEPRECATED - ); - } - + // Check whether we have passed an taskId via URL parameter + $taskId = (int) $this->getApplication()->getInput()->getInt('id', $id); + $scheduler = new Scheduler(); if ($taskId) { From 8e89b7639ebfd9d1ecfc2c9d09ef9991fbc24fe4 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Thu, 25 Jul 2024 22:20:38 +0200 Subject: [PATCH 06/13] Update administrator/language/en-GB/com_scheduler.ini --- administrator/language/en-GB/com_scheduler.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/com_scheduler.ini b/administrator/language/en-GB/com_scheduler.ini index 18c442f67e2f6..f5eee988a7c2c 100644 --- a/administrator/language/en-GB/com_scheduler.ini +++ b/administrator/language/en-GB/com_scheduler.ini @@ -9,7 +9,7 @@ COM_SCHEDULER_CONFIG_FIELDSET_LAZY_SCHEDULER_DESC="Configure how site visits tri COM_SCHEDULER_CONFIG_FIELDSET_LAZY_SCHEDULER_LABEL="Lazy Scheduler" COM_SCHEDULER_CONFIG_GENERATE_WEBCRON_KEY_DESC="The webcron needs a protection key before it is functional. Saving this configuration will autogenerate the key." COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_KEY_LABEL="Global Key" -COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_DESC="By default, requesting this base link will only run tasks due for execution. To execute a specific task, use the task's ID as a query parameter appended to the URL: BASE_URL&taskid=<taskId>" +COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_DESC="By default, requesting this base link will only run tasks due for execution. To execute a specific task, use the task's ID as a query parameter appended to the URL: BASE_URL&id=<taskId>" COM_SCHEDULER_CONFIG_GLOBAL_WEBCRON_LINK_LABEL="Webcron Link (Base)" COM_SCHEDULER_CONFIG_HASH_PROTECTION_DESC="If enabled, tasks will only be triggered when URLs have the scheduler hash as a parameter." COM_SCHEDULER_CONFIG_LAZY_SCHEDULER_ENABLED_DESC="If disabled, scheduled tasks will not be triggered by visitors on the site.
It is recommended to DISABLE the Lazy Scheduler, if triggering with native cron." From 060a945e238d3531eeb57df281036d0e1dbf86b7 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Fri, 26 Jul 2024 22:09:38 +0200 Subject: [PATCH 07/13] Update plugins/system/schedulerunner/src/Extension/ScheduleRunner.php --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 18121a783bf4b..bf4f432973657 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -203,7 +203,7 @@ public function runWebCron(Event $event) } // Check whether we have passed an taskId via URL parameter - $taskId = (int) $this->getApplication()->getInput()->getInt('id', $id); + $taskId = $this->getApplication()->getInput()->getInt('id', 0); $scheduler = new Scheduler(); From 39c66a0ce8baa50de42df1b9e2fcbb34547c79e6 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Fri, 26 Jul 2024 22:51:16 +0200 Subject: [PATCH 08/13] Update plugins/system/schedulerunner/src/Extension/ScheduleRunner.php Co-authored-by: Richard Fath --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index bf4f432973657..c5d970f7ef477 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -202,7 +202,7 @@ public function runWebCron(Event $event) throw new \Exception($this->getApplication()->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } - // Check whether we have passed an taskId via URL parameter + // Check whether we have passed a taskId via URL parameter $taskId = $this->getApplication()->getInput()->getInt('id', 0); $scheduler = new Scheduler(); From 5470d52c315e74d71472fb9b4908d2fc03fcdbc6 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Sat, 27 Jul 2024 14:49:17 +0200 Subject: [PATCH 09/13] Update plugins/system/schedulerunner/src/Extension/ScheduleRunner.php --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index c5d970f7ef477..c5ea32a68b519 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -204,7 +204,6 @@ public function runWebCron(Event $event) // Check whether we have passed a taskId via URL parameter $taskId = $this->getApplication()->getInput()->getInt('id', 0); - $scheduler = new Scheduler(); if ($taskId) { From fd35d739d36dc46abc4486ad1694c287f4685bed Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Sat, 27 Jul 2024 16:39:13 +0200 Subject: [PATCH 10/13] Update plugins/system/schedulerunner/src/Extension/ScheduleRunner.php Co-authored-by: Richard Fath --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index c5ea32a68b519..33dbcf11e521d 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -203,7 +203,7 @@ public function runWebCron(Event $event) } // Check whether we have passed a taskId via URL parameter - $taskId = $this->getApplication()->getInput()->getInt('id', 0); + $taskId = $this->getApplication()->getInput()->getInt('id', 0); $scheduler = new Scheduler(); if ($taskId) { From 0c055842e8c715b1ba1e9c5eb7da66b09c5dddec Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Tue, 17 Dec 2024 12:50:17 +0100 Subject: [PATCH 11/13] Update ScheduleRunner.php --- .../src/Extension/ScheduleRunner.php | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 33dbcf11e521d..4edccfb79c447 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -202,34 +202,14 @@ public function runWebCron(Event $event) throw new \Exception($this->getApplication()->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } - // Check whether we have passed a taskId via URL parameter - $taskId = $this->getApplication()->getInput()->getInt('id', 0); - $scheduler = new Scheduler(); + // Check whether there is an id passed via the URL + $id = (int) $this->getApplication()->getInput()->getInt('id', 0); - if ($taskId) { - $records[] = $scheduler->fetchTaskRecord($taskId); - } else { - $filters = $scheduler::TASK_QUEUE_FILTERS; - $listConfig = $scheduler::TASK_QUEUE_LIST_CONFIG; - - // Make sure we only get one task at the time - $listConfig['limit'] = 1; + // When the id is set to 0 the next task is executed + $task = $this->runScheduler($id); - // Get tasks to run - $records = $scheduler->fetchTaskRecords($filters, $listConfig); - } - - if (\count($records) === 0) { - // No tasks to run - return; - } - - foreach ($records as $record) { - $task = $this->runScheduler($record->id); - - if (!empty($task) && !empty($task->getContent()['exception'])) { - throw $task->getContent()['exception']; - } + if (!empty($task) && !empty($task->getContent()['exception'])) { + throw $task->getContent()['exception']; } } From 440682bde00ce316397e7ae54fc4f5348aa03b5d Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Wed, 18 Dec 2024 08:38:47 +0100 Subject: [PATCH 12/13] Update ScheduleRunner.php --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 4edccfb79c447..6025b1f3a136e 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -172,8 +172,7 @@ public function runLazyCron(EventInterface $e) /** * This method is responsible for the WebCron functionality of the Scheduler component.
* Acting on a `com_ajax` call, this method can work in two ways: - * 1. If no Task ID is specified, it triggers the Scheduler to run the next task in - * the task queue. + * 1. If no Task ID is specified, it triggers the Scheduler to run the next task in the task queue. * 2. If a Task ID is specified, it fetches the task (if it exists) from the Scheduler API and executes it.
* * URL query parameters: From 1ae95bf287a5f3618b99f07f7f0ea985cbbadf69 Mon Sep 17 00:00:00 2001 From: Tobias Zulauf Date: Wed, 18 Dec 2024 09:12:47 +0100 Subject: [PATCH 13/13] remove the
--- .../system/schedulerunner/src/Extension/ScheduleRunner.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 6025b1f3a136e..f462a9ebac0da 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -170,10 +170,10 @@ public function runLazyCron(EventInterface $e) } /** - * This method is responsible for the WebCron functionality of the Scheduler component.
+ * This method is responsible for the WebCron functionality of the Scheduler component. * Acting on a `com_ajax` call, this method can work in two ways: * 1. If no Task ID is specified, it triggers the Scheduler to run the next task in the task queue. - * 2. If a Task ID is specified, it fetches the task (if it exists) from the Scheduler API and executes it.
+ * 2. If a Task ID is specified, it fetches the task (if it exists) from the Scheduler API and executes it. * * URL query parameters: * - `hash` string (required) Webcron hash (from the Scheduler component configuration).