diff --git a/adminlib.php b/adminlib.php
index f4657ff88b3c334763ffca4feff4c02ee6a5be1c..77cf55b5e2a0e62160ee45e4cf4ea9771f2a94c8 100644
--- a/adminlib.php
+++ b/adminlib.php
@@ -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 {
diff --git a/classes/local/manager/settings_manager.php b/classes/local/manager/settings_manager.php
index cda7a688629399723486043a3d341b82dbee64ff..2b6bf91e4c3192d72c3a784a7ea032301eb240f3 100644
--- a/classes/local/manager/settings_manager.php
+++ b/classes/local/manager/settings_manager.php
@@ -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) {
- $record->value = $cleanedvalue;
- $DB->update_record('tool_lifecycle_settings', $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;
diff --git a/step/lib.php b/step/lib.php
index 86b20b7def0acb07b80dce00894cadae40a0106e..7209d1d3d5622341bab2ea2acf7e03cae4093282 100644
--- a/step/lib.php
+++ b/step/lib.php
@@ -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().
diff --git a/trigger/lib.php b/trigger/lib.php
index 79e6f9e45337098677638f5c381810fee02a91cb..3c01ffb7bc98d55f078e24af7f95b3f4b213065c 100644
--- a/trigger/lib.php
+++ b/trigger/lib.php
@@ -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().