diff --git a/classes/local/table/process_errors_table.php b/classes/local/table/process_errors_table.php index d7d0f9765c013363480d9f8ad26e20e9391bf004..545a883dc689e77a9c43fa2aabb98ca6351a83ef 100644 --- a/classes/local/table/process_errors_table.php +++ b/classes/local/table/process_errors_table.php @@ -95,9 +95,9 @@ class process_errors_table extends \table_sql { public function col_error($row) { return "<details><summary>" . nl2br(htmlentities($row->errormessage)) . - "</summary>" . + "</summary><code>" . nl2br(htmlentities($row->errortrace)) . - "</details>"; + "</code></details>"; } /** @@ -165,6 +165,27 @@ class process_errors_table extends \table_sql { return ''; } + /** + * Show custom nothing to display message. + * @return void + */ + public function print_nothing_to_display() { + global $OUTPUT; + + // Render the dynamic table header. + echo $this->get_dynamic_table_html_start(); + + // Render button to allow user to reset table preferences. + echo $this->render_reset_button(); + + $this->print_initials_bar(); + + echo $OUTPUT->heading(get_string('noprocesserrors', 'tool_lifecycle')); + + // Render the dynamic table footer. + echo $this->get_dynamic_table_html_end(); + } + /** * Hook that can be overridden in child classes to wrap a table in a form * for example. Called only when there is data to display and not diff --git a/classes/task/lifecycle_error_notify_task.php b/classes/task/lifecycle_error_notify_task.php new file mode 100644 index 0000000000000000000000000000000000000000..7c15fa866f42e296f45d657f4813e29730f8b227 --- /dev/null +++ b/classes/task/lifecycle_error_notify_task.php @@ -0,0 +1,69 @@ +<?php +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Scheduled task for notify admin upon process errors + * + * @package tool_lifecycle + * @copyright 2022 Justus Dieckmann WWU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace tool_lifecycle\task; + +defined('MOODLE_INTERNAL') || die; + +/** + * Scheduled task for notify admin upon process errors + * + * @package tool_lifecycle + * @copyright 2022 Justus Dieckmann WWU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class lifecycle_error_notify_task extends \core\task\scheduled_task { + + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + * @throws \coding_exception + */ + public function get_name() { + return get_string('lifecycle_error_notify_task', 'tool_lifecycle'); + } + + /** + * Do the job. + */ + public function execute() { + global $DB, $CFG; + + $errorcount = $DB->count_records('tool_lifecycle_proc_error'); + + if (!$errorcount) { + return; + } + + $obj = new \stdClass(); + $obj->amount = $errorcount; + $obj->url = $CFG->wwwroot . '/admin/tool/lifecycle/errors.php'; + + email_to_user(get_admin(), \core_user::get_noreply_user(), + get_string('notifyerrorsemailsubject', 'tool_lifecycle', $obj), + get_string('notifyerrorsemailcontent', 'tool_lifecycle', $obj), + get_string('notifyerrorsemailcontenthtml', 'tool_lifecycle', $obj), + ); + } +} diff --git a/db/tasks.php b/db/tasks.php index f708e82cbe5ce7aa4347e05f7cec5acf579a3842..d061305a9538a25298d8ca90ba16e938ed48324f 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -44,5 +44,14 @@ $tasks = array( 'day' => '*', 'month' => '*', 'dayofweek' => '0', - ) + ), + array( + 'classname' => 'tool_lifecycle\task\lifecycle_error_notify_task', + 'blocking' => 0, + 'minute' => 'R', + 'hour' => '5', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '0', + ), ); diff --git a/errors.php b/errors.php index 3f8032c1356721150a3bd622af6a8d692bbc522f..40c80bccf471728ec59bca390772f38eb9a26469 100644 --- a/errors.php +++ b/errors.php @@ -50,6 +50,8 @@ if ($action) { foreach ($ids as $id) { process_manager::rollback_process_after_error($id); } + } else { + throw new coding_exception("action must be either 'proceed' or 'rollback'"); } redirect($PAGE->url); } diff --git a/lang/de/tool_lifecycle.php b/lang/de/tool_lifecycle.php index 6409cc02877d8c3e55d17a1b40a0985858768558..17706b0949a933cee59195a487d53f2f62ae3fe3 100644 --- a/lang/de/tool_lifecycle.php +++ b/lang/de/tool_lifecycle.php @@ -177,5 +177,12 @@ $string['process_proceeded_event'] = 'Ein Prozess wurde fortgeführt'; $string['process_rollback_event'] = 'Ein Prozess wurde zurückgesetzt'; $string['courseid'] = 'Kurs-ID'; -$string['process_errors_header'] = 'Prozessfehler'; +$string['process_errors_header'] = 'Fehlermanagement'; +$string['proceed'] = 'Fortfahren'; $string['forselected'] = 'Für alle ausgewählten Prozesse'; +$string['noprocesserrors'] = 'Es gibt keine fehlerhaften Prozesse, die behandelt werden müssen!'; + +$string['lifecycle_error_notify_task'] = 'Benachrichtigt die Administratoren bei Fehlern in tool_lifecycle-Prozessen.'; +$string['notifyerrorsemailsubject'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!'; +$string['notifyerrorsemailcontent'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.'; +$string['notifyerrorsemailcontenthtml'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!<br>Bitte besuchen Sie <a href="{$a->url}">die Übersichtsseite</a>.'; diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php index 25aba077bd8646f1eeb41ba77b8057484d137864..b1149de50b89545ab15289a2480f7eda6b809548 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -212,7 +212,13 @@ $string['delays_for_workflow'] = 'Delays for "{$a}"'; $string['delete_all_delays'] = 'Delete all delays'; $string['courseid'] = 'Course ID'; -$string['process_errors_header'] = 'Process errors'; +$string['process_errors_header'] = 'Error handling'; $string['proceed'] = 'Proceed'; $string['rollback'] = 'Rollback'; $string['forselected'] = 'For all selected processes'; +$string['noprocesserrors'] = 'There are no process errors to handle!'; + +$string['lifecycle_error_notify_task'] = 'Notify the admin upon errors in tool_lifecycle processes'; +$string['notifyerrorsemailsubject'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!'; +$string['notifyerrorsemailcontent'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.'; +$string['notifyerrorsemailcontenthtml'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!<br>Please review them at the <a href="{$a->url}">error handling overview</a>.';