From 6d872a6cc22b3b319885b9ffd6f33745ecbfe251 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Tue, 30 Dec 2025 15:10:35 +0100 Subject: [PATCH 1/2] Feat(Fields): add compatibility with GLPI --- CHANGELOG.md | 7 +++++++ hook.php | 2 +- inc/container.class.php | 6 +++++- inc/toolbox.class.php | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e8930c7..ee6bf7bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +### Added + +- Add compatibility with GLPI `CustomAsset` + + ## [1.23.2] - 2025-12-22 - Fix prevent failure when attempting to delete an actor diff --git a/hook.php b/hook.php index 0eabc024..3ccd34ea 100644 --- a/hook.php +++ b/hook.php @@ -353,7 +353,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) /** @var DBmysql $DB */ global $DB; - $searchopt = &Search::getOptions($itemtype); + $searchopt = Search::getOptions($itemtype); $table = $searchopt[$ID]['table']; $field = $searchopt[$ID]['field']; $pfields_type = $searchopt[$ID]['pfields_type'] ?? ''; diff --git a/inc/container.class.php b/inc/container.class.php index 16d249c5..f31e4241 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -2013,7 +2013,11 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) // > To search for \, specify it as \\\\; this is because the backslashes are stripped // > once by the parser and again when the pattern match is made, // > leaving a single backslash to be matched against. - $search_string = str_replace('\\', '\\\\', $search_string); + + // But do not escape backslashes for CustomAsset, as they are alrady escaped + if (!str_contains($search_string, 'CustomAsset')) { + $search_string = str_replace('\\', '\\\\', $search_string); + } $request = [ 'SELECT' => [ diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 6b95ceb9..04efa1b6 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -232,6 +232,12 @@ public static function getGlpiItemtypes(): array Socket::class, ]; + foreach ($CFG_GLPI['asset_types'] as $asset_type) { + if (str_starts_with($asset_type, "Glpi\CustomAsset")) { + $assets_itemtypes[] = $asset_type; + } + } + $assistance_itemtypes = [ Ticket::class, Problem::class, From e0df0c838dcfc57bf7cd19c3413212044f9cedf5 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Tue, 30 Dec 2025 15:59:28 +0100 Subject: [PATCH 2/2] fix cs --- inc/toolbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 04efa1b6..a8e114a7 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -233,7 +233,7 @@ public static function getGlpiItemtypes(): array ]; foreach ($CFG_GLPI['asset_types'] as $asset_type) { - if (str_starts_with($asset_type, "Glpi\CustomAsset")) { + if (str_starts_with((string) $asset_type, "Glpi\CustomAsset")) { $assets_itemtypes[] = $asset_type; } }