Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
119 changes: 119 additions & 0 deletions inc/categoryinjection.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

/**
* -------------------------------------------------------------------------
* 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 <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @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 <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @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

Check failure on line 61 in inc/categoryinjection.class.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.5 - mariadb:11.8 / Continuous integration

Class PluginDatainjectionCategoryInjection extends final class Glpi\Form\Category.

Check failure on line 61 in inc/categoryinjection.class.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Class PluginDatainjectionCategoryInjection extends final class Glpi\Form\Category.
{
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;
}
}
2 changes: 2 additions & 0 deletions inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 2 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -141,6 +141,7 @@ function getTypesToInject(): void
'PluginDatainjectionGroup_UserInjection' => 'datainjection',
'PluginDatainjectionInfocomInjection' => 'datainjection',
'PluginDatainjectionLocationInjection' => 'datainjection',
'PluginDatainjectionCategoryInjection' => 'datainjection',
'PluginDatainjectionStateInjection' => 'datainjection',
'PluginDatainjectionManufacturerInjection' => 'datainjection',
'PluginDatainjectionMonitorInjection' => 'datainjection',
Expand Down
Loading