Skip to content

Fix - Avoid SQL warning when no user session is active during plugin init#1179

Open
RomainLvr wants to merge 2 commits intomainfrom
fix/entity-restrict-criteria-without-session
Open

Fix - Avoid SQL warning when no user session is active during plugin init#1179
RomainLvr wants to merge 2 commits intomainfrom
fix/entity-restrict-criteria-without-session

Conversation

@RomainLvr
Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !43370
  • Here is a brief description of what this PR does

When initializing the plugin during boot (before any user session), getEntitiesRestrictCriteria() was called without an active session, producing entities_id = '' in the SQL query and triggering a mass MySQL warning (1292: Truncated incorrect DECIMAL value).

Fix by skipping entity restriction when no user is logged in (!Session::getLoginUserID()), consistent with the existing check already in place in setup.php.

Error :

SQL: SELECT * FROM `glpi_plugin_fields_containers` WHERE `is_active` = '1' AND `type` = 'dom' AND ((`itemtypes` LIKE '%\\\"Ticket\\\"%') OR (`itemtypes` LIKE '%\\\"Change\\\"%') OR (`itemtypes` LIKE '%\\\"Problem\\\"%')) AND (`glpi_plugin_fields_containers`.`entities_id` = '') ORDER BY `name`
  Warnings: 
1292: Truncated incorrect DECIMAL value: '' at DBmysql.php line 444
  Backtrace :
  ./src/DBmysql.php:444                              
  ./src/DBmysqlIterator.php:129                      DBmysql->doQuery()
  ./src/DBmysql.php:1088                             DBmysqlIterator->execute()
  ./src/CommonDBTM.php:632                           DBmysql->request()
  ./plugins/fields/inc/questiontype.class.php:384    CommonDBTM->find()
  ./plugins/fields/inc/questiontype.class.php:426    PluginFieldsQuestionType->getAvailableBlocks()
  ./plugins/fields/setup.php:428                     PluginFieldsQuestionType::hasAvailableFields()
  ./plugins/fields/setup.php:136                     plugin_fields_register_plugin_types()
  ./src/Plugin.php:475                               plugin_init_fields()
  ./src/Plugin.php:428                               Plugin::load()
  ...tener/PostBootListener/InitializePlugins.php:75 Plugin->init()
  .../event-dispatcher/Debug/WrappedListener.php:116 Glpi\Kernel\Listener\PostBootListener\InitializePlugins->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:142 Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
  ./src/Glpi/Kernel/Kernel.php:149                   Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
  ./vendor/symfony/http-kernel/Kernel.php:201        Glpi\Kernel\Kernel->boot()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

Close #1172

$available_blocks = [];

$entity_restrict = isCommandLine() ? [] : getEntitiesRestrictCriteria(PluginFieldsContainer::getTable(), '', '', true);
$entity_restrict = (isCommandLine() || !Session::getLoginUserID()) ? [] : getEntitiesRestrictCriteria(PluginFieldsContainer::getTable(), '', '', true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, you're either in CLI mode or logged in as an authenticated user. It seems to be neither, so I don't think this should be allowed, to avoid creating a security issue

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.

MySQL warning 1292 spam on boot — getAvailableBlocks() calls getEntitiesRestrictCriteria() before session is initialized

2 participants