diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a279c098..0728b59e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -20,7 +20,7 @@ jobs: name: "Generate CI matrix" uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1" with: - glpi-version: "11.0.x" + glpi-version: "12.0.x" ci: name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" needs: "generate-ci-matrix" diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd91373..964dbd66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [2.15.11] - 2026-09-11 +### Added + +- GLPI 12 compatibility + ### Fixed - Move to iterator diff --git a/composer.json b/composer.json index cd9a47c2..05547d5d 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "php": ">=8.2" }, "config": { + "autoloader-suffix": "PluginDatainjection", "optimize-autoloader": true, "platform": { "php": "8.2.99" @@ -12,7 +13,9 @@ }, "autoload-dev": { "psr-4": { - "Glpi\\Tools\\": "../../tools/src/" + "Glpi\\Tools\\": "../../tools/src/", + "GlpiPlugin\\Datainjection\\Tests\\": "tests/", + "GlpiPlugin\\Datainjection\\Tests\\Unit\\": "tests/unit/" } } } diff --git a/front/clientinjection.form.php b/front/clientinjection.form.php index 4610c796..32161117 100644 --- a/front/clientinjection.form.php +++ b/front/clientinjection.form.php @@ -28,7 +28,7 @@ * ------------------------------------------------------------------------- */ -Session::checkRight("plugin_datainjection_use", READ); +Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ); Html::header( __('Data injection', 'datainjection'), @@ -61,6 +61,8 @@ && !$_FILES['filename']['error'] && $_FILES['filename']['size'] ) { + $uploaded_filename = $_FILES['filename']['name']; + //Read file using automatic encoding detection, and do not delete file once readed $options = [ 'file_encoding' => $_POST['file_encoding'], @@ -72,7 +74,7 @@ if ($response) { //File uploaded successfully and matches the given model : switch to the import tab - $_SESSION['datainjection']['file_name'] = $_FILES['filename']['name']; + $_SESSION['datainjection']['file_name'] = $uploaded_filename; $_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS; //Store model in session for injection $_SESSION['datainjection']['currentmodel'] = serialize($model); diff --git a/front/mapping.form.php b/front/mapping.form.php index d6ffb671..5149cc7e 100644 --- a/front/mapping.form.php +++ b/front/mapping.form.php @@ -28,7 +28,7 @@ * ------------------------------------------------------------------------- */ -Session::checkRight('plugin_datainjection_model', UPDATE); +Session::checkRight(PluginDatainjectionModel::$rightname, UPDATE); /* Update mappings */ if (isset($_POST["update"])) { diff --git a/front/model.form.php b/front/model.form.php index 95f32e3c..266a47b3 100644 --- a/front/model.form.php +++ b/front/model.form.php @@ -30,13 +30,9 @@ Session::checkLoginUser(); -if (!isset($_GET["id"])) { - $_GET["id"] = ""; -} +$_GET["id"] ??= ""; -if (!isset($_GET["withtemplate"])) { - $_GET["withtemplate"] = ""; -} +$_GET["withtemplate"] ??= ""; $model = new PluginDatainjectionModel(); $model->checkGlobal(READ); diff --git a/hook.php b/hook.php index 05a0a021..8bebc93e 100644 --- a/hook.php +++ b/hook.php @@ -236,7 +236,7 @@ function plugin_datainjection_migration_2158_2159(Migration $migration) // Fix remaining legacy data (old schema stored private models with `entities_id = -1`). // Must run *before* the changeField() below: the column is converted to // `unsigned`, which would mangle the `-1` values before this cleanup could match them. - if (countElementsInTable("glpi_plugin_datainjection_models", ['entities_id' => -1])) { + if (countElementsInTable("glpi_plugin_datainjection_models", ['entities_id' => -1]) !== 0) { $migration->addPreQuery( "UPDATE `glpi_plugin_datainjection_models` SET `is_private` = '1', `entities_id` = '0', `is_recursive` = '1' @@ -1916,7 +1916,7 @@ function plugin_datainjection_update220_230() /** @var DBmysql $DB */ global $DB; - if (countElementsInTable("glpi_plugin_datainjection_models", ['entities_id' => -1])) { + if (countElementsInTable("glpi_plugin_datainjection_models", ['entities_id' => -1]) !== 0) { $query = "UPDATE `glpi_plugin_datainjection_models` SET `is_private` = '1', `entities_id` = '0', @@ -1993,10 +1993,11 @@ function plugin_datainjection_addDefaultWhere($itemtype) } return "`glpi_plugin_datainjection_models`.`id` IN ('" . implode("','", $tab) . "')"; - } else { - return "1 = 0"; //no model available -> force WHERE clause to get no result } - // no break + + return "1 = 0"; + //no model available -> force WHERE clause to get no result + default: break; } diff --git a/inc/backendcsv.class.php b/inc/backendcsv.class.php index 2c579b63..2ffd2cac 100644 --- a/inc/backendcsv.class.php +++ b/inc/backendcsv.class.php @@ -226,15 +226,14 @@ public function getNextLine() return false; } - $line = []; if ( (count($data) > 1) || ($data[0] != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) ) { - $line = self::parseLine($this->file_handler, $data, $this->encoding); + return self::parseLine($this->file_handler, $data, $this->encoding); } - return $line; + return []; } diff --git a/inc/clientinjection.class.php b/inc/clientinjection.class.php index a8a12128..480cf6a6 100644 --- a/inc/clientinjection.class.php +++ b/inc/clientinjection.class.php @@ -47,7 +47,7 @@ class PluginDatainjectionClientInjection { - public static $rightname = "plugin_datainjection_use"; + public static string $rightname = "plugin_datainjection_use"; public const STEP_UPLOAD = 0; @@ -90,7 +90,7 @@ public function showForm($ID, $options = []) TemplateRenderer::getInstance()->display('@datainjection/clientinjection.html.twig', [ 'form_action' => Toolbox::getItemTypeFormURL(self::class), 'models' => PluginDatainjectionModel::getModels(Session::getLoginUserID(), 'name', $_SESSION['glpiactive_entity'], false), - 'can_create_model' => Session::haveRight('plugin_datainjection_model', CREATE), + 'can_create_model' => Session::haveRight(PluginDatainjectionModel::$rightname, CREATE), 'model_type_name' => PluginDatainjectionModel::getTypeName(), 'models_id' => PluginDatainjectionSession::getParam('models_id'), 'step' => PluginDatainjectionSession::getParam('step'), diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index 2154699a..97d6ceb9 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -639,7 +639,7 @@ private function getFieldValue( 'entities_id' => $this->entity, ]; - if ($item->getType() == 'Entity') { + if ($item::class == 'Entity') { // Blocks entity creation. The findID method only searches for direct sub-entities of the root, not deeper levels. $crit = 'name'; if (strpos($input['completename'], '>')) { @@ -658,7 +658,7 @@ private function getFieldValue( } $sons = getSonsOf('glpi_entities', $input['entities_id']); - if ($result === false && !empty($sons)) { + if ($result === false && $sons !== []) { foreach ($sons as $son_id) { $result = $entity->getFromDBByCrit( [ @@ -1506,11 +1506,10 @@ private function checkType($injectionClass, $option, $field_name, $data, $mandat if ($data == 0 || $data == 1) { return self::SUCCESS; - } else { - return self::TYPE_MISMATCH; } - // no break + return self::TYPE_MISMATCH; + default: //Not a standard check ? Try checks specific to the injection class //Will return SUCCESS if it's not a specific check @@ -1606,9 +1605,9 @@ private function lastCheckBeforeProcess($injectionClass) //Specific reformat action is itemtype needs it if (method_exists($injectionClass, 'lastCheck')) { return $injectionClass->lastCheck($this->values); - } else { - return true; } + + return true; } //--------------------------------------------------// @@ -1868,7 +1867,7 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr && !empty($option) && isset($option['table']) && $option['table'] === getTableForItemType(Group::class) - && Toolbox::hasTrait($item->getType(), AssignableItem::class) + && Toolbox::hasTrait($item::class, AssignableItem::class) ) { $normalized_value = $toinject[$key]; $group_type = null; @@ -1975,9 +1974,9 @@ protected function processDictionnariesIfNeeded() if (method_exists($this->injectionClass, 'processDictionnariesIfNeeded')) { //Invoke it return $this->injectionClass->processDictionnariesIfNeeded($this->values); - } else { - return true; } + + return true; } /** diff --git a/inc/devicecaseinjection.class.php b/inc/devicecaseinjection.class.php index 35ba7328..8814ad56 100644 --- a/inc/devicecaseinjection.class.php +++ b/inc/devicecaseinjection.class.php @@ -98,14 +98,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/devicecontrolinjection.class.php b/inc/devicecontrolinjection.class.php index a6992267..503d6bd5 100644 --- a/inc/devicecontrolinjection.class.php +++ b/inc/devicecontrolinjection.class.php @@ -99,14 +99,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/devicedriveinjection.class.php b/inc/devicedriveinjection.class.php index 83789b35..668e7af0 100644 --- a/inc/devicedriveinjection.class.php +++ b/inc/devicedriveinjection.class.php @@ -99,14 +99,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/deviceharddriveinjection.class.php b/inc/deviceharddriveinjection.class.php index 74d6ba83..240b3df5 100644 --- a/inc/deviceharddriveinjection.class.php +++ b/inc/deviceharddriveinjection.class.php @@ -100,14 +100,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/devicememoryinjection.class.php b/inc/devicememoryinjection.class.php index 0d2cdfa8..d6ab5daa 100644 --- a/inc/devicememoryinjection.class.php +++ b/inc/devicememoryinjection.class.php @@ -105,7 +105,7 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) 'items_id' => $values['Computer']['id'], ]; - if (!countElementsInTable($item->getTable(), $where)) { + if (countElementsInTable($item->getTable(), $where) === 0) { if ( isset($values[get_parent_class($this)]['size_default']) && ($values[get_parent_class($this)]['size_default'] > 0) diff --git a/inc/devicemotherboardinjection.class.php b/inc/devicemotherboardinjection.class.php index a5276073..d508ffb0 100644 --- a/inc/devicemotherboardinjection.class.php +++ b/inc/devicemotherboardinjection.class.php @@ -100,14 +100,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/devicenetworkcardinjection.class.php b/inc/devicenetworkcardinjection.class.php index 1b1f089b..5aa5c71a 100644 --- a/inc/devicenetworkcardinjection.class.php +++ b/inc/devicenetworkcardinjection.class.php @@ -98,14 +98,14 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if ( - !countElementsInTable( + countElementsInTable( $item->getTable(), [ $foreign => $values[get_parent_class($this)]['id'], 'itemtype' => 'Computer', 'items_id' => $values['Computer']['id'], ], - ) + ) === 0 ) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; diff --git a/inc/deviceprocessorinjection.class.php b/inc/deviceprocessorinjection.class.php index 75f0fdb9..9a65ac45 100644 --- a/inc/deviceprocessorinjection.class.php +++ b/inc/deviceprocessorinjection.class.php @@ -105,7 +105,7 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) 'items_id' => $values['Computer']['id'], ]; - if (!countElementsInTable($item->getTable(), $where)) { + if (countElementsInTable($item->getTable(), $where) === 0) { //try first frequency, then default_frequency if ( isset($values[get_parent_class($this)]['frequency']) diff --git a/inc/engine.class.php b/inc/engine.class.php index 810b93f1..fbd8e4c8 100644 --- a/inc/engine.class.php +++ b/inc/engine.class.php @@ -161,10 +161,7 @@ public function injectLine($line, $index) */ public function addRequiredFields($itemtype, &$fields_toinject = []): void { - //Add entity to the primary type - if (!isset($fields_toinject[$itemtype]['entities_id'])) { - $fields_toinject[$itemtype]['entities_id'] = $this->entity; - } + $fields_toinject[$itemtype]['entities_id'] ??= $this->entity; } diff --git a/inc/entityinjection.class.php b/inc/entityinjection.class.php index 34421311..d295f4f0 100644 --- a/inc/entityinjection.class.php +++ b/inc/entityinjection.class.php @@ -139,9 +139,9 @@ public function customimport($input = [], $add = true, $rights = []) if (count($results)) { $ent = array_pop($results); return $this->updateExistingEntity($ent['id'], $input); - } else { - return $this->importEntity($input); } + + return $this->importEntity($input); } public function importEntity($input) @@ -190,7 +190,7 @@ public function importEntity($input) ); // Entity doesn't exists => create it - if (empty($results)) { + if ($results === []) { $parent = $em->import($tmp); } else { // Entity already exists, use the ID as parent @@ -233,7 +233,7 @@ public function customDataAlreadyInDB($injectionClass, $values, $options) ['completename' => $values['completename']], ); - if (empty($results)) { + if ($results === []) { return false; } diff --git a/inc/info.class.php b/inc/info.class.php index 82758ef6..4527d57e 100644 --- a/inc/info.class.php +++ b/inc/info.class.php @@ -35,7 +35,7 @@ class PluginDatainjectionInfo extends CommonDBTM { - public static $rightname = "plugin_datainjection_model"; + public static string $rightname = "plugin_datainjection_model"; public function getEmpty() { @@ -156,7 +156,7 @@ public static function showFormInfos(PluginDatainjectionModel $model) $sel = "checked"; } - echo "", $sel); + echo "", $sel); echo ""; } @@ -476,13 +476,16 @@ public static function dropdownTemplates($name, $table) $values = [0 => Dropdown::EMPTY_VALUE]; - $sql = "SELECT `id`, `template_name` - FROM `" . $table . "` - WHERE `is_template`=1 " . - getEntitiesRestrictRequest(' AND ', $table) . - "ORDER BY `template_name`"; + $result = $DB->request([ + 'SELECT' => ['id', 'template_name'], + 'FROM' => $table, + 'WHERE' => [ + 'is_template' => 1, + ] + getEntitiesRestrictCriteria($table), + 'ORDER' => 'template_name', + ]); - foreach ($DB->doQuery($sql) as $data) { + foreach ($result as $data) { $values[$data['id']] = $data['template_name']; } diff --git a/inc/injectiontype.class.php b/inc/injectiontype.class.php index ee8eca2a..8da2105e 100644 --- a/inc/injectiontype.class.php +++ b/inc/injectiontype.class.php @@ -350,7 +350,7 @@ public static function showMandatoryCheckbox($options = []) && !in_array($options['value'], self::NON_MANDATORY_FIELDS) ) ) { - echo "", $checked); + echo "", $checked); } } diff --git a/inc/item_operatingsysteminjection.class.php b/inc/item_operatingsysteminjection.class.php index 34c8078b..48afa520 100644 --- a/inc/item_operatingsysteminjection.class.php +++ b/inc/item_operatingsysteminjection.class.php @@ -122,9 +122,9 @@ public function customDataAlreadyInDB($injectionClass, $values, $options) if ($matching_os->count() > 0) { $item_operatingsystem->getFromResultSet($matching_os->current()); return $item_operatingsystem->fields['id']; - } else { - return false; } + + return false; } diff --git a/inc/knowbaseitemcategoryinjection.class.php b/inc/knowbaseitemcategoryinjection.class.php deleted file mode 100644 index bee2b550..00000000 --- a/inc/knowbaseitemcategoryinjection.class.php +++ /dev/null @@ -1,91 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @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 PluginDatainjectionKnowbaseItemCategoryInjection extends KnowbaseItemCategory 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 true; // By default, all fields can be null - } - - - /** - * @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)); - $notimportable = [14]; - - $options['ignore_fields'] = array_merge($blacklist, $notimportable); - $options['displaytype'] = ["multiline_text" => [16]]; - - return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); - } - - - /** - * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject() - **/ - public function addOrUpdateObject($values = [], $options = []) - { - - $lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options); - $lib->processAddOrUpdate(); - return $lib->getInjectionResults(); - } -} diff --git a/inc/mapping.class.php b/inc/mapping.class.php index d9a3b495..20dfa36e 100644 --- a/inc/mapping.class.php +++ b/inc/mapping.class.php @@ -35,7 +35,7 @@ class PluginDatainjectionMapping extends CommonDBTM { - public static $rightname = "plugin_datainjection_model"; + public static string $rightname = "plugin_datainjection_model"; /** * @param string $field diff --git a/inc/menu.class.php b/inc/menu.class.php index 6d304cee..4c9d7146 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -30,7 +30,7 @@ class PluginDatainjectionMenu extends CommonGLPI { - public static $rightname = 'plugin_datainjection_use'; + public static string $rightname = 'plugin_datainjection_use'; public static function getMenuName() { @@ -73,14 +73,14 @@ public static function getMenuContent() $model_name = PluginDatainjectionModel::getTypeName(Session::getPluralNumber()); $image_model = "", $model_name, $model_name); - if (Session::haveRight('plugin_datainjection_model', READ)) { + if (Session::haveRight(PluginDatainjectionModel::$rightname, READ)) { $menu['options']['model']['title'] = $model_name; $menu['options']['model']['page'] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false); $menu['options']['model']['links']['search'] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false); $menu['options']['client']['links'][$image_model] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false); } - if (Session::haveRight('plugin_datainjection_model', UPDATE) || Session::haveRight('plugin_datainjection_model', CREATE)) { + if (Session::haveRight(PluginDatainjectionModel::$rightname, UPDATE) || Session::haveRight(PluginDatainjectionModel::$rightname, CREATE)) { $menu['options']['model']['links']['add'] = Toolbox::getItemTypeFormUrl('PluginDatainjectionModel', false); $menu['options']['client']['links'][$image_model] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false); } diff --git a/inc/model.class.php b/inc/model.class.php index 6a72d63a..c5bf44aa 100644 --- a/inc/model.class.php +++ b/inc/model.class.php @@ -64,7 +64,7 @@ class PluginDatainjectionModel extends CommonDBTM { - public static $rightname = "plugin_datainjection_model"; + public static string $rightname = "plugin_datainjection_model"; //Store mappings informations private $mappings; @@ -76,7 +76,7 @@ class PluginDatainjectionModel extends CommonDBTM protected $infos; //Do history (CommonDBTM) - public $dohistory = true; + public bool $dohistory = true; //Store specific backend parameters public $specific_model; @@ -459,7 +459,7 @@ public function rawSearchOptions() 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', - 'itemlink_type' => $this->getType(), + 'itemlink_type' => static::class, 'autocomplete' => true, ], [ 'id' => 2, @@ -740,20 +740,20 @@ public function defineTabs($options = []) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - $canedit = Session::haveRight('plugin_datainjection_model', UPDATE); + $canedit = Session::haveRight(self::$rightname, UPDATE); if (!$withtemplate && $item instanceof self) { - $tabs[1] = self::createTabEntry(__('Model'), 0, $item::getType(), self::getIcon()); + $tabs[1] = self::createTabEntry(__('Model'), 0, $item::class, self::getIcon()); if (!$this->isNewID($item->fields['id'])) { if ($canedit) { - $tabs[3] = self::createTabEntry(__('File to inject', 'datainjection'), 0, $item::getType(), 'ti ti-file-download'); + $tabs[3] = self::createTabEntry(__('File to inject', 'datainjection'), 0, $item::class, 'ti ti-file-download'); } - $tabs[4] = self::createTabEntry(__('Mappings', 'datainjection'), 0, $item::getType(), 'ti ti-columns'); + $tabs[4] = self::createTabEntry(__('Mappings', 'datainjection'), 0, $item::class, 'ti ti-columns'); if ($item->fields['step'] > self::MAPPING_STEP) { - $tabs[5] = self::createTabEntry(__('Additional Information', 'datainjection'), 0, $item::getType(), 'ti ti-code-variable-plus'); + $tabs[5] = self::createTabEntry(__('Additional Information', 'datainjection'), 0, $item::class, 'ti ti-code-variable-plus'); if ($canedit && $item->fields['step'] != self::READY_TO_USE_STEP) { - $tabs[6] = self::createTabEntry(__('Validation'), 0, $item::getType(), 'ti ti-checklist'); + $tabs[6] = self::createTabEntry(__('Validation'), 0, $item::class, 'ti ti-checklist'); } } } @@ -986,34 +986,32 @@ public function readUploadedFile($options = []) return ['status' => ERROR, 'message' => $message, ]; - } else { - //Initialise a new backend - $backend = PluginDatainjectionBackend::getInstance($this->fields['filetype']); - //Init backend with needed values - $backend->init($unique_filename, $file_encoding); - $backend->setHeaderPresent($this->specific_model->fields['is_header_present']); - $backend->setDelimiter($this->specific_model->fields['delimiter']); - - if (!$webservice) { - //Read n line from the CSV file if not webservice - $injectionData = $backend->read(20); - } else { - //Read the whole file - $injectionData = $backend->read(-1); - } - - //Read the whole file and store the number of lines found - $backend->storeNumberOfLines(); - $_SESSION['datainjection']['lines'] = serialize($injectionData); - $_SESSION['datainjection']['nblines'] = $backend->getNumberOfLines(); + } - if ($delete_file) { - $backend->deleteFile(); - } + //Initialise a new backend + $backend = PluginDatainjectionBackend::getInstance($this->fields['filetype']); + //Init backend with needed values + $backend->init($unique_filename, $file_encoding); + $backend->setHeaderPresent($this->specific_model->fields['is_header_present']); + $backend->setDelimiter($this->specific_model->fields['delimiter']); + if (!$webservice) { + //Read n line from the CSV file if not webservice + $injectionData = $backend->read(20); + } else { + //Read the whole file + $injectionData = $backend->read(-1); + } - $this->backend = $backend; + //Read the whole file and store the number of lines found + $backend->storeNumberOfLines(); + $_SESSION['datainjection']['lines'] = serialize($injectionData); + $_SESSION['datainjection']['nblines'] = $backend->getNumberOfLines(); + if ($delete_file) { + $backend->deleteFile(); } + $this->backend = $backend; + $this->injectionData = $injectionData; return true; } @@ -1457,9 +1455,7 @@ public static function showLogResults($models_id) // Prépare le résumé foreach ($logresults as $results) { foreach ($results as $result) { - if (!isset($resume[$result['status']][$result['type']])) { - $resume[$result['status']][$result['type']] = 0; - } + $resume[$result['status']][$result['type']] ??= 0; $resume[$result['status']][$result['type']]++; $nblines++; diff --git a/inc/modelcsv.class.php b/inc/modelcsv.class.php index 8666a76b..b76498b2 100644 --- a/inc/modelcsv.class.php +++ b/inc/modelcsv.class.php @@ -60,17 +60,16 @@ class PluginDatainjectionModelcsv extends CommonDBChild { - public static $rightname = "plugin_datainjection_model"; + public static string $rightname = "plugin_datainjection_model"; - public $specific_fields; + public array $specific_fields; // From CommonDBChild - public static $itemtype = 'PluginDatainjectionModel'; + public static string $itemtype = 'PluginDatainjectionModel'; - public static $items_id = 'models_id'; - - public $dohistory = true; + public static string $items_id = 'models_id'; + public bool $dohistory = true; public function getEmpty() { diff --git a/inc/profile.class.php b/inc/profile.class.php index bd657c27..ac57751b 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -30,7 +30,7 @@ class PluginDatainjectionProfile extends Profile { - public static $rightname = "profile"; + public static string $rightname = "profile"; public static function getAllRights() { @@ -68,7 +68,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) if ($item instanceof Profile) { if ($item->fields['interface'] == 'central') { - return self::createTabEntry(__('Data injection', 'datainjection'), 0, $item::getType(), 'ti ti-download'); + return self::createTabEntry(__('Data injection', 'datainjection'), 0, $item::class, 'ti ti-download'); } return ''; @@ -105,10 +105,10 @@ public static function addDefaultProfileInfos($profiles_id, $rights) $profileRight = new ProfileRight(); foreach ($rights as $right => $value) { if ( - !countElementsInTable( + countElementsInTable( 'glpi_profilerights', ['profiles_id' => $profiles_id, 'name' => $right], - ) + ) === 0 ) { $myright['profiles_id'] = $profiles_id; $myright['name'] = $right; diff --git a/inc/softwarelicenseinjection.class.php b/inc/softwarelicenseinjection.class.php index ae1791e0..eb425251 100644 --- a/inc/softwarelicenseinjection.class.php +++ b/inc/softwarelicenseinjection.class.php @@ -157,16 +157,17 @@ public function getValueForAdditionalMandatoryFields($fields_toinject = []) return $fields_toinject; } - $where = ['name' => $fields_toinject['SoftwareLicense']['softwares_id']] + getEntitiesRestrictCriteria( - "glpi_softwares", - "entities_id", - $fields_toinject['SoftwareLicense']['entities_id'], - true, - ); $result = $DB->request([ - 'SELECT' => 'id', + 'SELECT' => ['id'], 'FROM' => 'glpi_softwares', - 'WHERE' => $where, + 'WHERE' => [ + 'name' => $fields_toinject['SoftwareLicense']['softwares_id'], + ] + getEntitiesRestrictCriteria( + 'glpi_softwares', + 'entities_id', + $fields_toinject['SoftwareLicense']['entities_id'], + true, + ), ]); if (count($result) > 0) { diff --git a/inc/softwareversioninjection.class.php b/inc/softwareversioninjection.class.php index 202d2029..d6289920 100644 --- a/inc/softwareversioninjection.class.php +++ b/inc/softwareversioninjection.class.php @@ -152,16 +152,17 @@ public function getValueForAdditionalMandatoryFields($fields_toinject = []) return $fields_toinject; } - $where = ['name' => $fields_toinject['SoftwareVersion']['softwares_id']] + getEntitiesRestrictCriteria( - "glpi_softwares", - "entities_id", - $fields_toinject['SoftwareVersion']['entities_id'], - true, - ); $result = $DB->request([ - 'SELECT' => 'id', + 'SELECT' => ['id'], 'FROM' => 'glpi_softwares', - 'WHERE' => $where, + 'WHERE' => [ + 'name' => $fields_toinject['SoftwareVersion']['softwares_id'], + ] + getEntitiesRestrictCriteria( + 'glpi_softwares', + 'entities_id', + $fields_toinject['SoftwareVersion']['entities_id'], + true, + ), ]); if (count($result) > 0) { diff --git a/inc/userinjection.class.php b/inc/userinjection.class.php index 387453ba..aeb793aa 100644 --- a/inc/userinjection.class.php +++ b/inc/userinjection.class.php @@ -185,7 +185,7 @@ public function reformat(&$values) public function processAfterInsertOrUpdate($values, $add = true, $rights = []) { //Manage user emails - if (isset($values['User']['useremails_id']) && $rights['add_dropdown'] && Session::haveRight('user', UPDATE)) { + if (isset($values['User']['useremails_id']) && $rights['add_dropdown'] && Session::haveRight(User::$rightname, UPDATE)) { $emails = preg_split('/[\s,;]+/', $values['User']['useremails_id'], -1, PREG_SPLIT_NO_EMPTY); foreach ($emails as $email) { $email = trim((string) $email); @@ -203,7 +203,7 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) 'is_default' => 0, ]; // If user has no emails, set this one as default - if (!countElementsInTable("glpi_useremails", ['users_id' => $values['User']['id']])) { + if (countElementsInTable("glpi_useremails", ['users_id' => $values['User']['id']]) === 0) { $tmp['is_default'] = 1; } diff --git a/setup.php b/setup.php index 3c20c3e1..29ecbdf4 100644 --- a/setup.php +++ b/setup.php @@ -34,9 +34,9 @@ define('PLUGIN_DATAINJECTION_VERSION', '2.15.11'); // Minimal GLPI version, inclusive -define("PLUGIN_DATAINJECTION_MIN_GLPI", "11.0.5"); +define("PLUGIN_DATAINJECTION_MIN_GLPI", "12.0.0"); // Maximum GLPI version, exclusive -define("PLUGIN_DATAINJECTION_MAX_GLPI", "11.0.99"); +define("PLUGIN_DATAINJECTION_MAX_GLPI", "12.0.99"); if (!defined("PLUGIN_DATAINJECTION_UPLOAD_DIR")) { define("PLUGIN_DATAINJECTION_UPLOAD_DIR", GLPI_PLUGIN_DOC_DIR . "/datainjection/"); @@ -69,7 +69,7 @@ function plugin_init_datainjection() - if (Session::haveRight('plugin_datainjection_use', READ)) { + if (Session::haveRight(PluginDatainjectionClientInjection::$rightname, READ)) { $PLUGIN_HOOKS["menu_toadd"]['datainjection'] = ['tools' => 'PluginDatainjectionMenu']; } @@ -160,7 +160,6 @@ function getTypesToInject(): void 'PluginDatainjectionNetworkport_VlanInjection' => 'datainjection', 'PluginDatainjectionNetworkNameInjection' => 'datainjection', 'PluginDatainjectionNetpointInjection' => 'datainjection', - 'PluginDatainjectionKnowbaseItemCategoryInjection' => 'datainjection', 'PluginDatainjectionKnowbaseItemInjection' => 'datainjection', 'PluginDatainjectionITILFollowupTemplateInjection' => 'datainjection', 'PluginDatainjectionITILCategoryInjection' => 'datainjection', diff --git a/templates/clientinjection.html.twig b/templates/clientinjection.html.twig index 590b9cae..4790fe89 100644 --- a/templates/clientinjection.html.twig +++ b/templates/clientinjection.html.twig @@ -27,12 +27,10 @@ #} {% import 'components/form/fields_macros.html.twig' as fields %} -{% import 'components/alerts_macros.html.twig' as alerts %} {% set rand = random() %}