From 59051a65ade9a6e0eb0233b3069ea430afa62085 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 20 Jan 2026 14:19:58 +0100 Subject: [PATCH 1/3] fix(migration): resolve compile error during plugin update with genericobject asset --- inc/container.class.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index f31e4241..ef8a7a3a 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -213,6 +213,11 @@ public static function installBaseData(Migration $migration, $version) self::generateTemplate($container); foreach (json_decode((string) $container['itemtypes']) as $itemtype) { $classname = self::getClassname($itemtype, $container["name"]); + // prevent usage of plugin class if not loaded + if (!class_exists($classname)) { + continue; + } + $old_table = $classname::getTable(); // Rename genericobject container table if ( @@ -741,8 +746,10 @@ public static function create($fields) foreach (PluginFieldsToolbox::decodeJSONItemtypes($fields['itemtypes']) as $itemtype) { //install table for receive field - $classname = self::getClassname($itemtype, $fields['name']); - $classname::install(); + if (class_exists($itemtype)) { + $classname = self::getClassname($itemtype, $fields['name']); + $classname::install(); + } } return null; @@ -754,20 +761,30 @@ public static function generateTemplate($fields) ? PluginFieldsToolbox::decodeJSONItemtypes($fields['itemtypes'], true) : []; foreach ($itemtypes as $itemtype) { + + $sysname = self::getSystemName($itemtype, $fields['name']); + $classname = self::getClassname($itemtype, $fields['name']); + $class_filename = $sysname . '.class.php'; + $injection_filename = $sysname . 'injection.class.php'; + // prevent usage of plugin class if not loaded if (!class_exists($itemtype)) { + //remove file + if (file_exists(PLUGINFIELDS_CLASS_PATH . ('/' . $class_filename))) { + unlink(PLUGINFIELDS_CLASS_PATH . ('/' . $class_filename)); + } + + if (file_exists(PLUGINFIELDS_CLASS_PATH . ('/' . $injection_filename))) { + unlink(PLUGINFIELDS_CLASS_PATH . ('/' . $injection_filename)); + } continue; } - $sysname = self::getSystemName($itemtype, $fields['name']); - $classname = self::getClassname($itemtype, $fields['name']); - $template_class = file_get_contents(PLUGINFIELDS_DIR . '/templates/container.class.tpl'); $template_class = str_replace('%%CLASSNAME%%', $classname, $template_class); $template_class = str_replace('%%ITEMTYPE%%', $itemtype, $template_class); $template_class = str_replace('%%CONTAINER%%', $fields['id'], $template_class); $template_class = str_replace('%%ITEMTYPE_RIGHT%%', $itemtype::$rightname, $template_class); - $class_filename = $sysname . '.class.php'; if (file_put_contents(PLUGINFIELDS_CLASS_PATH . ('/' . $class_filename), $template_class) === false) { Toolbox::logDebug('Error : class file creation - ' . $class_filename); @@ -780,9 +797,8 @@ public static function generateTemplate($fields) $template_class = str_replace('%%ITEMTYPE%%', $itemtype, $template_class); $template_class = str_replace('%%CONTAINER_ID%%', $fields['id'], $template_class); $template_class = str_replace('%%CONTAINER_NAME%%', $fields['label'], $template_class); - $class_filename = $sysname . 'injection.class.php'; - if (file_put_contents(PLUGINFIELDS_CLASS_PATH . ('/' . $class_filename), $template_class) === false) { - Toolbox::logDebug('Error : datainjection class file creation - ' . $class_filename); + if (file_put_contents(PLUGINFIELDS_CLASS_PATH . ('/' . $injection_filename), $template_class) === false) { + Toolbox::logDebug('Error : datainjection class file creation - ' . $injection_filename); return false; } From fb5ffd730c15eacb021cbaf3185df7ba3c90e91c Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 20 Jan 2026 15:07:44 +0100 Subject: [PATCH 2/3] fix lint --- inc/container.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/container.class.php b/inc/container.class.php index ef8a7a3a..805eb58a 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -777,6 +777,7 @@ public static function generateTemplate($fields) if (file_exists(PLUGINFIELDS_CLASS_PATH . ('/' . $injection_filename))) { unlink(PLUGINFIELDS_CLASS_PATH . ('/' . $injection_filename)); } + continue; } From 821d7296e5b4051ac9e0c6e158d15ce5c8210f94 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 20 Jan 2026 15:10:20 +0100 Subject: [PATCH 3/3] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6bf7bd..c3d4749d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add compatibility with GLPI `CustomAsset` +### Fixed + +- Fix migration error caused by unknown itemtype in containers ## [1.23.2] - 2025-12-22