Skip to content

Prevent custom definitions to be loaded when DB is not up-to-date #20246

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

Merged

Conversation

cedric-anne
Copy link
Member

@cedric-anne cedric-anne commented Jul 8, 2025

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.

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 the getTypeName() method on corresponding classes, than cannot be loaded because the custom asset classes autoloader is not registered.

glpi.CRITICAL:   *** Uncaught Error: Class "Glpi\CustomAsset\PortableAsset" not found
  Backtrace :
  ...Api/HL/Controller/CustomAssetController.php:292 
  ./src/Webhook.php:363                              Glpi\Api\HL\Controller\CustomAssetController::getCustomAssetTypes()
  ./src/Webhook.php:1104                             Webhook::getAPIItemtypeData()
  ./src/CommonDBTM.php:1442                          Webhook::raise()
  ./src/Glpi/Event.php:129                           CommonDBTM->add()
  ./src/Plugin.php:1304                              Glpi\Event::log()
  ...ener/PostBootListener/CheckPluginsStates.php:76 Plugin->unactivateAll()
  .../event-dispatcher/Debug/WrappedListener.php:116 Glpi\Kernel\Listener\PostBootListener\CheckPluginsStates->onPostBoot()
  ...ymfony/event-dispatcher/EventDispatcher.php:220 Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
  ...symfony/event-dispatcher/EventDispatcher.php:56 Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
  ...spatcher/Debug/TraceableEventDispatcher.php:139 Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
  ./src/Glpi/Kernel/Kernel.php:144                   Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
  ./vendor/symfony/http-kernel/Kernel.php:192        Glpi\Kernel\Kernel->boot()
  ./public/index.php:70                              Symfony\Component\HttpKernel\Kernel->handle()

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.

@cedric-anne cedric-anne self-assigned this Jul 8, 2025
@cedric-anne cedric-anne force-pushed the 11.0/fix-definitions-registering branch 2 times, most recently from 15d9788 to d049a86 Compare July 9, 2025 09:24
@cedric-anne cedric-anne marked this pull request as ready for review July 9, 2025 09:24
@cedric-anne cedric-anne force-pushed the 11.0/fix-definitions-registering branch from d049a86 to c3b7698 Compare July 9, 2025 09:24
@cedric-anne cedric-anne merged commit fea4e4b into glpi-project:main Jul 9, 2025
7 checks passed
@cedric-anne cedric-anne deleted the 11.0/fix-definitions-registering branch July 9, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants