diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e904df..9d208f02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fix `json_decode` using class with namespace - Fix drag and drop - Increased the maximum length of the language column to support longer locale codes diff --git a/hook.php b/hook.php index c38b7619..86f11568 100644 --- a/hook.php +++ b/hook.php @@ -338,7 +338,7 @@ function plugin_datainjection_populate_fields() $container = new PluginFieldsContainer(); $found = $container->find(['is_active' => 1]); foreach ($found as $values) { - $types = json_decode($values['itemtypes']); + $types = PluginFieldsToolbox::decodeJSONItemtypes($values['itemtypes']); foreach ($types as $type) { $classname = PluginFieldsContainer::getClassname($type, $values['name'], 'Injection'); diff --git a/inc/container.class.php b/inc/container.class.php index e6ccd70c..5baa4c80 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -172,7 +172,7 @@ public static function installBaseData(Migration $migration, $version) foreach ($result as $type) { $migration_genericobject_itemtype[$type['itemtype']] = [ 'genericobject_itemtype' => $type['itemtype'], - 'itemtype' => 'Glpi\CustomAsset\\' . $type['name'] . 'Asset', + 'itemtype' => 'Glpi\\\\CustomAsset\\\\' . $type['name'] . 'Asset', 'genericobject_name' => $type['name'], 'name' => $type['name'] . 'Asset', ]; @@ -191,7 +191,7 @@ public static function installBaseData(Migration $migration, $version) $container_class = new self(); foreach ($result as $container) { self::generateTemplate($container); - foreach (json_decode($container['itemtypes']) as $itemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) { $classname = self::getClassname($itemtype, $container["name"]); $old_table = $classname::getTable(); // Rename genericobject container table @@ -239,7 +239,7 @@ public static function installUserData(Migration $migration, $version) foreach ($containers as $container) { $itemtypes = []; if (!empty($container['itemtypes'])) { - $decoded = json_decode($container['itemtypes'], true); + $decoded = PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes'], true); if (is_array($decoded)) { $itemtypes = $decoded; } @@ -290,7 +290,7 @@ public static function installUserData(Migration $migration, $version) // Update container name $new_name = $toolbox->getSystemNameFromLabel($container['label']); - foreach (json_decode($container['itemtypes']) as $itemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) { while (strlen(getTableForItemType(self::getClassname($itemtype, $new_name))) > 64) { // limit tables names to 64 chars (MySQL limit) $new_name = substr($new_name, 0, -1); @@ -304,7 +304,7 @@ public static function installUserData(Migration $migration, $version) ); // Rename container tables and itemtype if needed - foreach (json_decode($container['itemtypes']) as $itemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) { $migration->renameItemtype( self::getClassname($itemtype, $old_name), self::getClassname($itemtype, $new_name), @@ -640,7 +640,7 @@ public function prepareInputForAdd($input) $found = $this->find(['type' => 'dom']); if (count($found) > 0) { foreach (array_column($found, 'itemtypes') as $founditemtypes) { - foreach (json_decode($founditemtypes) as $founditemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR); @@ -656,7 +656,7 @@ public function prepareInputForAdd($input) $found = $this->find(['type' => 'domtab', 'subtype' => $input['subtype']]); if (count($found) > 0) { foreach (array_column($found, 'itemtypes') as $founditemtypes) { - foreach (json_decode($founditemtypes) as $founditemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", 'fields'), false, ERROR); @@ -688,7 +688,7 @@ public function prepareInputForAdd($input) $found = $this->find(['name' => $input['name']]); if (count($found) > 0) { foreach (array_column($found, 'itemtypes') as $founditemtypes) { - foreach (json_decode($founditemtypes) as $founditemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { Session::AddMessageAfterRedirect(__('You cannot add several blocs with identical name on same object', 'fields'), false, ERROR); @@ -781,7 +781,7 @@ public function pre_deleteItem() $_SESSION['delete_container'] = true; - foreach (json_decode($this->fields['itemtypes']) as $itemtype) { + foreach (PluginFieldsToolbox::decodeJSONItemtypes($this->fields['itemtypes']) as $itemtype) { $classname = self::getClassname($itemtype, $this->fields['name']); $sysname = self::getSystemName($itemtype, $this->fields['name']); $class_filename = $sysname . '.class.php'; @@ -843,7 +843,7 @@ public static function preItemPurge($item) $containers = new self(); $founded_containers = $containers->find(); foreach ($founded_containers as $container) { - $itemtypes = json_decode($container['itemtypes']); + $itemtypes = PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']); if (in_array($itemtype, $itemtypes)) { $classname = 'PluginFields' . $itemtype . getSingular($container['name']); $classname = preg_replace('/s{2}$/i', 's', $classname); // in case name ends with 'ss' remove last 's' @@ -928,7 +928,7 @@ public function showForm($ID, $options = []) echo '