Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer "complete[name]" field for mapping with tier item; see #121 #122

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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