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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fix crash when injection model has no mandatory fields defined
- Fix models created on parent entities can't be used on child entites
- Fix association of imported data with non-existing groups when the group column is empty in the import file

## [2.15.4] - 2026-03-16

Expand Down
11 changes: 9 additions & 2 deletions inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* -------------------------------------------------------------------------
*/
use Glpi\Exception\Http\HttpException;
use Glpi\Features\AssignableItem;

use function Safe\preg_match;
use function Safe\preg_replace;
Expand Down Expand Up @@ -963,8 +964,14 @@ private function setValueForItemtype($itemtype, $field, $value, $fromdb = false)
];
if (empty($value) && $value !== 0 && $value !== '0') {
if (isForeignKeyField($field) || (str_contains($field, 'is_')) || (method_exists($injectionClass, 'isNullable') && !$injectionClass->isNullable($field))) {
// If the field is an id, we set it to 0
$this->values[$itemtype][$field] = self::DROPDOWN_EMPTY_VALUE;
//If the field concernes groupds, unseting it instead of setting it to 0 in order to avoid associating the item to a non existing group (id 0)
$group_fields = ['groups_id_tech', 'groups_id', 'groups_id_normal'];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where come from this -> groups_id_normal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its one of the keys used by the plugin to map the import file column to a group field (see line 1700).

if (in_array($field, $group_fields) && Toolbox::hasTrait($itemtype, AssignableItem::class)) {
unset($this->values[$itemtype][$field]);
} else {
// If the field is an id, we set it to 0
$this->values[$itemtype][$field] = self::DROPDOWN_EMPTY_VALUE;
}
} else {
// Else we set it to NULL
$this->values[$itemtype][$field] = self::EMPTY_VALUE;
Expand Down