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

Add events for triggering/proceeding/rolling back processes

parent 6ebdc134
No related branches found
No related tags found
No related merge requests found
<?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/>.
/**
* The process_proceeded event.
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\event;
use moodle_url;
use \tool_lifecycle\entity\process;
defined('MOODLE_INTERNAL') || die();
/**
* The process_proceeded event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int processid: the id of the process.
* - int workflowid: the id of the workflow.
* - int stepindex: the index of the step.
* }
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class process_proceeded extends \core\event\base {
/**
* Creates an event with a process.
*
* @param process $process
* @return process_proceeded
*/
public static function event_from_process($process) {
$data = array(
'context' => \context_course::instance($process->courseid),
'other' => array(
'processid' => $process->id,
'workflowid' => $process->workflowid,
'stepindex' => $process->stepindex
),
'courseid' => $process->courseid,
);
return self::create($data);
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$processid = $this->other['processid'];
$workflowid = $this->other['workflowid'];
$stepindex = $this->other['stepindex'];
return "The workflow with id '$workflowid' finished step '$stepindex' successfully for course '$this->courseid' in the process with id '$processid'";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('process_proceeded_event', 'tool_lifecycle');
}
/**
* Returns relevant URL.
*
* @return moodle_url
*/
public function get_url() {
return new moodle_url('/admin/tool/lifecycle/view.php', array('contextid' => $this->contextid));
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['processid'])) {
throw new \coding_exception('The \'processid\' value must be set');
}
if (!isset($this->other['workflowid'])) {
throw new \coding_exception('The \'workflowid\' value must be set');
}
if (!isset($this->other['stepindex'])) {
throw new \coding_exception('The \'stepindex\' value must be set');
}
}
public static function get_other_mapping() {
// No backup and restore.
return false;
}
}
<?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/>.
/**
* The process_rollback event.
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\event;
use moodle_url;
use \tool_lifecycle\entity\process;
defined('MOODLE_INTERNAL') || die();
/**
* The process_rollback event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int processid: the id of the process.
* - int workflowid: the id of the workflow.
* - int stepindex: the index of the step.
* }
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class process_rollback extends \core\event\base {
/**
* Creates an event with a process.
*
* @param process $process
* @return process_rollback
*/
public static function event_from_process($process) {
$data = array(
'context' => \context_course::instance($process->courseid),
'other' => array(
'processid' => $process->id,
'workflowid' => $process->workflowid,
'stepindex' => $process->stepindex
),
'courseid' => $process->courseid,
);
return self::create($data);
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$processid = $this->other['processid'];
$workflowid = $this->other['workflowid'];
$stepindex = $this->other['stepindex'];
return "The workflow with id '$workflowid' was rolled back on step '$stepindex' for course '$this->courseid' in the process with id '$processid'";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('process_rollback_event', 'tool_lifecycle');
}
/**
* Returns relevant URL.
*
* @return moodle_url
*/
public function get_url() {
return new moodle_url('/admin/tool/lifecycle/view.php', array('contextid' => $this->contextid));
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['processid'])) {
throw new \coding_exception('The \'processid\' value must be set');
}
if (!isset($this->other['workflowid'])) {
throw new \coding_exception('The \'workflowid\' value must be set');
}
if (!isset($this->other['stepindex'])) {
throw new \coding_exception('The \'stepindex\' value must be set');
}
}
public static function get_other_mapping() {
// No backup and restore.
return false;
}
}
<?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/>.
/**
* The process_triggered event.
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\event;
use moodle_url;
use \tool_lifecycle\entity\process;
defined('MOODLE_INTERNAL') || die();
/**
* The process_triggered event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int processid: the id of the process.
* - int workflowid: the id of the workflow.
* }
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class process_triggered extends \core\event\base {
/**
* Creates an event with a process.
*
* @param process $process
* @return process_triggered
*/
public static function event_from_process($process) {
$data = array(
'context' => \context_course::instance($process->courseid),
'other' => array(
'processid' => $process->id,
'workflowid' => $process->workflowid
),
'courseid' => $process->courseid,
);
return self::create($data);
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$processid = $this->other['processid'];
$workflowid = $this->other['workflowid'];
return "The workflow with id '$workflowid' triggered for course '$this->courseid' and created process with id '$processid'";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('process_triggered_event', 'tool_lifecycle');
}
/**
* Returns relevant URL.
*
* @return moodle_url
*/
public function get_url() {
return new moodle_url('/admin/tool/lifecycle/view.php', array('contextid' => $this->contextid));
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['processid'])) {
throw new \coding_exception('The \'processid\' value must be set');
}
if (!isset($this->other['workflowid'])) {
throw new \coding_exception('The \'workflowid\' value must be set');
}
}
public static function get_other_mapping() {
// No backup and restore.
return false;
}
}
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
namespace tool_lifecycle\manager; namespace tool_lifecycle\manager;
use tool_lifecycle\entity\process; use tool_lifecycle\entity\process;
use tool_lifecycle\event\process_proceeded;
use tool_lifecycle\event\process_rollback;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -133,6 +135,7 @@ class process_manager { ...@@ -133,6 +135,7 @@ class process_manager {
global $DB; global $DB;
$step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $process->stepindex + 1); $step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $process->stepindex + 1);
if ($step) { if ($step) {
process_proceeded::event_from_process($process)->trigger();
$process->stepindex++; $process->stepindex++;
$process->waiting = false; $process->waiting = false;
$process->timestepchanged = time(); $process->timestepchanged = time();
...@@ -159,6 +162,7 @@ class process_manager { ...@@ -159,6 +162,7 @@ class process_manager {
* @param process $process process the rollback should be triggered for. * @param process $process process the rollback should be triggered for.
*/ */
public static function rollback_process($process) { public static function rollback_process($process) {
process_rollback::event_from_process($process)->trigger();
for ($i = $process->stepindex - 1; $i >= 1; $i--) { for ($i = $process->stepindex - 1; $i >= 1; $i--) {
$step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $i); $step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $i);
$lib = lib_manager::get_step_lib($step->subpluginname); $lib = lib_manager::get_step_lib($step->subpluginname);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
namespace tool_lifecycle; namespace tool_lifecycle;
use tool_lifecycle\entity\trigger_subplugin; use tool_lifecycle\entity\trigger_subplugin;
use tool_lifecycle\event\process_triggered;
use tool_lifecycle\manager\process_manager; use tool_lifecycle\manager\process_manager;
use tool_lifecycle\manager\step_manager; use tool_lifecycle\manager\step_manager;
use tool_lifecycle\manager\trigger_manager; use tool_lifecycle\manager\trigger_manager;
...@@ -78,7 +79,8 @@ class processor { ...@@ -78,7 +79,8 @@ class processor {
} }
} }
// If all trigger instances agree, that they want to trigger a process, we do so. // If all trigger instances agree, that they want to trigger a process, we do so.
process_manager::create_process($course->id, $workflow->id); $process = process_manager::create_process($course->id, $workflow->id);
process_triggered::event_from_process($process)->trigger();
$counttriggered++; $counttriggered++;
$recordset->next(); $recordset->next();
} }
......
...@@ -153,3 +153,7 @@ $string['restore_workflow_not_found'] = 'Wrong format of the backup file. The wo ...@@ -153,3 +153,7 @@ $string['restore_workflow_not_found'] = 'Wrong format of the backup file. The wo
$string['restore_subplugins_invalid'] = 'Wrong format of the backup file. The structure of the subplugin elements is not as expected.'; $string['restore_subplugins_invalid'] = 'Wrong format of the backup file. The structure of the subplugin elements is not as expected.';
$string['restore_step_does_not_exist'] = 'The step {$a} is not installed, but is included in the backup file. Please installed it first and try again.'; $string['restore_step_does_not_exist'] = 'The step {$a} is not installed, but is included in the backup file. Please installed it first and try again.';
$string['restore_trigger_does_not_exist'] = 'The trigger {$a} is not installed, but is included in the backup file. Please installed it first and try again.'; $string['restore_trigger_does_not_exist'] = 'The trigger {$a} is not installed, but is included in the backup file. Please installed it first and try again.';
$string['process_triggered_event'] = 'A process has been triggered';
$string['process_proceeded_event'] = 'A process has been proceeded';
$string['process_rollback_event'] = 'A process has been rolled back';
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment