Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fix SQL warning when no user session is active during plugin init
- Fix error when submitting a form with an hidden question of type `Field`
- Fixed a bug where a field was deleted when at least one question in a form was linked to another field

Expand Down
10 changes: 10 additions & 0 deletions inc/questiontype.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ private function getAvailableBlocks(): array
$available_blocks = [];

$entity_restrict = isCommandLine() ? [] : getEntitiesRestrictCriteria(PluginFieldsContainer::getTable(), '', '', true);

// If entity restriction contains an empty string value, it means no valid session
// is active. Running the query would produce a MySQL
// warning (1292: Truncated incorrect DECIMAL value)
foreach ($entity_restrict as $criterion) {
if (is_array($criterion) && in_array('', $criterion, true)) {
return $available_blocks;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this:

Suggested change
$entity_restrict = isCommandLine() ? [] : getEntitiesRestrictCriteria(PluginFieldsContainer::getTable(), '', '', true);
// If entity restriction contains an empty string value, it means no valid session
// is active. Running the query would produce a MySQL
// warning (1292: Truncated incorrect DECIMAL value)
foreach ($entity_restrict as $criterion) {
if (is_array($criterion) && in_array('', $criterion, true)) {
return $available_blocks;
}
}
$activeentities = getEntitiesRestrictCriteria(PluginFieldsContainer::getTable(), '', '', true);
if ($activeentities === []) {
return [];
}
$entity_restrict = isCommandLine() ? [] : $activeentities;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEntitiesRestrictCriteria returns an array of criteria. The problem here isn't that getEntitiesRestrictCriteria returns an empty array; rather, it returns the criterion glpi_plugin_fields_containers.entities_id = "", so the suggestion won't fix the problem.

Copy link
Copy Markdown
Contributor

@Rom1-B Rom1-B Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, but ultimately I think the problem lies in the getEntitiesRestrictCriteria() function, which returns an invalid value. Instead of returning ...entities_id = '' (which can never work), it should return [new QueryExpression(‘false’)];
For your information, it also checks isCommandLine(), so the one here will likely be redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the root cause is actually in the GLPI core — DbUtils::getEntitiesRestrictCriteria() in DbUtils.php.

When called with no active session, no CLI context, and no cron context, the function falls through all conditions without an else branch, leaving $value as an empty string ''. This produces an invalid SQL criterion entities_id = '' on an integer column, which triggers MySQL warning.

I've updated this with a cleaner guard:

if (!Session::getLoginUserID() && !isCommandLine()) {
    return $available_blocks;
}

This is semantically explicit (no session = no available blocks), consistent with the existing guard already in place in setup.php l.138 — it doesn't rely on inspecting the internal structure of the criteria returned by core.

The real fix should live in the core: adding an else { return [new QueryExpression('false')]; } branch to getEntitiesRestrictCriteria() so all callers are protected. I'll open a separate PR on the GLPI core for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the fix for the core : glpi-project/glpi#23934

$result = $field_container->find([
'is_active' => 1,
'type' => 'dom',
Expand Down