Skip to content

Commit

Permalink
fix(form): import restrictions by profile was broken
Browse files Browse the repository at this point in the history
fix #722
Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Jul 10, 2018
1 parent 360dc6e commit 34ae3bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
16 changes: 16 additions & 0 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
26 changes: 8 additions & 18 deletions inc/form_profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 34ae3bf

Please sign in to comment.