You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2024-12-01 12:29:17

tikkit
Member
Registered: 2015-03-25
Posts: 22

10.0.16 - Undefined array key "pending" in PendingReason_Item.php

I occasionally see this kind of error messages in php-errors.log:

[2024-11-21 14:22:22] glpiphplog.WARNING:   *** PHP Warning (2): Undefined array key "pending" in D:\inetpub\wwwroot\glpi\src\PendingReason_Item.php at line 470
  Backtrace :
  src\CommonITILTask.php:424                         PendingReason_Item::handleTimelineEdits()
  src\CommonDBTM.php:1747                            CommonITILTask->post_updateItem()
  src\Ticket.php:2188                                CommonDBTM->update()
  src\CommonDBTM.php:1343                            Ticket->post_addItem()
  front\ticket.form.php:80                           CommonDBTM->add()
  public\index.php:82                                require()
 
[2024-11-21 14:22:22] glpiphplog.WARNING:   *** PHP Warning (2): Undefined array key "status" in D:\inetpub\wwwroot\glpi\src\PendingReason_Item.php at line 472
  Backtrace :
  src\CommonITILTask.php:424                         PendingReason_Item::handleTimelineEdits()
  src\CommonDBTM.php:1747                            CommonITILTask->post_updateItem()
  src\Ticket.php:2188                                CommonDBTM->update()
  src\CommonDBTM.php:1343                            Ticket->post_addItem()
  front\ticket.form.php:80                           CommonDBTM->add()
  public\index.php:82                                require()

I've put a var_dump in post_updateItem. When there's an error it shows:

2024-11-21 14:22:22 post_updateItem:\TicketTask::__set_state(array(
   'type' => -1,
   'displaylist' => true,
   'showdebug' => false,
   'taborientation' => 'vertical',
   'get_item_to_display_tab' => true,
   'fields' =>
  array (
    'id' => 63075,
    'uuid' => '62550643-6f33-405d-bfeb-83208f9071e0',
    'tickets_id' => 42439,
    'taskcategories_id' => 0,
    'date' => '2024-11-21 13:08:35',
    'users_id' => 12,
    'users_id_editor' => 0,
    'content' => '<p>…</p>',
    'is_private' => 0,
    'actiontime' => 1800,
    'begin' => NULL,
    'end' => NULL,
    'state' => 2,
    'users_id_tech' => 12,
    'groups_id_tech' => 0,
    'date_mod' => '2024-11-21 14:22:21',
    'date_creation' => '2024-11-21 13:08:35',
    'tasktemplates_id' => 0,
    'timeline_position' => 1,
    'sourceitems_id' => 0,
    'sourceof_items_id' => 42823,
  ),
   'input' =>
  array (
    'id' => '63075',
    'sourceof_items_id' => 42823,
    '_no_history' => false,
    'plan' => NULL,
    '_job' =>
    \Ticket::__set_state(array(
       'type' => -1,
       'displaylist' => true,
       'showdebug' => false,
       'taborientation' => 'vertical',
       'get_item_to_display_tab' => true,
       'fields' =>
      array (
      ),
       'input' =>
      array (
      ),
       'updates' =>
      array (
      ),
       'oldvalues' =>
      array (
      ),
       'dohistory' => true,
       'history_blacklist' =>
      array (
      ),
       'auto_message_on_action' => true,
       'no_form_page' => false,
       'additional_fields_for_dictionnary' =>
      array (
      ),
       'fkfield' => '',
       'searchopt' => false,
       'usenotepad' => false,
       'deduplicate_queued_notifications' => false,
       'right' => NULL,
       'lazy_loaded_users' => NULL,
       'userlinkclass' => 'Ticket_User',
       'lazy_loaded_groups' => NULL,
       'grouplinkclass' => 'Group_Ticket',
       'lazy_loaded_suppliers' => NULL,
       'supplierlinkclass' => 'Supplier_Ticket',
       'userentity_oncreate' => true,
       'last_clone_index' => NULL,
       'hardwaredatas' =>
      array (
      ),
       'computerfound' => 0,
    )),
  ),
   'updates' =>
  array (
    0 => 'sourceof_items_id',
    1 => 'date_mod',
  ),
   'oldvalues' =>
  array (
    'sourceof_items_id' => 0,
  ),
   'dohistory' => false,
   'history_blacklist' =>
  array (
  ),
   'auto_message_on_action' => false,
   'no_form_page' => false,
   'additional_fields_for_dictionnary' =>
  array (
  ),
   'fkfield' => '',
   'searchopt' => false,
   'usenotepad' => false,
   'deduplicate_queued_notifications' => true,
   'right' => NULL,
))

When there's no error it shows:

2024-11-21 14:23:16 post_updateItem:\TicketTask::__set_state(array(
   'type' => -1,
   'displaylist' => true,
   'showdebug' => false,
   'taborientation' => 'vertical',
   'get_item_to_display_tab' => true,
   'fields' =>
  array (
    'id' => 63077,
    'uuid' => 'e8ed41bc-c075-4d2a-9263-1cef36161ad2',
    'tickets_id' => 42777,
    'taskcategories_id' => 0,
    'date' => '2024-11-21 14:21:07',
    'users_id' => 12,
    'users_id_editor' => 12,
    'content' => '<p>…</p>',
    'is_private' => 0,
    'actiontime' => '4500',
    'begin' => NULL,
    'end' => NULL,
    'state' => 2,
    'users_id_tech' => 12,
    'groups_id_tech' => 0,
    'date_mod' => '2024-11-21 14:23:16',
    'date_creation' => '2024-11-21 14:21:07',
    'tasktemplates_id' => 0,
    'timeline_position' => 4,
    'sourceitems_id' => 0,
    'sourceof_items_id' => 0,
  ),
   'input' =>
  array (
    'itemtype' => 'Ticket',
    'tickets_id' => '42777',
    'content' => '<p>…</p>',
    'tasktemplates_id' => '0',
    'date' => '2024-11-21 14:21:07',
    'taskcategories_id' => '0',
    'state' => '2',
    'is_private' => '0',
    '_task_to_kb' => '0',
    'actiontime' => '4500',
    'users_id_tech' => '12',
    'groups_id_tech' => '0',
    'id' => '63077',
    'pending' => '0',
    'followup_frequency' => '0',
    'followups_before_resolution' => '0',
    '_glpi_csrf_token' => 'c841c44078f3ee49ccc46b62f1d5885cd20e8deb950654913930e20e16f0d9f2',
    '_no_history' => false,
    '_update' => '',
    'plan' => NULL,
    'users_id_editor' => 12,
    '_job' =>
    \Ticket::__set_state(array(
       'type' => -1,
       'displaylist' => true,
       'showdebug' => false,
       'taborientation' => 'vertical',
       'get_item_to_display_tab' => true,
       'fields' =>
      array (
        'id' => 42777,
        'entities_id' => 0,
        'name' => '…',
        'date' => '2024-11-15 09:29:17',
        'closedate' => NULL,
        'solvedate' => NULL,
        'takeintoaccountdate' => '2024-11-15 09:29:17',
        'date_mod' => '2024-11-21 14:21:07',
        'users_id_lastupdater' => 12,
        'status' => 2,
        'users_id_recipient' => 12,
        'requesttypes_id' => 1,
        'content' => '<p>…</p>',
        'urgency' => 3,
        'impact' => 3,
        'priority' => 3,
        'itilcategories_id' => 48,
        'type' => 2,
        'global_validation' => 1,
        'slas_id_ttr' => 0,
        'slas_id_tto' => 0,
        'slalevels_id_ttr' => 0,
        'time_to_resolve' => NULL,
        'time_to_own' => NULL,
        'begin_waiting_date' => NULL,
        'sla_waiting_duration' => 0,
        'ola_waiting_duration' => 0,
        'olas_id_tto' => 0,
        'olas_id_ttr' => 0,
        'olalevels_id_ttr' => 0,
        'ola_ttr_begin_date' => NULL,
        'internal_time_to_resolve' => NULL,
        'internal_time_to_own' => NULL,
        'waiting_duration' => 0,
        'close_delay_stat' => 0,
        'solve_delay_stat' => 0,
        'takeintoaccount_delay_stat' => 1,
        'actiontime' => 0,
        'is_deleted' => 0,
        'locations_id' => 60,
        'validation_percent' => 0,
        'date_creation' => '2024-11-15 09:29:17',
        'ola_tto_begin_date' => NULL,
      ),
       'input' =>
      array (
      ),
       'updates' =>
      array (
      ),
       'oldvalues' =>
      array (
      ),
       'dohistory' => true,
       'history_blacklist' =>
      array (
      ),
       'auto_message_on_action' => true,
       'no_form_page' => false,
       'additional_fields_for_dictionnary' =>
      array (
      ),
       'fkfield' => '',
       'searchopt' => false,
       'usenotepad' => false,
       'deduplicate_queued_notifications' => false,
       'right' => NULL,
       'lazy_loaded_users' => NULL,
       'userlinkclass' => 'Ticket_User',
       'lazy_loaded_groups' => NULL,
       'grouplinkclass' => 'Group_Ticket',
       'lazy_loaded_suppliers' => NULL,
       'supplierlinkclass' => 'Supplier_Ticket',
       'userentity_oncreate' => true,
       'last_clone_index' => NULL,
       'hardwaredatas' =>
      array (
      ),
       'computerfound' => 0,
    )),
  ),
   'updates' =>
  array (
    0 => 'actiontime',
    1 => 'users_id_editor',
    2 => 'date_mod',
  ),
   'oldvalues' =>
  array (
    'actiontime' => 0,
    'users_id_editor' => 0,
  ),
   'dohistory' => false,
   'history_blacklist' =>
  array (
  ),
   'auto_message_on_action' => false,
   'no_form_page' => false,
   'additional_fields_for_dictionnary' =>
  array (
  ),
   'fkfield' => '',
   'searchopt' => false,
   'usenotepad' => false,
   'deduplicate_queued_notifications' => true,
   'right' => NULL,
))

I'm not yet sure what triggers it, so I can't reproduce it myself. Any hints on what causes this or how I could further debug it?

Offline

#2 2025-01-31 20:50:51

tikkit
Member
Registered: 2015-03-25
Posts: 22

Re: 10.0.16 - Undefined array key "pending" in PendingReason_Item.php

# Steps to reproduce
  1. Create a new ticket.

  2. Add a task to the ticket with status = To do and set status to pending checked.

  3. When the task is created, click its To do box.

  4. Refresh the ticket.

# Actual result
  1. After step 1 the ticket's status is new.

  2. After step 2 the ticket's status is pending.

  3. After step 3 the task's status is done.

  4. After step 4 the ticket's status is new.

  5. php-errors.log shows Undefined array key "pending" in /var/www/glpi/src/PendingReason_Item.php.

# Expected result
  1. After step 1 the ticket's status is new.

  2. After step 2 the ticket's status is pending.

  3. After step 3 the task's status is done.

  4. After step 3 the ticket's status is new.

  5. Nothing added to php-errors.log.

So the updates seem to be correct. There's just this annoying warning in the logs.

# Analysis

Function handleTimelineEdits in PendingReason_Item.php has this construction:

if ($timeline_item->input['pending'] ?? 0) {
    …
} else if (!$timeline_item->input['pending'] ?? 1) {
    // Change status of parent if needed
    …
}

The warning points to the second if statement. The execution path leads there if either the array key is undefined or if it's false.

## Item is undefined

If the array key is undefined, the code evaluates to:

if (null ?? 0) {
    …
} else if (!null ?? 1) {
    …
}

and further:

if (0) {
    …
} else if (true ?? 1) {
    …
}
## Item is false

If the item is false, the code evaluates to:

if (false ?? 0) {
    …
} else if (!false ?? 1) {
    …
}

and further:

if (false) {
    …
} else if (true ?? 1) {
    …
}
## Conclusion

The second if block is always executed if the else is reached. So the condition is redundant and the code can be simplified to:

if ($timeline_item->input['pending'] ?? 0) {
    …
} else {
    // Change status of parent if needed
    …
}

thereby also avoiding the warning message.

I tried this on my test environment and it seems to work. Please review this change and implement it if you agree that it's an improvement.

Offline

#3 2025-02-15 21:23:57

tikkit
Member
Registered: 2015-03-25
Posts: 22

Re: 10.0.16 - Undefined array key "pending" in PendingReason_Item.php

The suggested change in patch format:

--- a/src/PendingReason_Item.php
+++ b/src/PendingReason_Item.php
@@ -504,7 +504,7 @@ class PendingReason_Item extends CommonDBRelation
                         self::updateForItem($timeline_item->input['_job'], $pending_updates);
                     }
                 }
-            } else if (!$timeline_item->input['pending'] ?? 1) {
+            } else {
                // Change status of parent if needed
                 if ($timeline_item->input["_job"]->fields['status'] == CommonITILObject::WAITING) {
                     // get previous stored status for parent

Offline

#4 2025-02-17 09:12:05

lordbat
Member
From: Spain
Registered: 2016-02-12
Posts: 179

Re: 10.0.16 - Undefined array key "pending" in PendingReason_Item.php

tikkit wrote:

The suggested change in patch format:

--- a/src/PendingReason_Item.php
+++ b/src/PendingReason_Item.php
@@ -504,7 +504,7 @@ class PendingReason_Item extends CommonDBRelation
                         self::updateForItem($timeline_item->input['_job'], $pending_updates);
                     }
                 }
-            } else if (!$timeline_item->input['pending'] ?? 1) {
+            } else {
                // Change status of parent if needed
                 if ($timeline_item->input["_job"]->fields['status'] == CommonITILObject::WAITING) {
                     // get previous stored status for parent

I suggest you check the glpi github since the latest version is 10.0.18 maybe this is fixed. If is not you can report this issue o even do a pull request with your fix.

Regards!


You can mark this thread as [Solved] in the subject of your thread. (This is only available edit of the first post.) It is good for users who help others to quickly see which post is still open.
############################################################

Offline

#5 2025-02-20 20:55:37

tikkit
Member
Registered: 2015-03-25
Posts: 22

Re: 10.0.16 - Undefined array key "pending" in PendingReason_Item.php

I'm on 10.0.18 since last week. It's not yet fixed. I'd rather not use Github. Seeing as this forum category is specifically meant for bugs, I'm hoping that the developers (or triagers) will check here every so often.

Offline

Board footer

Powered by FluxBB