Fix duplicated search option key bug #214
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix these error messages in log: CommonDBTM::searchOptions() in /opt/bitnami/apps/glpi/htdocs/inc/commondbtm.class.php line 3455
Duplicate key # (field A/field B) in PluginGenericobjectFoo searchOptions!
This also fixes the issue of missing fields in dropdowns for objects created with GenericObjects. For example, fields like serial where not in the list of fields to select when defining duplicity rules. It will probably fix some other issues too, because this affects anything that relies on SearchOptions, like dropdowns related to GenericObjects.
This fix can only ensure that the $options array stops repeating itself. The fix heavily relies on the provided $index_exceptions array to avoid globally reserved indexes.
The $options array repeated itself, because the "$currentindex = $index_exceptions[$field]" sometimes jumps to a lower index. The code "If this index is reserved, jump to next: $currentindex++;" was wrong in assuming that incrementing would always choose an unused index.