glpi-project / glpi-inventory-plugin

GLPI Inventory plugin
GNU Affero General Public License v3.0
46 stars 27 forks source link

deploygroup.class.php : Undefined array key "type" #338

Closed AnthoDingo closed 1 year ago

AnthoDingo commented 1 year ago

Describe the bug

On computer package deployment, I can't get my packages. Every time, the API return error 500 on my web browser console.

I open the target url, I get this error :

PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 442
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 625

To reproduce

  1. Go to a computer asset
  2. Go to Package Deploy
  3. Open web browser debug

Expected behavior

The pakage input list must appear

Operating system

Windows

GLPI Agent version

1.4

GLPI version

10.0.6

GLPIInventory plugin

1.1.0

Additional context

No response

stonebuzz commented 1 year ago

Hi @AnthoDingo

From your deploy group, type is defined ?

image

Best regards

AnthoDingo commented 1 year ago

Yes, all groups type are defined. I checked on the web ui and in the db in table glpi_plugin_glpiinventory_deploygroups : image

stonebuzz commented 1 year ago

I open the target url, I get this error :

what url are you talking about, can you provide a screenshot?

AnthoDingo commented 1 year ago

The target URL is the ajax : image

Full url : http://myserver/glpi/ajax/common.tabs.php?_target=/glpi/front/computer.form.php&_itemtype=Computer&_glpi_tab=PluginGlpiinventoryDeployPackage$1&id=853&withtemplate=&formoptions=data-track-changes%3Dtrue

The GLPI is under http://myserver/glpi/

stonebuzz commented 1 year ago

what is the version of PHP?

stonebuzz commented 1 year ago

Could you test the develop branch

I don't reproduce and I worked on the deploy group part some time ago

AnthoDingo commented 1 year ago

what is the version of PHP?

I'm using PHP 8.1.17:

Operating system: Windows NT 10.0 build 19044 (Windows 10) AMD64
PHP 8.1.17 cgi-fcgi (Core, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, bcmath, bz2, calendar, cgi-fcgi, ctype, curl,
    date, dom, exif, fileinfo, filter, gd, hash, iconv, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, openssl, pcre,
    pdo_mysql, readline, session, sodium, standard, tokenizer, xml, xmlreader, xmlwriter, zip, zlib)
Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files"
    upload_max_filesize="2M" 
Software: Microsoft-IIS/10.0
    Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62
Server Software: mariadb.org binary distribution
    Server Version: 10.6.7-MariaDB
    Server SQL Mode: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    Parameters: glpi@localhost/glpi
    Host info: localhost via TCP/IP

PHP version (8.1.17) is supported.PHP version (8.1.17) is supported.
Sessions configuration is OK.Sessions configuration is OK.
Allocated memory is sufficient.Allocated memory is sufficient.
mysqli extension is installed.mysqli extension is installed.
Following extensions are installed: dom, fileinfo, json, simplexml.Following extensions are installed: dom, fileinfo, json, simplexml.
curl extension is installed.curl extension is installed.
gd extension is installed.gd extension is installed.
intl extension is installed.intl extension is installed.
libxml extension is installed.libxml extension is installed.
zlib extension is installed.zlib extension is installed.
The constant SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES is present.The constant SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES is present.
Database engine version (10.6.7) is supported.Database engine version (10.6.7) is supported.
No files from previous GLPI version detected.No files from previous GLPI version detected.
The log file has been created successfully.The log file has been created successfully.
GLPI data directories are located in a secured path.GLPI data directories are located in a secured path.
Sessions configuration is secured.Sessions configuration is secured.
exif extension is installed.exif extension is installed.
ldap extension is installed.ldap extension is installed.
openssl extension is installed.openssl extension is installed.
zip extension is installed.zip extension is installed.
bz2 extension is installed.bz2 extension is installed.
Zend OPcache extension is installed.Zend OPcache extension is installed.
Following extensions are installed: ctype, iconv, mbstring, sodium.Following extensions are installed: ctype, iconv, mbstring, sodium.
Timezones seems loaded in database.Timezones seems loaded in database.
AnthoDingo commented 1 year ago

Could you test the develop branch

I don't reproduce and I worked on the deploy group part some time ago

Same error on the developp branch:

PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 473
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
AnthoDingo commented 1 year ago

I found a temporary solution and not clean, I disable the "error_reporting" settings in my php.in from:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

to:

error_reporting = Off
cedric-anne commented 1 year ago

It probably means that asset package is linked to a group that does not exists anymore. Following patch would prevent this issue, but I guess an additional patch is required to ensure that removing a group correctly update related packages.

diff --git a/inc/deploygroup.class.php b/inc/deploygroup.class.php
index ded198756..203521735 100644
--- a/inc/deploygroup.class.php
+++ b/inc/deploygroup.class.php
@@ -612,11 +612,10 @@ class PluginGlpiinventoryDeployGroup extends CommonDBTM
     */
     public static function getTargetsForGroup($groups_id, $use_cache = false)
     {
-        $group = new self();
-        $group->getFromDB($groups_id);
-
         $results = [];
-        if ($group->isStaticGroup()) {
+
+        $group = new self();
+        if ($group->getFromDB($groups_id) && $group->isStaticGroup()) {
             $staticgroup = new PluginGlpiinventoryDeployGroup_Staticdata();
             foreach (
                 $staticgroup->find(
AnthoDingo commented 1 year ago

Hello,

The fix has half solved the problem. Error line 473 has gone, however, the error line 673 still present:

PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
PHP Warning:  Undefined array key "type" in glpi\10.0.6\plugins\glpiinventory\inc\deploygroup.class.php on line 656
stonebuzz commented 1 year ago

Can you check from your database (table glpi_plugin_glpiinventory_deploypackages_groups)

If a row is related to non exist deploy group.

try this SQL query

SELECT * FROM glpi_plugin_glpiinventory_deploypackages_groups WHERE  groups_id NOT IN 
(SELECT id FROM glpi_plugin_glpiinventory_deploygroups )

If you find any, just delete them