Prevent custom definitions to be loaded when DB is not up-to-date #20246
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 a DB update is required, the custom objects autoloader is not registered and the definitions are not booted. However, the
AssetDefinitionManager::getDefinitions()
method returns all the definitions founds in the database, due to its "on demand" loading mechanism.It can cause issues. For instance, when the plugins are deactivated when a DB update is required,
Plugin->unactivateAll()
is executed and indirectly tries to load the asset definitions (Glpi\Event::log()
->CommonDBTM->add()
->Webhook::raise()
->Webhook::getAPIItemtypeData()
->Glpi\Api\HL\Controller\CustomAssetController::getCustomAssetTypes()
->Glpi\Asset\AssetDefinitionManager->getDefinitions()
), and then tries to call thegetTypeName()
method on corresponding classes, than cannot be loaded because the custom asset classes autoloader is not registered.I think the root issue here is that
CommonDBTM::add()
is executed on a GLPI instance that requires an update. However, changing this is probably complex, and probably requires some specifications. Indeed, we want to keep the event log (both in DB and in files) for the changes made on the plugins states during the GLPI bootstrap. A solution could be to disable the add/update/delete hooks on the event log, but it is too late to do it in GLPI 11.0.