Skip to content

Commit 34ae3bf

Browse files
committed
fix(form): import restrictions by profile was broken
fix #722 Signed-off-by: btry <tbugier@teclib.com>
1 parent 360dc6e commit 34ae3bf

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

inc/form.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,22 @@ public static function import($form = []) {
18741874
$forms_id = $form_obj->add($form);
18751875
}
18761876

1877+
// import restrictions
1878+
if ($forms_id) {
1879+
// Delete all previous restrictions
1880+
$FormProfile = new PluginFormcreatorForm_Profile();
1881+
$FormProfile->deleteByCriteria([
1882+
'plugin_formcreator_forms_id' => $forms_id,
1883+
]);
1884+
1885+
// Import updates
1886+
if (isset($form['_profiles'])) {
1887+
foreach ($form['_profiles'] as $formProfile) {
1888+
PluginFormcreatorForm_Profile::import($forms_id, $formProfile);
1889+
}
1890+
}
1891+
}
1892+
18771893
// import form's sections
18781894
if ($forms_id
18791895
&& isset($form['_sections'])) {

inc/form_profile.class.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,22 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl
141141
*
142142
* @param integer $forms_id id of the parent form
143143
* @param array $form_profile the validator data (match the validator table)
144-
* @return integer the validator's id
144+
* @return integer|false the form_Profile ID or false on error
145145
*/
146146
public static function import($forms_id = 0, $form_profile = []) {
147147
$item = new self;
148148
$profile = new Profile;
149-
$form_profile['plugin_formcreator_forms_id'] = $forms_id;
149+
$formFk = PluginFormcreatorForm::getForeignKeyField();
150+
$form_profile[$formFk] = $forms_id;
150151

151-
// retrieve foreign key
152-
if (!isset($form['_profile'])
153-
|| !$form['profiles_id']
154-
= plugin_formcreator_getFromDBByField($profile, 'name', $form['_profile'])) {
155-
$form['profiles_id'] = $_SESSION['glpiactive_entity'];
156-
}
157-
158-
if ($form_profiles_id = plugin_formcreator_getFromDBByField($item, 'uuid', $form_profile['uuid'])) {
159-
// add id key
160-
$form_profile['id'] = $form_profiles_id;
152+
if ($form_profiles_id = plugin_formcreator_getFromDBByField($profile, 'name', $form_profile['_profile'])) {
153+
$form_profile[Profile::getForeignKeyField()] = $form_profiles_id;
154+
$item->add($form_profile);
161155

162-
// update section
163-
$item->update($form_profile);
164-
} else {
165-
//create section
166-
$form_profiles_id = $item->add($form_profile);
156+
return $item->getID();
167157
}
168158

169-
return $validators_id;
159+
return false;
170160
}
171161

172162
/**

0 commit comments

Comments
 (0)