Skip to content

Commit 7105a1c

Browse files
committed
Fix(SQL): prevent SQL error when column not exist (Item_DeviceSimcard)
1 parent 45ff257 commit 7105a1c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Fixed
1111

1212
- Fix tag search
13+
- Prevent SQL error when column `name` not exist from `Item_Device`
1314

1415
## [2.14.3] - 2025-12-22
1516

inc/tagitem.class.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ public static function showForTag(PluginTagTag $tag)
265265
$item_id = $result2[$i]['items_id'];
266266

267267
if ($item->canView()) {
268-
$column = (strtolower(substr((string) $itemtype, 0, 6)) === "device") ? "designation" : "name";
268+
$column = (stripos((string) $itemtype, 'item_device') !== false)
269+
? ''
270+
: ((stripos((string) $itemtype, 'device') === 0) ? 'designation' : 'name');
269271

270272
// For rules itemtypes (example : ruledictionnaryphonemodel)
271273
if (strtolower(substr((string) $itemtype, 0, 4)) === 'rule' || $itemtype == "PluginResourcesRulechecklist") {
@@ -296,11 +298,14 @@ public static function showForTag(PluginTagTag $tag)
296298
'WHERE' => [
297299
'glpi_plugin_tag_tagitems.plugin_tag_tags_id' => $instID,
298300
] + getEntitiesRestrictCriteria($itemtable, '', '', $item->maybeRecursive()),
299-
'ORDERBY' => [
300-
$itemtable . '.' . $column,
301-
],
302301
];
303302

303+
if (!empty($column)) {
304+
$criteria['ORDERBY'] = [
305+
$itemtable . '.' . $column,
306+
];
307+
}
308+
304309
if ($item->maybeTemplate()) {
305310
$criteria['WHERE'][$itemtable . '.is_template'] = 0;
306311
}
@@ -339,6 +344,10 @@ public static function showForTag(PluginTagTag $tag)
339344
],
340345
],
341346
];
347+
if (!isset($criteria['ORDERBY']) || !is_array($criteria['ORDERBY'])) {
348+
$criteria['ORDERBY'] = [];
349+
}
350+
342351
array_unshift($criteria['ORDERBY'], 'glpi_entities.completename');
343352
} else {
344353
$criteria['SELECT'][] = new QueryExpression('-1 AS ' . $DB::quoteName('entity'));
@@ -364,7 +373,7 @@ public static function showForTag(PluginTagTag $tag)
364373
);
365374
}
366375

367-
$linkname = $data[$column];
376+
$linkname = $data[$column] ?? "";
368377

369378
if ($_SESSION["glpiis_ids_visible"] || empty($data[$column])) {
370379
$linkname = sprintf(__s('%1$s (%2$s)'), $linkname, $data["id"]);

0 commit comments

Comments
 (0)