Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"php": ">=8.2"
},
"config": {
"autoloader-suffix": "PluginDatainjection",
"optimize-autoloader": true,
"platform": {
"php": "8.2.99"
Expand All @@ -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/"
}
}
}
6 changes: 4 additions & 2 deletions front/clientinjection.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

Session::checkRight("plugin_datainjection_use", READ);
Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);

Html::header(
__('Data injection', 'datainjection'),
Expand Down Expand Up @@ -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'],
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion front/mapping.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

Session::checkRight('plugin_datainjection_model', UPDATE);
Session::checkRight(PluginDatainjectionModel::$rightname, UPDATE);

/* Update mappings */
if (isset($_POST["update"])) {
Expand Down
8 changes: 2 additions & 6 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions inc/backendcsv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}


Expand Down
4 changes: 2 additions & 2 deletions inc/clientinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

class PluginDatainjectionClientInjection
{
public static $rightname = "plugin_datainjection_use";
public static string $rightname = "plugin_datainjection_use";

public const STEP_UPLOAD = 0;

Expand Down Expand Up @@ -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'),
Expand Down
19 changes: 9 additions & 10 deletions inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '>')) {
Expand All @@ -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(
[
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

//--------------------------------------------------//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions inc/devicecaseinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions inc/devicecontrolinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions inc/devicedriveinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions inc/deviceharddriveinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion inc/devicememoryinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions inc/devicemotherboardinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions inc/devicenetworkcardinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion inc/deviceprocessorinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
5 changes: 1 addition & 4 deletions inc/engine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
8 changes: 4 additions & 4 deletions inc/entityinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +233,7 @@ public function customDataAlreadyInDB($injectionClass, $values, $options)
['completename' => $values['completename']],
);

if (empty($results)) {
if ($results === []) {
return false;
}

Expand Down
Loading
Loading