pluginsGLPI / genericobject

Genericobject object plugin
http://glpi-plugins.rtfd.io/en/latest/genericobject/index.html
GNU General Public License v3.0
53 stars 58 forks source link

Fix duplicated search option key bug #214

Closed loicbenoit closed 6 years ago

loicbenoit commented 6 years ago

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.

cedric-anne commented 6 years ago

Hi,

I did not test but it seems correct. Maybe you can simplify code but just using an array of indexes, like $taken_indexes = $index_exceptions; and check if it used using while(in_array($currentindex, $taken_indexes)) { ... }.

Regards

loicbenoit commented 6 years ago

2 empty lines and 1 missing space after "while" were corrected.

cedric-anne commented 6 years ago

Hi,

Thanks for the contribution.

Regards