Skip to content

Commit

Permalink
Prefer "complete[name]" field for mapping with tier item; see plugins…
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Sep 7, 2018
1 parent 4261da7 commit f49df34
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,36 @@ static function addToSearchOptions(array $type_searchOptions, array $options,
}
}

return $type_searchOptions;
/*
* Preserve only one option per linkfield, as mapping process is based on arrays indexed by linkfield.
* This is a hack to handle behaviour explained in issue https://github.com/pluginsGLPI/datainjection/issues/121.
*
* Preserved option is "complename" if existing, or "name" if existing,
* or first founded option for each linkfield.
*/
$linkfield_preserved_option = array_fill_keys(array_column($type_searchOptions, 'linkfield'), null);
foreach ($type_searchOptions as $option) {
if (!array_key_exists('linkfield', $option)) {
continue;
}

$linkfield = $option['linkfield'];

if (null === $linkfield_preserved_option[$linkfield]
|| ('name' === $option['field'] && 'completename' !== $linkfield_preserved_option[$linkfield]['field'])
|| 'completename' === $option['field']) {
$linkfield_preserved_option[$linkfield] = $option;
}
}

$type_searchOptions = array_filter(
$type_searchOptions,
function ($option) use ($linkfield_preserved_option) {
return in_array($option, $linkfield_preserved_option);
}
);

return $type_searchOptions;
}


Expand Down

0 comments on commit f49df34

Please sign in to comment.