From c14be4fe1ba17568d79ed98a851be93c59e1d7bb Mon Sep 17 00:00:00 2001 From: Justus Dieckmann <justusdieckmann@wwu.de> Date: Thu, 23 Sep 2021 01:54:48 +0200 Subject: [PATCH] Start with implementing editing active workflows --- adminlib.php | 17 +++++++++-------- classes/local/form/form_step_instance.php | 14 ++++++++------ classes/local/manager/settings_manager.php | 2 ++ step/email/lib.php | 8 ++++---- step/lib.php | 7 ++++++- trigger/lib.php | 7 ++++++- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/adminlib.php b/adminlib.php index 76afb02..f4657ff 100644 --- a/adminlib.php +++ b/adminlib.php @@ -636,17 +636,18 @@ class workflow_settings { \core\notification::add( get_string('active_workflow_not_changeable', 'tool_lifecycle'), \core\notification::WARNING); - } else { - if (!empty($data->id)) { - $step = step_manager::get_step_instance($data->id); + } + if (!empty($data->id)) { + $step = step_manager::get_step_instance($data->id); + if ($data->instancename) { $step->instancename = $data->instancename; - } else { - $step = step_subplugin::from_record($data); } - step_manager::insert_or_update($step); - // Save local subplugin settings. - settings_manager::save_settings($step->id, settings_type::STEP, $form->subpluginname, $data); + } else { + $step = step_subplugin::from_record($data); } + step_manager::insert_or_update($step); + // Save local subplugin settings. + settings_manager::save_settings($step->id, settings_type::STEP, $form->subpluginname, $data); } else { $this->view_step_instance_form($form); return true; diff --git a/classes/local/form/form_step_instance.php b/classes/local/form/form_step_instance.php index 542817c..6a6fc76 100644 --- a/classes/local/form/form_step_instance.php +++ b/classes/local/form/form_step_instance.php @@ -130,11 +130,7 @@ class form_step_instance extends \moodleform { } // For active workflows, we do not want the form to be editable. - if ($this->workflowid && !workflow_manager::is_editable($this->workflowid)) { - $this->add_cancel_button(); - } else { - $this->add_action_buttons(); - } + $this->add_action_buttons(); } /** @@ -183,7 +179,13 @@ class form_step_instance extends \moodleform { // For active workflows, we do not want the form to be editable. if ($this->workflowid && !workflow_manager::is_editable($this->workflowid)) { // The group buttonar is the array of submit buttons. For inactive workflows this is only a cancel button. - $mform->hardFreezeAllVisibleExcept(array('buttonar')); + $notfreeze = ['buttonar']; + foreach ($this->lib->instance_settings() as $setting) { + if ($setting->editable) { + $notfreeze[] = $setting->name; + } + } + $mform->hardFreezeAllVisibleExcept($notfreeze); } } diff --git a/classes/local/manager/settings_manager.php b/classes/local/manager/settings_manager.php index 7e76238..cda7a68 100644 --- a/classes/local/manager/settings_manager.php +++ b/classes/local/manager/settings_manager.php @@ -63,6 +63,8 @@ class settings_manager { global $DB; self::validate_type($type); + // TODO before PR merges: Saveguard for changing settings + if (!$data) { return; } diff --git a/step/email/lib.php b/step/email/lib.php index b247741..e71040c 100644 --- a/step/email/lib.php +++ b/step/email/lib.php @@ -221,10 +221,10 @@ class email extends libbase { */ public function instance_settings() { return array( - new instance_setting('responsetimeout', PARAM_INT), - new instance_setting('subject', PARAM_TEXT), - new instance_setting('content', PARAM_RAW), - new instance_setting('contenthtml', PARAM_RAW), + new instance_setting('responsetimeout', PARAM_INT, true), + new instance_setting('subject', PARAM_TEXT, true), + new instance_setting('content', PARAM_RAW, true), + new instance_setting('contenthtml', PARAM_RAW, true), ); } diff --git a/step/lib.php b/step/lib.php index f5cbb9f..86b20b7 100644 --- a/step/lib.php +++ b/step/lib.php @@ -149,14 +149,19 @@ class instance_setting { /** @var string param type of the setting, e.g. PARAM_INT */ public $paramtype; + /** @var bool if editable after activation */ + public $editable; + /** * Create a local settings object. * @param string $name name of the setting * @param string $paramtype param type. Used for cleansing and parsing, e.g. PARAM_INT. + * @param bool $editable if setting is editable after activation */ - public function __construct($name, $paramtype) { + public function __construct(string $name, string $paramtype, bool $editable = false) { $this->name = $name; $this->paramtype = $paramtype; + $this->editable = $editable; } } diff --git a/trigger/lib.php b/trigger/lib.php index 5ec5ad7..79e6f9e 100644 --- a/trigger/lib.php +++ b/trigger/lib.php @@ -179,14 +179,19 @@ class instance_setting { /** @var string param type of the setting, e.g. PARAM_INT */ public $paramtype; + /** @var bool if editable after activation */ + public $editable; + /** * Create a local settings object. * @param string $name name of the setting * @param string $paramtype param type. Used for cleansing and parsing, e.g. PARAM_INT. + * @param bool $editable if setting is editable after activation */ - public function __construct($name, $paramtype) { + public function __construct(string $name, string $paramtype, bool $editable = false) { $this->name = $name; $this->paramtype = $paramtype; + $this->editable = $editable; } } -- GitLab