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 diff --git a/inc/container.class.php b/inc/container.class.php index b2c3f0cd..cc124506 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -687,13 +687,16 @@ 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), ], $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) { @@ -712,7 +715,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/setup.php b/setup.php index 1b02c436..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'])) { 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']);