From 49d1515252a68ebc44151a55791f6e55d28b2188 Mon Sep 17 00:00:00 2001 From: Hans Kuijpers Date: Wed, 3 Jan 2024 13:08:57 +0100 Subject: [PATCH] apply code changes as mentioned in #36725. Based on 5.1-dev applied suggested adjustments --- .../components/com_scheduler/access.xml | 4 +-- .../com_scheduler/tmpl/tasks/default.php | 28 ++++++++-------- .../language/en-GB/com_scheduler.ini | 33 ++++++++++++------- .../com_scheduler/joomla.asset.json | 4 +-- ...task.es6.js => admin-view-run-task.es6.js} | 26 +++++++-------- .../src/Extension/ScheduleRunner.php | 12 +++---- 6 files changed, 58 insertions(+), 49 deletions(-) rename build/media_source/com_scheduler/js/{admin-view-run-test-task.es6.js => admin-view-run-task.es6.js} (79%) diff --git a/administrator/components/com_scheduler/access.xml b/administrator/components/com_scheduler/access.xml index 203b6eddf5533..518d4861c1ee3 100644 --- a/administrator/components/com_scheduler/access.xml +++ b/administrator/components/com_scheduler/access.xml @@ -8,12 +8,12 @@ - +
- +
diff --git a/administrator/components/com_scheduler/tmpl/tasks/default.php b/administrator/components/com_scheduler/tmpl/tasks/default.php index 9a04f76691ff3..3096adbac0efa 100644 --- a/administrator/components/com_scheduler/tmpl/tasks/default.php +++ b/administrator/components/com_scheduler/tmpl/tasks/default.php @@ -27,16 +27,16 @@ $wa = $this->document->getWebAssetManager(); $wa->useScript('table.columns') ->useScript('multiselect') - ->useScript('com_scheduler.test-task') + ->useScript('com_scheduler.run-test') ->useStyle('com_scheduler.admin-view-tasks-css'); -Text::script('COM_SCHEDULER_TEST_RUN_TITLE'); -Text::script('COM_SCHEDULER_TEST_RUN_TASK'); -Text::script('COM_SCHEDULER_TEST_RUN_DURATION'); -Text::script('COM_SCHEDULER_TEST_RUN_OUTPUT'); -Text::script('COM_SCHEDULER_TEST_RUN_STATUS_STARTED'); -Text::script('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED'); -Text::script('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED'); +Text::script('COM_SCHEDULER_RUN_TEST_TITLE'); +Text::script('COM_SCHEDULER_RUN_TEST_TASK'); +Text::script('COM_SCHEDULER_RUN_TEST_DURATION'); +Text::script('COM_SCHEDULER_RUN_TEST_OUTPUT'); +Text::script('COM_SCHEDULER_RUN_TEST_STATUS_STARTED'); +Text::script('COM_SCHEDULER_RUN_TEST_STATUS_COMPLETED'); +Text::script('COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED'); Text::script('JLIB_JS_AJAX_ERROR_OTHER'); Text::script('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT'); Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT'); @@ -63,7 +63,7 @@ HTMLHelper::_('draggablelist.draggable'); } -$this->document->addScriptOptions('com_scheduler.test-task.token', Session::getFormToken()); +$this->getDocument()->addScriptOptions('com_scheduler.run-test.token', Session::getFormToken()); ?>
- + @@ -242,9 +242,9 @@ class="js-draggable" data-url="" data-direction=" - @@ -272,14 +272,14 @@ class="js-draggable" data-url="" data-direction=" // Load the pagination. (@todo: testing) echo $this->pagination->getListFooter(); - // Modal for test runs + // Modal for run test $modalparams = [ 'title' => '', ]; $modalbody = '
'; - echo HTMLHelper::_('bootstrap.renderModal', 'scheduler-test-modal', $modalparams, $modalbody); + echo HTMLHelper::_('bootstrap.renderModal', 'scheduler-task-modal', $modalparams, $modalbody); ?> diff --git a/administrator/language/en-GB/com_scheduler.ini b/administrator/language/en-GB/com_scheduler.ini index 4bbc9f5ef82f4..fdf198fa7891f 100644 --- a/administrator/language/en-GB/com_scheduler.ini +++ b/administrator/language/en-GB/com_scheduler.ini @@ -104,9 +104,18 @@ COM_SCHEDULER_OPTION_EXECUTION_MANUAL_LABEL="Manual Execution" COM_SCHEDULER_OPTION_ORPHANED_HIDE="Hide Orphaned" COM_SCHEDULER_OPTION_ORPHANED_ONLY="Only Orphaned" COM_SCHEDULER_OPTION_ORPHANED_SHOW="Show Orphaned" -COM_SCHEDULER_PERMISSION_TESTRUN="Test task" +COM_SCHEDULER_PERMISSION_RUN_TEST="Run test" +COM_SCHEDULER_PERMISSION_TESTRUN="Test task" ; Deprecated removed with 6.0 COM_SCHEDULER_ROUTINE_LOG_PREFIX="Task> " COM_SCHEDULER_RUNNING_SINCE="Running since %s" +COM_SCHEDULER_RUN_TEST="Run Test" +COM_SCHEDULER_RUN_TEST_DURATION="Duration: %s seconds" +COM_SCHEDULER_RUN_TEST_OUTPUT="Output:
%s" +COM_SCHEDULER_RUN_TEST_STATUS_COMPLETED="Status: Completed" +COM_SCHEDULER_RUN_TEST_STATUS_STARTED="Status: Started" +COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED="Status: Terminated" +COM_SCHEDULER_RUN_TEST_TASK="Task: \"%s\"" +COM_SCHEDULER_RUN_TEST_TITLE="Run task (ID: %d)" COM_SCHEDULER_SCHEDULER="Scheduler" COM_SCHEDULER_SCHEDULER_TASK_COMPLETE="Successfully finished task#%1$02d in %2$.2f (net %3$.2f) seconds." COM_SCHEDULER_SCHEDULER_TASK_LOCKED="task#%1$02d is locked." @@ -128,17 +137,17 @@ COM_SCHEDULER_TASK_PRIORITY_ASC="Task Priority ascending" COM_SCHEDULER_TASK_PRIORITY_DESC="Task Priority descending" COM_SCHEDULER_TASK_ROUTINE_EXCEPTION="Routine threw exception: %1$s" COM_SCHEDULER_TASK_TYPE="Task Type" -COM_SCHEDULER_TASK_TYPE_ASC="Task Type ascending" -COM_SCHEDULER_TASK_TYPE_DESC="Task Type descending" -COM_SCHEDULER_TEST_RUN="Run Test" -COM_SCHEDULER_TEST_RUN_DURATION="Duration: %s seconds" -COM_SCHEDULER_TEST_RUN_OUTPUT="Output:
%s" -COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED="Status: Completed" -COM_SCHEDULER_TEST_RUN_STATUS_STARTED="Status: Started" -COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED="Status: Terminated" -COM_SCHEDULER_TEST_RUN_TASK="Task: \"%s\"" -COM_SCHEDULER_TEST_RUN_TITLE="Test task (ID: %d)" -COM_SCHEDULER_TEST_TASK="Test Task" +COM_SCHEDULER_TASK_TYPE_ASC="Task type ascending" +COM_SCHEDULER_TASK_TYPE_DESC="Task type descending" +COM_SCHEDULER_TEST_RUN="Run Test" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_DURATION="Duration: %s seconds" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_OUTPUT="Output:
%s" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED="Status: Completed" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_STATUS_STARTED="Status: Started" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED="Status: Terminated" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_TASK="Task: \"%s\"" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_RUN_TITLE="Test task (ID: %d)" ; Deprecated removed with 6.0 +COM_SCHEDULER_TEST_TASK="Test Task" ; Deprecated removed with 6.0 COM_SCHEDULER_TOOLBAR_UNLOCK="Unlock" COM_SCHEDULER_TYPE_CHOOSE="Select a Task type" COM_SCHEDULER_WARNING_EXISTING_TASK_TYPE_NOT_FOUND="The task routine for this task could not be found!
It's likely that the provider plugin was removed or disabled." diff --git a/build/media_source/com_scheduler/joomla.asset.json b/build/media_source/com_scheduler/joomla.asset.json index 0a02038b91012..d86d459a9a86c 100644 --- a/build/media_source/com_scheduler/joomla.asset.json +++ b/build/media_source/com_scheduler/joomla.asset.json @@ -6,9 +6,9 @@ "license": "GNU General Public License version 2 or later; see LICENSE.txt", "assets": [ { - "name": "com_scheduler.test-task", + "name": "com_scheduler.run-task.es6", "type": "script", - "uri": "com_scheduler/admin-view-run-test-task.js", + "uri": "com_scheduler/admin-view-run-task-es6.js", "dependencies": [ "core" ], diff --git a/build/media_source/com_scheduler/js/admin-view-run-test-task.es6.js b/build/media_source/com_scheduler/js/admin-view-run-task.es6.js similarity index 79% rename from build/media_source/com_scheduler/js/admin-view-run-test-task.es6.js rename to build/media_source/com_scheduler/js/admin-view-run-task.es6.js index 6981c9786f975..6ccf7f9f332ee 100644 --- a/build/media_source/com_scheduler/js/admin-view-run-test-task.es6.js +++ b/build/media_source/com_scheduler/js/admin-view-run-task.es6.js @@ -17,14 +17,14 @@ if (!window.Joomla) { const initRunner = () => { const paths = Joomla.getOptions('system.paths'); - const token = Joomla.getOptions('com_scheduler.test-task.token'); - const uri = `${paths ? `${paths.base}/index.php` : window.location.pathname}?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d${token ? `&${token}=1` : ''}`; - const modal = document.getElementById('scheduler-test-modal'); + const token = Joomla.getOptions('com_scheduler.run-test.token'); + const uri = `${paths ? `${paths.base}/index.php` : window.location.pathname}?option=com_ajax&format=json&plugin=RunSchedulerTask&group=system&id=%d${token ? `&${token}=1` : ''}`; + const modal = document.getElementById('scheduler-task-modal'); // Task output template const template = ` -

${Joomla.Text._('COM_SCHEDULER_TEST_RUN_TASK')}

-
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_STARTED')}
+

${Joomla.Text._('COM_SCHEDULER_RUN_TEST_TASK')}

+
${Joomla.Text._('COM_SCHEDULER_RUN_TASK_STATUS_STARTED')}
`; @@ -42,7 +42,7 @@ const initRunner = () => { const id = parseInt(button.dataset.id, 10); const { title } = button.dataset; - modal.querySelector('.modal-title').innerHTML = Joomla.Text._('COM_SCHEDULER_TEST_RUN_TITLE').replace('%d', id.toString()); + modal.querySelector('.modal-title').innerHTML = Joomla.Text._('COM_SCHEDULER_RUN_TEST_TITLE').replace('%d', id.toString()); modal.querySelector('.modal-body > div').innerHTML = template.replace('%s', title); Joomla.request({ @@ -55,28 +55,28 @@ const initRunner = () => { const output = JSON.parse(data); if (output && output.success && output.data) { - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED')}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_COMPLETED')}
`; if (output.data.duration > 0) { - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_DURATION').replace('%s', output.data.duration.toFixed(2))}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_DURATION').replace('%s', output.data.duration.toFixed(2))}
`; } if (output.data.output) { const result = Joomla.sanitizeHtml((output.data.output), null, sanitiseTaskOutput); // Can use an indication for non-0 exit codes - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', result)}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', result)}
`; } } else { - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}
`; - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status))}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED')}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status))}
`; } }, onError: (xhr) => { - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED')}
`; const msg = Joomla.ajaxErrorsMessages(xhr); - modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', msg.error)}
`; + modal.querySelector('.modal-body > div').innerHTML += `
${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', msg.error)}
`; }, }); }; diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 143272585d5f6..a76041914df91 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -144,7 +144,7 @@ public function injectLazyJS(EventInterface $event): void * * @throws \Exception */ - public function runLazyCron(EventInterface $e) + public function runLazyCron(EventInterface $e): void { $config = ComponentHelper::getParams('com_scheduler'); @@ -188,7 +188,7 @@ public function runLazyCron(EventInterface $e) * * @throws \Exception */ - public function runWebCron(Event $event) + public function runWebCron(Event $event): void { $config = ComponentHelper::getParams('com_scheduler'); $hash = $config->get('webcron.key', ''); @@ -212,7 +212,7 @@ public function runWebCron(Event $event) } /** - * This method is responsible for the "test run" functionality in the Scheduler administrator backend interface. + * This method is responsible for the "run test" functionality in the Scheduler administrator backend interface. * Acting on a `com_ajax` call, this method requires the URL to have a `id` query parameter (corresponding to an * existing Task ID). * @@ -224,7 +224,7 @@ public function runWebCron(Event $event) * * @throws \Exception */ - public function runTestCron(Event $event) + public function runTestCron(Event $event): void { if (!Session::checkToken('GET')) { return; @@ -235,7 +235,7 @@ public function runTestCron(Event $event) $user = $this->getApplication()->getIdentity(); - if (empty($id) || !$user->authorise('core.testrun', 'com_scheduler.task.' . $id)) { + if (empty($id) || !$user->authorise('core.runtest', 'com_scheduler.task.' . $id)) { throw new \Exception($this->getApplication()->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } @@ -260,7 +260,7 @@ public function runTestCron(Event $event) } else { /** * Placeholder result, but the idea is if we failed to fetch the task, it's likely because another task was - * already running. This is a fair assumption if this test run was triggered through the administrator backend, + * already running. This is a fair assumption if this run test was triggered through the administrator backend, * so we know the task probably exists and is either enabled/disabled (not trashed). */ // @todo language constant + review if this is done right.