diff --git a/classes/local/manager/process_manager.php b/classes/local/manager/process_manager.php index 96e43b4021785953edc6e0f7af56865453353966..1c3c74a1cf8bafb5df76241eda72bb8958a60c9c 100644 --- a/classes/local/manager/process_manager.php +++ b/classes/local/manager/process_manager.php @@ -260,6 +260,7 @@ class process_manager { $procerror = (object) clone $process; $procerror->errormessage = get_class($e) . ': ' . $e->getMessage(); $procerror->errortrace = $e->getTraceAsString(); + $procerror->errortime = time(); $m = ''; foreach ($e->getTrace() as $v) { $m .= $v['file'] . ':' . $v['line'] . '::'; @@ -283,6 +284,7 @@ class process_manager { unset($process->errormessage); unset($process->errortrace); unset($process->errorhash); + unset($process->errortime); $DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true); $DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]); @@ -301,6 +303,7 @@ class process_manager { unset($process->errormessage); unset($process->errortrace); unset($process->errorhash); + unset($process->errortime); $DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true); $DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]); diff --git a/classes/task/lifecycle_error_notify_task.php b/classes/task/lifecycle_error_notify_task.php index 7c15fa866f42e296f45d657f4813e29730f8b227..ec631a4f059d20995e7a3ecb997cd9620f9c0cf3 100644 --- a/classes/task/lifecycle_error_notify_task.php +++ b/classes/task/lifecycle_error_notify_task.php @@ -50,7 +50,16 @@ class lifecycle_error_notify_task extends \core\task\scheduled_task { public function execute() { global $DB, $CFG; - $errorcount = $DB->count_records('tool_lifecycle_proc_error'); + $lastrun = get_config('tool_lifecycle', 'adminerrornotifylastrun'); + if (!$lastrun) { + $lastrun = 0; + } + + $currenttime = time(); + + $errorcount = $DB->count_records_select('tool_lifecycle_proc_error', 'errortime > :lastrun', ['lastrun' => $lastrun]); + + set_config('adminerrornotifylastrun', $currenttime, 'tool_lifecycle'); if (!$errorcount) { return; diff --git a/db/install.xml b/db/install.xml index 4c085807c9e53826ea4b51b0cc4eb8702099eac0..22f2fa0f655b87debb931afafb36e5b76e639826 100644 --- a/db/install.xml +++ b/db/install.xml @@ -157,6 +157,7 @@ <FIELD NAME="errormessage" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Message of the error"/> <FIELD NAME="errortrace" TYPE="text" NOTNULL="true" SEQUENCE="false"/> <FIELD NAME="errorhash" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Where the error occured in the form 'path/to/filename.php:line'"/> + <FIELD NAME="errortime" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="unix timestamp - time the error occured"/> </FIELDS> <KEYS> <KEY NAME="primary" TYPE="primary" FIELDS="id"/> diff --git a/db/upgrade.php b/db/upgrade.php index c0b808b91fbc60d28f68f9537f6d67bfc6a7a74a..a0a11f6e3ef63a8bbcbacb9b294ef7940db7df4d 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -461,6 +461,7 @@ function xmldb_tool_lifecycle_upgrade($oldversion) { $table->add_field('errormessage', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); $table->add_field('errortrace', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); $table->add_field('errorhash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + $table->add_field('errortime', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null); // Adding keys to table tool_lifecycle_proc_error. $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); diff --git a/lang/de/tool_lifecycle.php b/lang/de/tool_lifecycle.php index 17706b0949a933cee59195a487d53f2f62ae3fe3..fa77816ec52ad1a4da05b7a4bdffd9fba24a66de 100644 --- a/lang/de/tool_lifecycle.php +++ b/lang/de/tool_lifecycle.php @@ -183,6 +183,6 @@ $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>.'; +$string['notifyerrorsemailsubject'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!'; +$string['notifyerrorsemailcontent'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.'; +$string['notifyerrorsemailcontenthtml'] = '{$a->amount} neue 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 b1149de50b89545ab15289a2480f7eda6b809548..420eb2665200454727ca2c6d5dc333c430b81316 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -219,6 +219,6 @@ $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>.'; +$string['notifyerrorsemailsubject'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!'; +$string['notifyerrorsemailcontent'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.'; +$string['notifyerrorsemailcontenthtml'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!<br>Please review them at the <a href="{$a->url}">error handling overview</a>.';