From ff3690c52f82d26bacef5fa3b8be6e2f4890c9fe Mon Sep 17 00:00:00 2001 From: Herafia Date: Mon, 16 Nov 2026 14:59:49 +0100 Subject: [PATCH 1/2] fix clone mandatory glpi item field # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 2 ++ inc/container.class.php | 5 +++ tests/Units/ContainerItemUpdateTest.php | 48 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a57ea7bf..fba5478c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix form submission error when a multiple dropdown field question is left empty - Fix search criterion value on multiple dropdown fields being reset after a search, which emptied the criterion when sorting or paging results +- Fix fields values not injectable with DataInjection, and models using them being no longer accessible +- Fix item clone failing when a mandatory GLPI item field is in an "Insert in form" block ## [1.24.7] - 2026-10-28 diff --git a/inc/container.class.php b/inc/container.class.php index a5a78af4..681e7fc7 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -2091,6 +2091,11 @@ public static function validateValues($data, $itemtype, $massiveaction, $is_crea $itemtype_key = sprintf('itemtype_%s', $name); $items_id_key = sprintf('items_id_%s', $name); + // not submitted during a massive action (ex: clone) as for the other field types + if ($massiveaction && !isset($data[$items_id_key])) { + continue; + } + $is_unchanged_reference = isset($stored_values[$itemtype_key], $stored_values[$items_id_key], $data[$itemtype_key], $data[$items_id_key]) && $stored_values[$itemtype_key] === $data[$itemtype_key] && (int) $stored_values[$items_id_key] === (int) $data[$items_id_key]; diff --git a/tests/Units/ContainerItemUpdateTest.php b/tests/Units/ContainerItemUpdateTest.php index 4888a513..75f4ff5d 100644 --- a/tests/Units/ContainerItemUpdateTest.php +++ b/tests/Units/ContainerItemUpdateTest.php @@ -41,6 +41,7 @@ use Entity; use Notification; use Problem; +use Supplier; require_once __DIR__ . '/../FieldTestCase.php'; @@ -1117,4 +1118,51 @@ public function testNotBlockedWhenMandatoryDomContainerIsHidden(): void ERROR, ); } + + public function testCloneThroughMassiveActionIsNotBlockedByMandatoryGlpiItemField(): void + { + $this->login(); + + $container = $this->createFieldContainer([ + 'label' => 'Mandatory GLPI item Clone Container', + 'type' => 'dom', + 'itemtypes' => [Computer::class], + 'is_active' => 1, + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $field = $this->createField([ + 'label' => 'Mandatory GLPI item', + 'type' => 'glpi_item', + PluginFieldsContainer::getForeignKeyField() => $container->getID(), + 'ranking' => 1, + 'is_active' => 1, + 'is_readonly' => 0, + 'mandatory' => 1, + 'allowed_values' => [Supplier::class], + ]); + $itemtype_key = 'itemtype_' . $field->fields['name']; + $items_id_key = 'items_id_' . $field->fields['name']; + + $supplier = $this->createItem(Supplier::class, [ + 'name' => 'Supplier for clone', + 'entities_id' => 0, + ]); + $computer = $this->createItem(Computer::class, [ + 'name' => 'Computer with mandatory GLPI item', + 'entities_id' => 0, + $itemtype_key => Supplier::class, + $items_id_key => $supplier->getID(), + ], [$itemtype_key, $items_id_key]); + + // The "Clone" massive action, also used from the item form, does not submit the plugin fields + $_REQUEST['massiveaction'] = 1; + try { + $clone_id = $computer->clone(); + } finally { + unset($_REQUEST['massiveaction']); + } + + $this->assertGreaterThan(0, $clone_id, 'Clone must not be blocked by a mandatory GLPI item field.'); + } } From 1cedc5a919d15726eeceb656a1529c3aad31d972 Mon Sep 17 00:00:00 2001 From: Herafia Date: Mon, 16 Nov 2026 15:08:30 +0100 Subject: [PATCH 2/2] rebase --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fba5478c..0c6c9009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix form submission error when a multiple dropdown field question is left empty - Fix search criterion value on multiple dropdown fields being reset after a search, which emptied the criterion when sorting or paging results -- Fix fields values not injectable with DataInjection, and models using them being no longer accessible - Fix item clone failing when a mandatory GLPI item field is in an "Insert in form" block ## [1.24.7] - 2026-10-28