Skip to content

Fix(Search): Fix undefined array key during database inventory task#74

Merged
stonebuzz merged 4 commits intomainfrom
fix_undefined_index
Sep 4, 2025
Merged

Fix(Search): Fix undefined array key during database inventory task#74
stonebuzz merged 4 commits intomainfrom
fix_undefined_index

Conversation

@stonebuzz
Copy link
Copy Markdown
Contributor

@stonebuzz stonebuzz commented Sep 2, 2025

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

When the task involves configuring databases to be inventoried, this request is made through an autonomous curl call.

Under these conditions, $_SESSION['glpiname'] is not initialized with the name of the user who is connecting, which causes the following error when performing a search using the Search.php class:

[2025-09-02 13:29:03] glpiphplog.WARNING:   *** PHP Warning (2): Undefined array key "glpiname" in D:\wamp\www\glpi\src\Search.php at line 729
  Backtrace :
  ...nventory\inc\computergroupdynamic.class.php:183 Search::constructSQL()
  plugins\databaseinventory\inc\task.class.php:244   PluginDatabaseinventoryComputerGroupDynamic->isDynamicSearchMatchComputer()
  src\Plugin.php:1763                                PluginDatabaseinventoryTask::handleInventoryTask()
  src\Inventory\Request.php:420                      Plugin::doHookFunction()
  src\Inventory\Request.php:130                      Glpi\Inventory\Request->handleInventoryTask()
  src\Inventory\Request.php:340                      Glpi\Inventory\Request->handleTask()
  src\Inventory\Request.php:83                       Glpi\Inventory\Request->contact()
  src\Agent\Communication\AbstractRequest.php:359    Glpi\Inventory\Request->handleAction()
  src\Agent\Communication\AbstractRequest.php:271    Glpi\Agent\Communication\AbstractRequest->handleJSONRequest()
  front\inventory.php:100                            Glpi\Agent\Communication\AbstractRequest->handleRequest()
  plugins\glpiinventory\front\communication.php:72   include_once()
  plugins\glpiinventory\index.php:45                 include_once()

This PR forcibly sets $_SESSION['glpiname'] to 'databaseinventory_plugin' (useful for debugging) during the execution of the search, and restores the original value after the call to the Search class.

Fix : #73

Screenshots (if appropriate):

@stonebuzz stonebuzz requested a review from Lainow September 2, 2025 12:10
@stonebuzz stonebuzz self-assigned this Sep 2, 2025
@stonebuzz stonebuzz added the bug Something isn't working label Sep 2, 2025
@stonebuzz stonebuzz mentioned this pull request Sep 2, 2025
2 tasks
@stonebuzz stonebuzz merged commit 12b6d80 into main Sep 4, 2025
3 checks passed
@stonebuzz stonebuzz deleted the fix_undefined_index branch September 4, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic group or activing plugin ?

1 participant