Skip to content

Implement Process error table #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions amd/build/tablebulkactions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/tablebulkactions.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions amd/src/tablebulkactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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/>.

/**
* Javascript controller for checkboxed table.
* @module tool_lifecycle/tablebulkactions
* @copyright 2021 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Helper function to redirect via POST
* @param {String} url redirect to
* @param {Array} data redirect with data
*/
function redirectPost(url, data) {
const form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (const pair of data) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = pair.k;
input.value = pair.v;
form.appendChild(input);
}
form.submit();
}

/**
* Init function
*/
export function init() {
const checkboxes = document.querySelectorAll('input[name="procerror-select"]');

const action = document.querySelectorAll('*[data-lifecycle-action]');
action.forEach((a) => {
a.onclick = (e) => {
e.preventDefault();
let data = [
{k: 'action', v: a.getAttribute('data-lifecycle-action')},
{k: 'sesskey', v: M.cfg.sesskey}
];
if (a.getAttribute('data-lifecycle-forall') === '1') {
data.push({k: 'all', v: '1'});
redirectPost(window.location, data);
} else {
checkboxes.forEach((c) => {
if (c.checked) {
data.push({k: 'id[]', v: c.value});
}
});
redirectPost(window.location, data);
}
};
});
}
2 changes: 0 additions & 2 deletions classes/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
namespace tool_lifecycle;

defined('MOODLE_INTERNAL') || die();

/**
* Delivers all available action names throughout the plugin.
* @package tool_lifecycle
Expand Down
2 changes: 0 additions & 2 deletions classes/event/process_proceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
use moodle_url;
use tool_lifecycle\local\entity\process;

defined('MOODLE_INTERNAL') || die();

/**
* The process_proceeded event class.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/event/process_rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use moodle_url;
use tool_lifecycle\local\entity\process;

defined('MOODLE_INTERNAL') || die();

/**
* The process_rollback event class.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/event/process_triggered.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use moodle_url;
use tool_lifecycle\local\entity\process;

defined('MOODLE_INTERNAL') || die();

/**
* The process_triggered event class.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/backup/backup_lifecycle_workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
use tool_lifecycle\local\manager\settings_manager;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();

/**
* Class to backup a workflow.
* @package tool_lifecycle
Expand Down
2 changes: 0 additions & 2 deletions classes/local/backup/restore_lifecycle_workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
use tool_lifecycle\local\manager\settings_manager;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();

/**
* Class to restore a workflow.
* @package tool_lifecycle
Expand Down
2 changes: 0 additions & 2 deletions classes/local/data/manual_trigger_tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

use renderable;

defined('MOODLE_INTERNAL') || die();

/**
* Class representing a manual trigger tool
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/entity/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\entity;

defined('MOODLE_INTERNAL') || die();

/**
* Life Cycle Process class
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/entity/step_subplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\entity;

defined('MOODLE_INTERNAL') || die();

/**
* Subplugin class
*
Expand Down
4 changes: 1 addition & 3 deletions classes/local/entity/subplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
*/
namespace tool_lifecycle\local\entity;

defined('MOODLE_INTERNAL') || die();

/**
* Subplugin class
*
* @package tool_lifecycle
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class subplugin{
abstract class subplugin {

/** @var int $id Id of subplugin */
public $id;
Expand Down
4 changes: 1 addition & 3 deletions classes/local/entity/trigger_subplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
*/
namespace tool_lifecycle\local\entity;

defined('MOODLE_INTERNAL') || die();

/**
* Trigger subplugin class
*
* @package tool_lifecycle
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class trigger_subplugin extends subplugin{
class trigger_subplugin extends subplugin {

/**
* Creates a subplugin from a db record.
Expand Down
2 changes: 0 additions & 2 deletions classes/local/entity/workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\entity;

defined('MOODLE_INTERNAL') || die();

/**
* Life Cycle Workflow class
*
Expand Down
1 change: 0 additions & 1 deletion classes/local/manager/delayed_courses_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
namespace tool_lifecycle\local\manager;

defined('MOODLE_INTERNAL') || die();
/**
* Manager for Delayed Courses.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/manager/interaction_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use tool_lifecycle\processor;
use tool_lifecycle\local\response\step_interactive_response;

defined('MOODLE_INTERNAL') || die();

/**
* Manager to handle interactions by users
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/manager/lib_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use tool_lifecycle\trigger\base_automatic;
use tool_lifecycle\trigger\base_manual;

defined('MOODLE_INTERNAL') || die();

/**
* Manager to retrive the lib of each subplugin.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/manager/process_data_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use tool_lifecycle\local\entity\process;
use tool_lifecycle\local\entity\trigger_subplugin;

defined('MOODLE_INTERNAL') || die();

/**
* Manager for data of Life Cycle Processes.
*
Expand Down
68 changes: 66 additions & 2 deletions classes/local/manager/process_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
namespace tool_lifecycle\local\manager;

use core\event\course_deleted;
use Exception;
use tool_lifecycle\local\entity\process;
use tool_lifecycle\event\process_proceeded;
use tool_lifecycle\event\process_rollback;

defined('MOODLE_INTERNAL') || die();

/**
* Manager for Life Cycle Processes
*
Expand Down Expand Up @@ -245,4 +244,69 @@ public static function abort_process($process) {
$steplib->abort_course($process);
self::remove_process($process);
}

/**
* Moves a process into the procerror table.
*
* @param process $process The process
* @param Exception $e The exception
* @return void
*/
public static function insert_process_error(process $process, Exception $e) {
global $DB;

$procerror = (object) clone $process;
$procerror->errormessage = get_class($e) . ': ' . $e->getMessage();
$procerror->errortrace = $e->getTraceAsString();
$procerror->errortimecreated = time();
$m = '';
foreach ($e->getTrace() as $v) {
$m .= $v['file'] . ':' . $v['line'] . '::';
}
$procerror->errorhash = md5($m);
$procerror->waiting = intval($procerror->waiting);

$DB->insert_record_raw('tool_lifecycle_proc_error', $procerror, false, false, true);
$DB->delete_records('tool_lifecycle_process', ['id' => $process->id]);
}

/**
* Proceed process from procerror back into the process board.
* @param int $processid the processid
* @return void
*/
public static function proceed_process_after_error(int $processid) {
global $DB;
$process = $DB->get_record('tool_lifecycle_proc_error', ['id' => $processid]);
// Unset process error entries.
unset($process->errormessage);
unset($process->errortrace);
unset($process->errorhash);
unset($process->errortimecreated);

$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);
}

/**
* Rolls back a process from procerror table
* @param int $processid the processid
* @return void
*/
public static function rollback_process_after_error(int $processid) {
global $DB;

$process = $DB->get_record('tool_lifecycle_proc_error', ['id' => $processid]);
// Unset process error entries.
unset($process->errormessage);
unset($process->errortrace);
unset($process->errorhash);
unset($process->errortimecreated);

$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);

delayed_courses_manager::set_course_delayed_for_workflow($process->courseid, true, $process->workflowid);
self::rollback_process($process);
}
}
2 changes: 0 additions & 2 deletions classes/local/manager/step_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use tool_lifecycle\local\entity\step_subplugin;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();

/**
* Manager for Subplugins
*
Expand Down
16 changes: 0 additions & 16 deletions classes/local/manager/subplugin_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
*/
namespace tool_lifecycle\local\manager;

defined('MOODLE_INTERNAL') || die();
// 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/>.

/**
* Manager for Subplugins
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/manager/trigger_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use tool_lifecycle\local\entity\workflow;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();

/**
* Manager for Trigger subplugins
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use tool_lifecycle\local\data\manual_trigger_tool;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();

/**
* Manager for Life Cycle Workflows
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/response/step_interactive_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\response;

defined('MOODLE_INTERNAL') || die();

/**
* Possible Responses of a Subplugin for interaction handling
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/response/step_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\response;

defined('MOODLE_INTERNAL') || die();

/**
* Possible Responses of a Subplugin
*
Expand Down
2 changes: 0 additions & 2 deletions classes/local/response/trigger_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
namespace tool_lifecycle\local\response;

defined('MOODLE_INTERNAL') || die();

/**
* Possible Responses of a Trigger Subplugin
*
Expand Down
Loading