From d8ef335648e3567475ba5d45b38a83ed4975dfc5 Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 6 Jul 2026 11:36:59 +0200
Subject: [PATCH 1/6] Fix(Migration): prevent container name corruption on
partial update
---
CHANGELOG.md | 1 +
inc/container.class.php | 17 +++++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99ef6902..102600be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fix search crash when two containers share a dropdown field with the same name.
+- Prevent table and file regeneration when label and/or name is updated.
## [1.24.2] - 2026-06-30
diff --git a/inc/container.class.php b/inc/container.class.php
index 6f38c4dd..513bdd56 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -648,7 +648,10 @@ public function defineTabs($options = [])
public function prepareInputForUpdate($input)
{
- return PluginFieldsToolbox::prepareLabel($input);
+ unset($input['label']);
+ unset($input['name']);
+
+ return $input;
}
public function prepareInputForAdd($input)
@@ -970,11 +973,17 @@ public function showForm($ID, $options = [])
echo '
';
echo "| " . __('Label') . ' : | ';
echo "";
+ $options = [
+ 'value' => $this->fields['label'],
+ ];
+
+ if (!$this->isNewID($ID)) {
+ $options['readonly'] = true;
+ }
+
echo Html::input(
'label',
- [
- 'value' => $this->fields['label'],
- ],
+ $options,
);
echo ' | ';
echo " | ";
From d24ff41c8d4fe9e4778c61a3eb7c8d7556d5ddfc Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:05:17 +0200
Subject: [PATCH 2/6] add flag
---
inc/container.class.php | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/inc/container.class.php b/inc/container.class.php
index 513bdd56..da4dbcc7 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -648,8 +648,10 @@ public function defineTabs($options = [])
public function prepareInputForUpdate($input)
{
- unset($input['label']);
- unset($input['name']);
+ if (isAPI() || isset($input['form_submission']) ) {
+ unset($input['label']);
+ unset($input['name']);
+ }
return $input;
}
@@ -973,17 +975,24 @@ public function showForm($ID, $options = [])
echo '
';
echo "| " . __('Label') . ' : | ';
echo "";
- $options = [
+ $label_options = [
'value' => $this->fields['label'],
];
if (!$this->isNewID($ID)) {
- $options['readonly'] = true;
+ $label_options['readonly'] = true;
}
echo Html::input(
'label',
- $options,
+ $label_options,
+ );
+
+ echo Html::hidden(
+ 'form_submission',
+ [
+ 'value' => true,
+ ],
);
echo ' | ';
echo " | ";
From 3e072d13242a53c5fcac5a3d748686e7b186a4fa Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:11:55 +0200
Subject: [PATCH 3/6] add unit test
---
tests/Units/ContainerTest.php | 53 +++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/tests/Units/ContainerTest.php b/tests/Units/ContainerTest.php
index a7fa7098..dcd33683 100644
--- a/tests/Units/ContainerTest.php
+++ b/tests/Units/ContainerTest.php
@@ -36,6 +36,7 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PluginFieldsContainer;
+use Ticket;
require_once __DIR__ . '/../FieldTestCase.php';
@@ -106,4 +107,56 @@ public function testAddWithValidItemtypesSucceeds(): void
$this->assertGreaterThan(0, $container->getID());
}
+
+ public function testPrepareInputForUpdateStripsLabelAndNameOnFormSubmission(): void
+ {
+ $container = new PluginFieldsContainer();
+ $input = [
+ 'label' => 'New Label',
+ 'name' => 'new_name',
+ 'form_submission' => true,
+ 'is_active' => 1,
+ ];
+
+ $result = $container->prepareInputForUpdate($input);
+
+ $this->assertArrayNotHasKey('label', $result);
+ $this->assertArrayNotHasKey('name', $result);
+ $this->assertArrayHasKey('is_active', $result);
+ }
+
+ public function testPrepareInputForUpdatePreservesNameAndLabelForMigration(): void
+ {
+ $container = new PluginFieldsContainer();
+ $input = [
+ 'name' => 'migration_corrected_name',
+ 'label' => 'Some Label',
+ 'itemtypes' => '["Computer"]',
+ ];
+
+ $result = $container->prepareInputForUpdate($input);
+
+ $this->assertSame('migration_corrected_name', $result['name']);
+ $this->assertArrayHasKey('label', $result);
+ }
+
+ public function testUpdateNameViaMigrationPathPersistsInDatabase(): void
+ {
+ $container = $this->createFieldContainer([
+ 'label' => 'MigrationPath ' . $this->getUniqueString(),
+ 'type' => 'tab',
+ 'itemtypes' => [Computer::class],
+ 'is_active' => 1,
+ 'entities_id' => 0,
+ 'is_recursive' => 1,
+ ]);
+
+ $new_name = 'migrated_' . $container->fields['name'];
+ $container->update(['id' => $container->getID(), 'name' => $new_name]);
+
+ $refreshed = new PluginFieldsContainer();
+ $refreshed->getFromDB($container->getID());
+
+ $this->assertSame($new_name, $refreshed->fields['name']);
+ }
}
From 02d93a84bcaafda970f971882921d11808553f8a Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:24:45 +0200
Subject: [PATCH 4/6] fix test
---
tests/Units/ContainerTest.php | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tests/Units/ContainerTest.php b/tests/Units/ContainerTest.php
index dcd33683..8f54db26 100644
--- a/tests/Units/ContainerTest.php
+++ b/tests/Units/ContainerTest.php
@@ -151,12 +151,16 @@ public function testUpdateNameViaMigrationPathPersistsInDatabase(): void
'is_recursive' => 1,
]);
- $new_name = 'migrated_' . $container->fields['name'];
+ $original_name = $container->fields['name'];
+ $new_name = 'mig_' . substr($original_name, 0, 20);
+
$container->update(['id' => $container->getID(), 'name' => $new_name]);
$refreshed = new PluginFieldsContainer();
$refreshed->getFromDB($container->getID());
-
$this->assertSame($new_name, $refreshed->fields['name']);
+
+ // Restore original name so teardown can locate and drop the physical table
+ $container->update(['id' => $container->getID(), 'name' => $original_name]);
}
}
From 7f2e4951a0596a79bc9fbd764415ea8646a2ebf6 Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:30:33 +0200
Subject: [PATCH 5/6] fix
---
tests/Units/ContainerTest.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/Units/ContainerTest.php b/tests/Units/ContainerTest.php
index 8f54db26..3c3465c8 100644
--- a/tests/Units/ContainerTest.php
+++ b/tests/Units/ContainerTest.php
@@ -36,7 +36,6 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PluginFieldsContainer;
-use Ticket;
require_once __DIR__ . '/../FieldTestCase.php';
@@ -152,7 +151,7 @@ public function testUpdateNameViaMigrationPathPersistsInDatabase(): void
]);
$original_name = $container->fields['name'];
- $new_name = 'mig_' . substr($original_name, 0, 20);
+ $new_name = 'mig_' . substr((string) $original_name, 0, 20);
$container->update(['id' => $container->getID(), 'name' => $new_name]);
From 066c94672c2612420ec012f13f6925cb4462d528 Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:36:27 +0200
Subject: [PATCH 6/6] CS Fixer
---
inc/container.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/container.class.php b/inc/container.class.php
index da4dbcc7..0cd19aba 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -648,7 +648,7 @@ public function defineTabs($options = [])
public function prepareInputForUpdate($input)
{
- if (isAPI() || isset($input['form_submission']) ) {
+ if (isAPI() || isset($input['form_submission'])) {
unset($input['label']);
unset($input['name']);
}