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

Make active workflows editable

parent c14be4fe
No related branches found
No related tags found
No related merge requests found
......@@ -639,7 +639,7 @@ class workflow_settings {
}
if (!empty($data->id)) {
$step = step_manager::get_step_instance($data->id);
if ($data->instancename) {
if (isset($data->instancename)) {
$step->instancename = $data->instancename;
}
} else {
......
......@@ -23,6 +23,7 @@
*/
namespace tool_lifecycle\local\manager;
use tool_lifecycle\local\entity\workflow;
use tool_lifecycle\settings_type;
defined('MOODLE_INTERNAL') || die();
......@@ -63,8 +64,6 @@ class settings_manager {
global $DB;
self::validate_type($type);
// TODO before PR merges: Saveguard for changing settings
if (!$data) {
return;
}
......@@ -76,8 +75,12 @@ class settings_manager {
if ($type == settings_type::TRIGGER) {
$lib = lib_manager::get_trigger_lib($subpluginname);
$trigger = trigger_manager::get_instance($instanceid);
$wfeditable = workflow_manager::is_editable($trigger->workflowid);
} else {
$lib = lib_manager::get_step_lib($subpluginname);
$step = step_manager::get_step_instance($instanceid);
$wfeditable = workflow_manager::is_editable($step->workflowid);
}
$settingsfields = $lib->instance_settings();
......@@ -85,6 +88,9 @@ class settings_manager {
throw new \moodle_exception('id of the step instance has to be set!');
}
foreach ($settingsfields as $setting) {
if (!$wfeditable && !$setting->editable) {
continue;
}
if (array_key_exists($setting->name, $data)) {
$value = $data[$setting->name];
// Needed for editor support.
......@@ -107,8 +113,14 @@ class settings_manager {
'name' => $setting->name)
);
if ($record) {
if ($record->value != $cleanedvalue) {
$oldvalue = $record->value;
$record->value = $cleanedvalue;
$DB->update_record('tool_lifecycle_settings', $record);
if (!$wfeditable) {
$lib->on_setting_changed($setting->name, $cleanedvalue, $oldvalue);
}
}
} else {
$newrecord = new \stdClass();
$newrecord->instanceid = $instanceid;
......
......@@ -107,6 +107,16 @@ abstract class libbase {
return array();
}
/**
* Is called when a setting is changed after a workflow is activated.
* @param string $settingname name of the setting
* @param mixed $newvalue the new value
* @param mixed $oldvalue the old value
*/
public function on_setting_changed($settingname, $newvalue, $oldvalue) {
}
/**
* This method can be overriden, to add form elements to the form_step_instance.
* It is called in definition().
......
......@@ -53,6 +53,16 @@ abstract class base {
return array();
}
/**
* Is called when a setting is changed after a workflow is activated.
* @param string $settingname name of the setting
* @param mixed $newvalue the new value
* @param mixed $oldvalue the old value
*/
public function on_setting_changed($settingname, $newvalue, $oldvalue) {
}
/**
* This method can be overriden, to add form elements to the form_step_instance.
* It is called in definition().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment