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 mandatory fields of a block hidden by its display conditions blocking the save of an item
- Fix fields values updates not applying the expected checks in some cases
- Fix `Yes/No` field values returned as strings instead of integers in search results

## [1.24.6] - 2026-10-06

Expand Down
9 changes: 6 additions & 3 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2571,9 +2571,12 @@ public static function getAddSearchOptions($itemtype, $containers_id = false)
&& !in_array($data['type'], ['dropdown', 'glpi_item'], true)
&& !preg_match('/^dropdown-.+$/i', (string) $data['type'])
) {
$default_expression = in_array($data['type'], ['date', 'datetime'], true) && $data['default_value'] === 'now'
? QueryFunction::now()
: new QueryExpression($DB::quoteValue($data['default_value']));
$default_expression = match (true) {
in_array($data['type'], ['date', 'datetime'], true) && $data['default_value'] === 'now' => QueryFunction::now(),
// a quoted default would make COALESCE return a string instead of the INT column type
$data['type'] === 'yesno' => new QueryExpression((string) (int) $data['default_value']),
default => new QueryExpression($DB::quoteValue($data['default_value'])),
};

$opt[$i]['computation'] = QueryFunction::coalesce([
'TABLE.' . $data['field_name'],
Expand Down
52 changes: 52 additions & 0 deletions tests/Units/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,60 @@ public function testSearchoptionsShowsDefaultValueFieldWithoutAnyRow(
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/',
(string) $row['raw']['ITEM_Ticket_' . $so_id],
);
} elseif ($type === 'yesno') {
$this->assertSame((int) $default_value, $row['raw']['ITEM_Ticket_' . $so_id]);
} else {
$this->assertSame($default_value, $row['raw']['ITEM_Ticket_' . $so_id]);
}
}

public function testSearchoptionsKeepsYesnoStoredValueAsInteger(): void
{
$this->login();
$entities_id = $_SESSION['glpiactive_entity'];

$container = $this->createFieldContainer([
'label' => 'Search Yesno Container',
'type' => 'dom',
'itemtypes' => [Ticket::class],
'is_active' => 1,
'entities_id' => $entities_id,
'is_recursive' => 1,
]);

$field = $this->createField([
'label' => 'Search Yesno Field',
'type' => 'yesno',
PluginFieldsContainer::getForeignKeyField() => $container->getID(),
'ranking' => 1,
'is_active' => 1,
'is_readonly' => 0,
'default_value' => '0',
]);

// Ticket created after the field, so its row stores the default value
$ticket = $this->createItem(Ticket::class, [
'name' => 'Search yesno ticket ' . $this->getUniqueString(),
'content' => 'Test',
'entities_id' => $entities_id,
]);
$this->assertSame(0, $this->getDefaultValueStored($ticket, $container, $field->fields['name']));

$so_id = PluginFieldsField::SEARCH_OPTION_STARTING_INDEX + $field->getID();
$data = Search::getDatas(
Ticket::class,
[
'is_deleted' => 0,
'start' => 0,
'criteria' => [
['field' => 'view', 'searchtype' => 'contains', 'value' => $ticket->fields['name']],
],
],
[$so_id],
);

$this->assertSame(1, $data['data']['totalcount']);
$row = current($data['data']['rows']);
$this->assertSame(0, $row['raw']['ITEM_Ticket_' . $so_id]);
}
}
Loading