From b5ca803f7d8de310587652823820349e23410692 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 14:12:11 +0100 Subject: [PATCH 1/4] Fix(Install): fix template generation error --- inc/container.class.php | 4 ++-- templates/container.class.tpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index b2c3f0cd..b3b7b95e 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -687,7 +687,7 @@ public static function generateTemplate($fields) ['%%CLASSNAME%%', '%%ITEMTYPE%%', '%%CONTAINER%%', '%%ITEMTYPE_RIGHT%%'], [ $classname, - var_export($itemtype, true), + str_replace('\'','', var_export($itemtype, true)), var_export($fields['id'], true), var_export($itemtype::$rightname, true), ], @@ -712,7 +712,7 @@ public static function generateTemplate($fields) ['%%CLASSNAME%%', '%%ITEMTYPE%%', '%%CONTAINER_ID%%', '%%CONTAINER_NAME%%'], [ $classname, - var_export($itemtype, true), + str_replace('\'','', var_export($itemtype, true)), var_export($fields['id'], true), var_export($fields['label'], true), ], diff --git a/templates/container.class.tpl b/templates/container.class.tpl index 0e6f36e4..19aefa4f 100644 --- a/templates/container.class.tpl +++ b/templates/container.class.tpl @@ -51,7 +51,7 @@ class %%CLASSNAME%% extends PluginFieldsAbstractContainerInstance * This block ensures that the 'entities_id' field is created and populated if it * associated item type requires entity assignment */ - if (getItemForItemtype("%%ITEMTYPE%%")->isEntityAssign() && !$DB->fieldExists($table, 'entities_id')) { + if (getItemForItemtype(%%ITEMTYPE%%::class)->isEntityAssign() && !$DB->fieldExists($table, 'entities_id')) { $migration->addField($table, 'entities_id', 'fkey', ['after' => 'plugin_fields_containers_id']); $migration->addKey($table, 'entities_id'); $migration->executeMigration(); @@ -107,7 +107,7 @@ class %%CLASSNAME%% extends PluginFieldsAbstractContainerInstance * associated item type requires recursive assignment */ if ( - getItemForItemtype("%%ITEMTYPE%%")->maybeRecursive() + getItemForItemtype(%%ITEMTYPE%%::class)->maybeRecursive() && !$DB->fieldExists($table, 'is_recursive') && $DB->fieldExists($table, 'entities_id')) { $migration->addField($table, 'is_recursive', 'bool', ['after' => 'entities_id']); From a0ad37fb2673ec00941f7d73e34005b125bbba0f Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 14:12:48 +0100 Subject: [PATCH 2/4] adapt changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f4e3cd..b76085d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +- Fix template generation error on update + + ## [1.21.26] - 2026-02-12 ### Fixed From 1b53101257e5d7752b7f969ccd74b397fcd2fc6f Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 14:24:19 +0100 Subject: [PATCH 3/4] force genericobject load --- inc/container.class.php | 4 ++-- setup.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index b3b7b95e..b4ed0169 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -687,7 +687,7 @@ public static function generateTemplate($fields) ['%%CLASSNAME%%', '%%ITEMTYPE%%', '%%CONTAINER%%', '%%ITEMTYPE_RIGHT%%'], [ $classname, - str_replace('\'','', var_export($itemtype, true)), + str_replace('\'', '', var_export($itemtype, true)), var_export($fields['id'], true), var_export($itemtype::$rightname, true), ], @@ -712,7 +712,7 @@ public static function generateTemplate($fields) ['%%CLASSNAME%%', '%%ITEMTYPE%%', '%%CONTAINER_ID%%', '%%CONTAINER_NAME%%'], [ $classname, - str_replace('\'','', var_export($itemtype, true)), + str_replace('\'', '', var_export($itemtype, true)), var_export($fields['id'], true), var_export($fields['label'], true), ], diff --git a/setup.php b/setup.php index 1b02c436..b880061d 100644 --- a/setup.php +++ b/setup.php @@ -110,6 +110,8 @@ function plugin_init_fields() = ['PluginFieldsInventory', 'updateInventory']; } + Plugin::load('genericobject', true); + // complete rule engine $PLUGIN_HOOKS['use_rules']['fields'] = ['PluginFusioninventoryTaskpostactionRule']; $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched'; From f3eb1f8b47147c3f92c08744b0824e2f9f1bd501 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 14:39:27 +0100 Subject: [PATCH 4/4] fix CLI install --- inc/container.class.php | 3 +++ setup.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index b4ed0169..cc124506 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -694,6 +694,9 @@ public static function generateTemplate($fields) $template_class, ); + Toolbox::logDebug(str_replace('\'', '', var_export($itemtype, true))); + Toolbox::logDebug(var_export($itemtype, true)); + $class_filename = basename($sysname) . '.class.php'; $filepath = rtrim(PLUGINFIELDS_CLASS_PATH, '/') . '/' . $class_filename; if (file_put_contents($filepath, $template_class) === false) { diff --git a/setup.php b/setup.php index b880061d..7f329160 100644 --- a/setup.php +++ b/setup.php @@ -86,6 +86,8 @@ function plugin_init_fields() $pluginfields_autoloader = new PluginFieldsAutoloader([PLUGINFIELDS_CLASS_PATH]); $pluginfields_autoloader->register(); + Plugin::load('genericobject', true); + if ((Session::getLoginUserID() || isCommandLine()) && Plugin::isPluginActive('fields')) { // Init hook about itemtype(s) for plugin fields if (!isset($PLUGIN_HOOKS['plugin_fields'])) { @@ -110,8 +112,6 @@ function plugin_init_fields() = ['PluginFieldsInventory', 'updateInventory']; } - Plugin::load('genericobject', true); - // complete rule engine $PLUGIN_HOOKS['use_rules']['fields'] = ['PluginFusioninventoryTaskpostactionRule']; $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched';