Skip to content

Commit

Permalink
apply code changes as mentioned in joomla#36725. Based on 5.1-dev
Browse files Browse the repository at this point in the history
applied suggested adjustments
  • Loading branch information
hans2103 committed Jan 3, 2024
1 parent 57f62a2 commit 49d1515
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 49 deletions.
4 changes: 2 additions & 2 deletions administrator/components/com_scheduler/access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<action name="core.delete" title="JACTION_DELETE" />
<action name="core.edit" title="JACTION_EDIT" />
<action name="core.edit.state" title="JACTION_EDITSTATE" />
<action name="core.testrun" title="COM_SCHEDULER_PERMISSION_TESTRUN" />
<action name="core.runtest" title="COM_SCHEDULER_PERMISSION_RUN_TEST" />
</section>
<section name="task">
<action name="core.delete" title="JACTION_DELETE" />
<action name="core.edit" title="JACTION_EDIT" />
<action name="core.edit.state" title="JACTION_EDITSTATE" />
<action name="core.testrun" title="COM_SCHEDULER_PERMISSION_TESTRUN" />
<action name="core.runtest" title="COM_SCHEDULER_PERMISSION_RUN_TEST" />
</section>
</access>
28 changes: 14 additions & 14 deletions administrator/components/com_scheduler/tmpl/tasks/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
?>

<form action="<?php echo Route::_('index.php?option=com_scheduler&view=tasks'); ?>" method="post" name="adminForm"
Expand Down Expand Up @@ -130,7 +130,7 @@ class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo HTMLHelper::_('searchtools.sort', 'COM_SCHEDULER_LAST_RUN_DATE', 'a.last_execution', $listDirn, $listOrder) ?>
</th>

<!-- Test task -->
<!-- Run test -->
<th scope="col" class="d-none d-md-table-cell">
<?php echo Text::_('COM_SCHEDULER_TEST_TASK'); ?>
</th>
Expand Down Expand Up @@ -242,9 +242,9 @@ class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="

<!-- Test task -->
<td class="small d-none d-md-table-cell">
<button type="button" class="btn btn-sm btn-warning" <?php echo $item->state < 0 ? 'disabled' : ''; ?> data-id="<?php echo (int) $item->id; ?>" data-title="<?php echo htmlspecialchars($item->title); ?>" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#scheduler-test-modal">
<button type="button" class="btn btn-sm btn-warning" <?php echo $item->state < 0 ? 'disabled' : ''; ?> data-id="<?php echo (int) $item->id; ?>" data-title="<?php echo htmlspecialchars($item->title); ?>" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#scheduler-task-modal">
<span class="fa fa-play fa-sm me-2"></span>
<?php echo Text::_('COM_SCHEDULER_TEST_RUN'); ?>
<?php echo Text::_('COM_SCHEDULER_RUN_TEST'); ?>
</button>
</td>

Expand Down Expand Up @@ -272,14 +272,14 @@ class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="
// Load the pagination. (@todo: testing)
echo $this->pagination->getListFooter();

// Modal for test runs
// Modal for run test
$modalparams = [
'title' => '',
];

$modalbody = '<div class="p-3"></div>';

echo HTMLHelper::_('bootstrap.renderModal', 'scheduler-test-modal', $modalparams, $modalbody);
echo HTMLHelper::_('bootstrap.renderModal', 'scheduler-task-modal', $modalparams, $modalbody);

?>

Expand Down
33 changes: 21 additions & 12 deletions administrator/language/en-GB/com_scheduler.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br>%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."
Expand All @@ -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:<br>%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:<br>%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!<br>It's likely that the provider plugin was removed or disabled."
Expand Down
4 changes: 2 additions & 2 deletions build/media_source/com_scheduler/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<h4 class="scheduler-headline">${Joomla.Text._('COM_SCHEDULER_TEST_RUN_TASK')}</h4>
<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_STARTED')}</div>
<h4 class="scheduler-headline">${Joomla.Text._('COM_SCHEDULER_RUN_TEST_TASK')}</h4>
<div>${Joomla.Text._('COM_SCHEDULER_RUN_TASK_STATUS_STARTED')}</div>
<div class="mt-3 text-center"><span class="fa fa-spinner fa-spin fa-lg"></span></div>
`;

Expand All @@ -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({
Expand All @@ -55,28 +55,28 @@ const initRunner = () => {
const output = JSON.parse(data);

if (output && output.success && output.data) {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED')}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_COMPLETED')}</div>`;

if (output.data.duration > 0) {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_DURATION').replace('%s', output.data.duration.toFixed(2))}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_DURATION').replace('%s', output.data.duration.toFixed(2))}</div>`;
}

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 += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', result)}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', result)}</div>`;
}
} else {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status))}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED')}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status))}</div>`;
}
},
onError: (xhr) => {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_STATUS_TERMINATED')}</div>`;

const msg = Joomla.ajaxErrorsMessages(xhr);
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', msg.error)}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_RUN_TEST_OUTPUT').replace('%s', msg.error)}</div>`;
},
});
};
Expand Down
12 changes: 6 additions & 6 deletions plugins/system/schedulerunner/src/Extension/ScheduleRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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', '');
Expand All @@ -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).
*
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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.
Expand Down

0 comments on commit 49d1515

Please sign in to comment.