Do not alter current object when fetching its search options #18911
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.
Checklist before requesting a review
Description
When the
CommonDBTM::isField()
method is used on a "non-hydrated" object, theCommonDBTM::getEmpty()
is triggerred, calling itself theCommonDBTM::post_getEmpty()
method and theitem_empty
hook.One of the side-effect of this is that
$this->fields['entities_id']
field is automatically set with the$_SESSION['glpiactive_entity']
value for anyCommonDBTM::add()
operation. For all items created from the generic GLPI form, it will not change much, as theentities_id
will be overriden by the form input, but for all objects created from anywhere else, it could hide the fact that the information is missing in the input. For instance, the following commit fixes an issue that has not been detected earlier due to this defaultentities_id
value: 8e69433Another side effect is that calling
CommonDBTM::rawSearchOptions()
may be altered the current object, because it often usesCommonDBTM::isField()
to populate generic search options.This is probably an unexpected behaviour. I am pretty sure that nobody expect the current object to be altered when using the
CommonDBTM::isField()
or theCommonDBTM::searchOptions()
methods.