diff --git a/CHANGELOG.md b/CHANGELOG.md index 233952fe40..79f1d5dea3 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 +- Prevent invalid references and non-existent classes during generate item flow. - 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..36e101151d 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"]); + if ( + $item === false + || (int) $row["templates_id"] === 0 + || !$item->getFromDB($row["templates_id"]) + ) { + return 0; + } + if ($item->getField('entities_id') == $entity || ($item->maybeRecursive() && $item->fields['is_recursive']