Skip to content

Commit ca75227

Browse files
Implement admin notification on process errors
And other small fixes
1 parent 8054270 commit ca75227

File tree

6 files changed

+119
-5
lines changed

6 files changed

+119
-5
lines changed

classes/local/table/process_errors_table.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function __construct() {
9595
public function col_error($row) {
9696
return "<details><summary>" .
9797
nl2br(htmlentities($row->errormessage)) .
98-
"</summary>" .
98+
"</summary><code>" .
9999
nl2br(htmlentities($row->errortrace)) .
100-
"</details>";
100+
"</code></details>";
101101
}
102102

103103
/**
@@ -165,6 +165,27 @@ protected function show_hide_link($column, $index) {
165165
return '';
166166
}
167167

168+
/**
169+
* Show custom nothing to display message.
170+
* @return void
171+
*/
172+
public function print_nothing_to_display() {
173+
global $OUTPUT;
174+
175+
// Render the dynamic table header.
176+
echo $this->get_dynamic_table_html_start();
177+
178+
// Render button to allow user to reset table preferences.
179+
echo $this->render_reset_button();
180+
181+
$this->print_initials_bar();
182+
183+
echo $OUTPUT->heading(get_string('noprocesserrors', 'tool_lifecycle'));
184+
185+
// Render the dynamic table footer.
186+
echo $this->get_dynamic_table_html_end();
187+
}
188+
168189
/**
169190
* Hook that can be overridden in child classes to wrap a table in a form
170191
* for example. Called only when there is data to display and not
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Scheduled task for notify admin upon process errors
19+
*
20+
* @package tool_lifecycle
21+
* @copyright 2022 Justus Dieckmann WWU
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace tool_lifecycle\task;
25+
26+
defined('MOODLE_INTERNAL') || die;
27+
28+
/**
29+
* Scheduled task for notify admin upon process errors
30+
*
31+
* @package tool_lifecycle
32+
* @copyright 2022 Justus Dieckmann WWU
33+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34+
*/
35+
class lifecycle_error_notify_task extends \core\task\scheduled_task {
36+
37+
/**
38+
* Get a descriptive name for this task (shown to admins).
39+
*
40+
* @return string
41+
* @throws \coding_exception
42+
*/
43+
public function get_name() {
44+
return get_string('lifecycle_error_notify_task', 'tool_lifecycle');
45+
}
46+
47+
/**
48+
* Do the job.
49+
*/
50+
public function execute() {
51+
global $DB, $CFG;
52+
53+
$errorcount = $DB->count_records('tool_lifecycle_proc_error');
54+
55+
if (!$errorcount) {
56+
return;
57+
}
58+
59+
$obj = new \stdClass();
60+
$obj->amount = $errorcount;
61+
$obj->url = $CFG->wwwroot . '/admin/tool/lifecycle/errors.php';
62+
63+
email_to_user(get_admin(), \core_user::get_noreply_user(),
64+
get_string('notifyerrorsemailsubject', 'tool_lifecycle', $obj),
65+
get_string('notifyerrorsemailcontent', 'tool_lifecycle', $obj),
66+
get_string('notifyerrorsemailcontenthtml', 'tool_lifecycle', $obj),
67+
);
68+
}
69+
}

db/tasks.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@
4444
'day' => '*',
4545
'month' => '*',
4646
'dayofweek' => '0',
47-
)
47+
),
48+
array(
49+
'classname' => 'tool_lifecycle\task\lifecycle_error_notify_task',
50+
'blocking' => 0,
51+
'minute' => 'R',
52+
'hour' => '5',
53+
'day' => '*',
54+
'month' => '*',
55+
'dayofweek' => '0',
56+
),
4857
);

errors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
foreach ($ids as $id) {
5151
process_manager::rollback_process_after_error($id);
5252
}
53+
} else {
54+
throw new coding_exception("action must be either 'proceed' or 'rollback'");
5355
}
5456
redirect($PAGE->url);
5557
}

lang/de/tool_lifecycle.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,12 @@
177177
$string['process_rollback_event'] = 'Ein Prozess wurde zurückgesetzt';
178178

179179
$string['courseid'] = 'Kurs-ID';
180-
$string['process_errors_header'] = 'Prozessfehler';
180+
$string['process_errors_header'] = 'Fehlermanagement';
181+
$string['proceed'] = 'Fortfahren';
181182
$string['forselected'] = 'Für alle ausgewählten Prozesse';
183+
$string['noprocesserrors'] = 'Es gibt keine fehlerhaften Prozesse, die behandelt werden müssen!';
184+
185+
$string['lifecycle_error_notify_task'] = 'Benachrichtigt die Administratoren bei Fehlern in tool_lifecycle-Prozessen.';
186+
$string['notifyerrorsemailsubject'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!';
187+
$string['notifyerrorsemailcontent'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.';
188+
$string['notifyerrorsemailcontenthtml'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!<br>Bitte besuchen Sie <a href="{$a->url}">die Übersichtsseite</a>.';

lang/en/tool_lifecycle.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@
212212
$string['delete_all_delays'] = 'Delete all delays';
213213

214214
$string['courseid'] = 'Course ID';
215-
$string['process_errors_header'] = 'Process errors';
215+
$string['process_errors_header'] = 'Error handling';
216216
$string['proceed'] = 'Proceed';
217217
$string['rollback'] = 'Rollback';
218218
$string['forselected'] = 'For all selected processes';
219+
$string['noprocesserrors'] = 'There are no process errors to handle!';
220+
221+
$string['lifecycle_error_notify_task'] = 'Notify the admin upon errors in tool_lifecycle processes';
222+
$string['notifyerrorsemailsubject'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!';
223+
$string['notifyerrorsemailcontent'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.';
224+
$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>.';

0 commit comments

Comments
 (0)