diff --git a/CHANGELOG.md b/CHANGELOG.md index 233952fe40..8cdce0d51e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix generate associated item massive action +- Add safety guards in Generate item flow for invalid references and non-existent classes (GLPI 11 / PHP 8.3) - Update locales diff --git a/inc/link.class.php b/inc/link.class.php index 8af76df2a8..9af3c3015a 100644 --- a/inc/link.class.php +++ b/inc/link.class.php @@ -148,7 +148,8 @@ public function showItemGenerationForm($params) $row['template_name'] = ""; } - if (Toolbox::hasTrait($itemtype, AssignableItem::class)) { + // GLPI 11 safety: skip non-existent classes (e.g. uninstalled plugins like GenericObject) + if (class_exists($itemtype) && Toolbox::hasTrait($itemtype, AssignableItem::class)) { $row['assignableitem'] = true; if (!is_array($row['groups_id'])) { $row['groups_id'] = $row['groups_id'] > 0 ? [$row['groups_id']] : []; @@ -174,7 +175,7 @@ public function showItemGenerationForm($params) 'active_entities' => $_SESSION['glpiactiveentities'] ?? [], 'item_rows' => $item_rows, 'order_web_dir' => $order_web_dir, - 'assignableitem' => Toolbox::hasTrait($itemtype, AssignableItem::class), + 'assignableitem' => class_exists($itemtype) && Toolbox::hasTrait($itemtype, AssignableItem::class), ]); return null; } diff --git a/inc/reference.class.php b/inc/reference.class.php index a54866540b..e7e5fb8c73 100644 --- a/inc/reference.class.php +++ b/inc/reference.class.php @@ -471,7 +471,14 @@ public function checkIfTemplateExistsInEntity($detailID, $itemtype, $entity) } else { $row = $result->current(); $item = getItemForItemtype($itemtype); - $item->getFromDB($row["templates_id"]); + // GLPI 11 safety: custom asset classes may fail to resolve in HTTP context + // and templates_id may be 0 for entries created before plugin migration. + if ($item === false || empty($row["templates_id"])) { + return 0; + } + if (!$item->getFromDB($row["templates_id"])) { + return 0; + } if ($item->getField('entities_id') == $entity || ($item->maybeRecursive() && $item->fields['is_recursive']