Skip to content
Snippets Groups Projects
Commit 0f84502f authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Added process_manager function for manually triggering a process

parent 25e201be
No related branches found
No related tags found
No related merge requests found
......@@ -24,8 +24,6 @@
namespace tool_cleanupcourses\manager;
use tool_cleanupcourses\entity\process;
use tool_cleanupcourses\entity\trigger_subplugin;
use tool_cleanupcourses\manager\delayed_courses_manager;
defined('MOODLE_INTERNAL') || die();
......@@ -52,6 +50,26 @@ class process_manager {
return null;
}
/**
* Creates a process based on a manual trigger.
* @param $courseid int id of the course to be triggerd.
* @param $triggerid int id of the triggering trigger.
* @return process the triggered process instance.
* @throws \moodle_exception for invalid workflow definition or missing trigger.
*/
public static function manually_trigger_process($courseid, $triggerid) {
$trigger = trigger_manager::get_instance($triggerid);
if (!$trigger) {
throw new \moodle_exception('trigger_does_not_exist', 'tool_cleanupcourses');
}
$workflow = workflow_manager::get_workflow($trigger->workflowid);
if (!$workflow || !workflow_manager::is_active($workflow->id) || !workflow_manager::is_valid($workflow->id) ||
$workflow->manual !== true) {
throw new \moodle_exception('cannot_trigger_workflow_manually', 'tool_cleanupcourses');
}
return self::create_process($courseid, $workflow->id);
}
/**
* Returns all current active processes.
* @return process[]
......
......@@ -51,6 +51,8 @@ $string['invalid_workflow_details'] = 'Go to details view, to create a trigger f
$string['active_workflow_not_changeable'] = 'The workflow instance is active. It is not possible to change any of its steps.';
$string['active_workflow_not_removeable'] = 'The workflow instance is active. It is not possible to remove it.';
$string['invalid_workflow_cannot_be_activated'] = 'The workflow definition is invalid, thus it cannot be activated.';
$string['trigger_does_not_exist'] = 'The requested trigger could not be found.';
$string['cannot_trigger_workflow_manually'] = 'The requested workflow could not be triggered manually.';
$string['process_cleanup'] = 'Run the cleanup courses processes';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment