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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix slow page loads when many entities are active: the containers available to the user were computed with one query per container on every request
- Fix item clone failing when a mandatory dropdown field has an empty default value
- Fix search on number fields: `is` / `is not` ignoring values from 1000, `<` / `>` comparing values as text, and `is not` excluding items without value
- Fix `Some mandatory fields are empty` error on a filled dropdown field when its block table contains a leftover column with the same name

## [1.24.7] - 2026-10-28

Expand Down
14 changes: 8 additions & 6 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2133,12 +2133,14 @@ public static function validateValues($data, $itemtype, $massiveaction, $is_crea
continue;
}
}
} elseif (isset($data[$name])) {
$value = $data[$name];
} elseif (isset($data['plugin_fields_' . $name . 'dropdowns_id'])) {
$value = $data['plugin_fields_' . $name . 'dropdowns_id'];
} elseif ($massiveaction) {
continue;
} else {
// Key chosen from the field type: a leftover column named after the field must not hide a dropdown value
$value_key = $field['type'] === 'dropdown' ? sprintf('plugin_fields_%sdropdowns_id', $name) : $name;
if (isset($data[$value_key])) {
$value = $data[$value_key];
} elseif ($massiveaction) {
continue;
}
}

//translate label
Expand Down
57 changes: 57 additions & 0 deletions tests/Units/ContainerItemUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
namespace GlpiPlugin\Field\Tests\Units;

use Auth;
use Change;
use Computer;
use DBmysql;
use Glpi\Tests\DbTestCase;
use Glpi\Tests\GLPITestCase;
use GlpiPlugin\Field\Tests\FieldTestTrait;
Expand Down Expand Up @@ -755,6 +757,61 @@ public function testUpdateIsNotBlockedWhenMandatoryTabFieldIsAlreadyFilled(): vo
$this->assertSame('Renamed after tab field was filled', $problem->fields['name']);
}

/**
* A leftover column named after a dropdown field (ex: field recreated with another type)
* must not hide the stored dropdown value when an update is checked against stored values.
*/
public function testUpdateIsNotBlockedByLeftoverColumnNamedAfterMandatoryDropdownField(): void
{
/** @var DBmysql $DB */
global $DB;

$this->login();

$container = $this->createFieldContainer([
'label' => 'Dropdown Leftover Column Container',
'type' => 'dom',
'itemtypes' => [Change::class],
'is_active' => 1,
'entities_id' => 0,
'is_recursive' => 1,
]);
$field = $this->createField([
'label' => 'Environment',
'type' => 'dropdown',
PluginFieldsContainer::getForeignKeyField() => $container->getID(),
'ranking' => 1,
'is_active' => 1,
'is_readonly' => 0,
'mandatory' => 1,
]);
$field_name = $field->fields['name'];
$dropdown_key = sprintf('plugin_fields_%sdropdowns_id', $field_name);
$value = $this->createItem(PluginFieldsDropdown::getClassname($field_name), ['name' => 'Production']);

$change = $this->createItem(Change::class, [
'name' => 'Change with a mandatory dropdown field',
'content' => 'Test',
'entities_id' => 0,
'c_id' => $container->getID(),
$dropdown_key => $value->getID(),
], ['c_id', $dropdown_key]);

$table = getTableForItemType(PluginFieldsContainer::getClassname(Change::class, $container->fields['name']));
$DB->doQuery(sprintf('ALTER TABLE %s ADD %s INT NOT NULL DEFAULT 0', $DB->quoteName($table), $DB->quoteName($field_name)));

// Update without submitted plugin values (ex: closing on solution approval)
$updated = $change->update([
'id' => $change->getID(),
'name' => 'Renamed with the leftover column',
]);

$this->assertTrue($updated);
$this->assertEmpty($_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR] ?? []);
$change->getFromDB($change->getID());
$this->assertSame('Renamed with the leftover column', $change->fields['name']);
}

/**
* Update a ticket with explicit c_id through an API-like context.
*/
Expand Down