From 34ae3bf7a05159defa356f26116e2cc55ca3af84 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 4 Jul 2018 12:01:07 +0200 Subject: [PATCH] fix(form): import restrictions by profile was broken fix #722 Signed-off-by: btry --- inc/form.class.php | 16 ++++++++++++++++ inc/form_profile.class.php | 26 ++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index b5b04f044..03d431330 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1874,6 +1874,22 @@ public static function import($form = []) { $forms_id = $form_obj->add($form); } + // import restrictions + if ($forms_id) { + // Delete all previous restrictions + $FormProfile = new PluginFormcreatorForm_Profile(); + $FormProfile->deleteByCriteria([ + 'plugin_formcreator_forms_id' => $forms_id, + ]); + + // Import updates + if (isset($form['_profiles'])) { + foreach ($form['_profiles'] as $formProfile) { + PluginFormcreatorForm_Profile::import($forms_id, $formProfile); + } + } + } + // import form's sections if ($forms_id && isset($form['_sections'])) { diff --git a/inc/form_profile.class.php b/inc/form_profile.class.php index df1c69381..0f8950b72 100644 --- a/inc/form_profile.class.php +++ b/inc/form_profile.class.php @@ -141,32 +141,22 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl * * @param integer $forms_id id of the parent form * @param array $form_profile the validator data (match the validator table) - * @return integer the validator's id + * @return integer|false the form_Profile ID or false on error */ public static function import($forms_id = 0, $form_profile = []) { $item = new self; $profile = new Profile; - $form_profile['plugin_formcreator_forms_id'] = $forms_id; + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $form_profile[$formFk] = $forms_id; - // retrieve foreign key - if (!isset($form['_profile']) - || !$form['profiles_id'] - = plugin_formcreator_getFromDBByField($profile, 'name', $form['_profile'])) { - $form['profiles_id'] = $_SESSION['glpiactive_entity']; - } - - if ($form_profiles_id = plugin_formcreator_getFromDBByField($item, 'uuid', $form_profile['uuid'])) { - // add id key - $form_profile['id'] = $form_profiles_id; + if ($form_profiles_id = plugin_formcreator_getFromDBByField($profile, 'name', $form_profile['_profile'])) { + $form_profile[Profile::getForeignKeyField()] = $form_profiles_id; + $item->add($form_profile); - // update section - $item->update($form_profile); - } else { - //create section - $form_profiles_id = $item->add($form_profile); + return $item->getID(); } - return $validators_id; + return false; } /**