diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b0eea9..f3edab26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix `name` and `locations_id` when updating the `completename` - Fix user field updates and email import +### Added + +- Handle `Service catalog category` + ## [2.15.2] - 2025-11-25 ### Fixed diff --git a/inc/categoryinjection.class.php b/inc/categoryinjection.class.php new file mode 100644 index 00000000..edfda088 --- /dev/null +++ b/inc/categoryinjection.class.php @@ -0,0 +1,119 @@ +. + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2007-2023 by DataInjection plugin team. + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/datainjection + * ------------------------------------------------------------------------- + */ + +use Glpi\Form\Category; + +/** + * ------------------------------------------------------------------------- + * DataInjection plugin for GLPI + * ------------------------------------------------------------------------- + * + * LICENSE + * + * This file is part of DataInjection. + * + * DataInjection is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DataInjection is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DataInjection. If not, see . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2007-2023 by DataInjection plugin team. + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/datainjection + * ------------------------------------------------------------------------- + */ + +class PluginDatainjectionCategoryInjection extends Category implements PluginDatainjectionInjectionInterface +{ + public static function getTable($classname = null) + { + $parenttype = get_parent_class(self::class); + return $parenttype::getTable(); + } + + public function isPrimaryType() + { + return true; + } + + public function connectedTo() + { + return []; + } + + public function isNullable($field) + { + return !in_array($field, ['illustration']); + } + + /** + * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() + */ + public function getOptions($primary_type = '') + { + $tab = Search::getOptions(get_parent_class($this)); + + //Remove some options because some fields cannot be imported + $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); + $options['ignore_fields'] = $blacklist; + + return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); + } + + /** + * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject() + **/ + public function addOrUpdateObject($values = [], $options = []) + { + $values = $this->fixCategoryTreeStructure($values); + $lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options); + $lib->processAddOrUpdate(); + return $lib->getInjectionResults(); + } + + public function fixCategoryTreeStructure($values) + { + if (isset($values['Category']['completename']) && !isset($values['Category']['name']) && !str_contains($values['Category']['completename'], '>')) { + $values['Category']['name'] = trim($values['Category']['completename']); + $values['Category']['forms_categories_id'] = '0'; + $values['Category']['ancestors_cache'] = '[]'; + } + + return $values; + } +} diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index 2bfdabc2..01f95307 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -341,10 +341,12 @@ public static function getInjectionClassInstance($itemtype) { if (!isPluginItemType($itemtype)) { + $itemtype = (new ReflectionClass($itemtype))->getShortName(); // get shortname of class when full namespaced class given (from GLPI) $injectionClass = 'PluginDatainjection' . ucfirst($itemtype) . 'Injection'; } else { $injectionClass = ucfirst($itemtype) . 'Injection'; } + if (!is_a($injectionClass, PluginDatainjectionInjectionInterface::class, true)) { throw new HttpException(500, 'Class ' . $injectionClass . ' is not a valid class'); } diff --git a/setup.php b/setup.php index 84e4dac8..efaf2a96 100644 --- a/setup.php +++ b/setup.php @@ -34,7 +34,7 @@ define('PLUGIN_DATAINJECTION_VERSION', '2.15.2'); // Minimal GLPI version, inclusive -define("PLUGIN_DATAINJECTION_MIN_GLPI", "11.0.0"); +define("PLUGIN_DATAINJECTION_MIN_GLPI", "11.0.5"); // Maximum GLPI version, exclusive define("PLUGIN_DATAINJECTION_MAX_GLPI", "11.0.99"); @@ -141,6 +141,7 @@ function getTypesToInject(): void 'PluginDatainjectionGroup_UserInjection' => 'datainjection', 'PluginDatainjectionInfocomInjection' => 'datainjection', 'PluginDatainjectionLocationInjection' => 'datainjection', + 'PluginDatainjectionCategoryInjection' => 'datainjection', 'PluginDatainjectionStateInjection' => 'datainjection', 'PluginDatainjectionManufacturerInjection' => 'datainjection', 'PluginDatainjectionMonitorInjection' => 'datainjection',