From 710308f95ba1f218f6c7dff1a182dbee9d182e2e Mon Sep 17 00:00:00 2001 From: Justus Dieckmann <justusdieckmann@wwu.de> Date: Mon, 25 Oct 2021 02:04:21 +0200 Subject: [PATCH] Make active workflows editable --- adminlib.php | 2 +- classes/local/manager/settings_manager.php | 20 ++++++++++++++++---- step/lib.php | 10 ++++++++++ trigger/lib.php | 10 ++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/adminlib.php b/adminlib.php index f4657ff..77cf55b 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 cda7a68..2b6bf91 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 86b20b7..7209d1d 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 79e6f9e..3c01ffb 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(). -- GitLab