Skip to content
Snippets Groups Projects
Commit eed7b5d3 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Rename errortime to errortimecreated; Add phpunit test for process errors

parent 3ee2fb04
No related branches found
No related tags found
No related merge requests found
......@@ -260,7 +260,7 @@ class process_manager {
$procerror = (object) clone $process;
$procerror->errormessage = get_class($e) . ': ' . $e->getMessage();
$procerror->errortrace = $e->getTraceAsString();
$procerror->errortime = time();
$procerror->errortimecreated = time();
$m = '';
foreach ($e->getTrace() as $v) {
$m .= $v['file'] . ':' . $v['line'] . '::';
......@@ -284,7 +284,7 @@ class process_manager {
unset($process->errormessage);
unset($process->errortrace);
unset($process->errorhash);
unset($process->errortime);
unset($process->errortimecreated);
$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);
......@@ -303,7 +303,7 @@ class process_manager {
unset($process->errormessage);
unset($process->errortrace);
unset($process->errorhash);
unset($process->errortime);
unset($process->errortimecreated);
$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);
......
......@@ -57,7 +57,8 @@ class lifecycle_error_notify_task extends \core\task\scheduled_task {
$currenttime = time();
$errorcount = $DB->count_records_select('tool_lifecycle_proc_error', 'errortime > :lastrun', ['lastrun' => $lastrun]);
$errorcount = $DB->count_records_select('tool_lifecycle_proc_error', 'errortimecreated > :lastrun',
['lastrun' => $lastrun]);
set_config('adminerrornotifylastrun', $currenttime, 'tool_lifecycle');
......
......@@ -157,7 +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"/>
<FIELD NAME="errortimecreated" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="unix timestamp - time the error occured"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
......@@ -461,7 +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);
$table->add_field('errortimecreated', 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']);
......
<?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/>.
/**
* Checks whether process errors are properly inserted into the table.
*
* @package tool_lifecycle
* @category test
* @group tool_lifecycle
* @copyright 2022 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle;
use tool_lifecycle\local\entity\trigger_subplugin;
use tool_lifecycle\local\manager\settings_manager;
use tool_lifecycle\local\manager\workflow_manager;
use tool_lifecycle\local\manager\trigger_manager;
use tool_lifecycle\local\manager\process_manager;
/**
* Checks whether process errors are properly inserted into the table.
*
* @package tool_lifecycle
* @category test
* @group tool_lifecycle
* @copyright 2022 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class process_error_test extends \advanced_testcase {
/** Icon of the manual trigger. */
const MANUAL_TRIGGER1_ICON = 't/up';
/** Display name of the manual trigger. */
const MANUAL_TRIGGER1_DISPLAYNAME = 'Up';
/** Capability of the manual trigger. */
const MANUAL_TRIGGER1_CAPABILITY = 'moodle/course:manageactivities';
/** @var trigger_subplugin $trigger Instances of the triggers under test. */
private $trigger;
/** @var array $course Instance of the course under test. */
private $course;
/**
* Setup the testcase.
* @throws \coding_exception
* @throws \moodle_exception
*/
public function setUp() : void {
global $USER, $DB;
// We do not need a sesskey check in theses tests.
$USER->ignoresesskey = true;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator()->get_plugin_generator('tool_lifecycle');
$triggersettings = new \stdClass();
$triggersettings->icon = self::MANUAL_TRIGGER1_ICON;
$triggersettings->displayname = self::MANUAL_TRIGGER1_DISPLAYNAME;
$triggersettings->capability = self::MANUAL_TRIGGER1_CAPABILITY;
$manualworkflow = $generator->create_manual_workflow($triggersettings);
$step = $generator->create_step("instance1", "deletecourse", $manualworkflow->id);
settings_manager::save_settings($step->id, settings_type::STEP, "deletecourse",
array("maximumdeletionspercron" => 10)
);
workflow_manager::handle_action(action::WORKFLOW_ACTIVATE, $manualworkflow->id);
$this->course = $this->getDataGenerator()->create_course();
$this->getDataGenerator()->create_module('page', ['course' => $this->course->id]);
// Corrupt course.
$DB->execute('UPDATE {course_modules} SET instance = 0');
$this->trigger = trigger_manager::get_triggers_for_workflow($manualworkflow->id)[0];
}
/**
* Test if the correct process error was put into the table.
*/
public function test_process_error_in_table() {
global $DB;
$process = process_manager::manually_trigger_process($this->course->id, $this->trigger->id);
// The delete course step really wants to print output.
ob_start();
$processor = new processor();
$processor->process_courses();
ob_end_clean();
$records = $DB->get_records('tool_lifecycle_proc_error');
$this->assertEquals(1, count($records));
$this->assertEquals(0, $DB->count_records('tool_lifecycle_process'));
$record = reset($records);
$this->assertEquals($this->course->id, $record->courseid);
$this->assertStringContainsString("Trying to get property 'id' of non-object", $record->errormessage);
$this->assertEquals($process->id, $record->id);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment