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

- Fix crash when injection model has no mandatory fields defined
- Fix models created on parent entities can't be used on child entites

## [2.15.4] - 2026-03-16

Expand Down
49 changes: 30 additions & 19 deletions inc/model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,29 +382,40 @@ public static function getModels($user_id, $order = "name", $entity = -1, $all =
global $DB;

$models = [];
$query = "SELECT `id`, `name`, `is_private`, `entities_id`, `is_recursive`, `itemtype`,
`step`, `comment`
FROM `glpi_plugin_datainjection_models` ";

$query = [
'SELECT' => ['id', 'name', 'is_private', 'entities_id', 'is_recursive', 'itemtype', 'step', 'comment'],
'FROM' => 'glpi_plugin_datainjection_models',
];
Comment thread
Rom1-B marked this conversation as resolved.
Outdated

$where = [];
if (!$all) {
$query .= " WHERE `step` = '" . self::READY_TO_USE_STEP . "' AND (";
} else {
$query .= " WHERE (";
$where['step'] = self::READY_TO_USE_STEP;
}

$query .= "(`is_private` = '" . self::MODEL_PUBLIC . "'" .
getEntitiesRestrictRequest(
" AND",
"glpi_plugin_datainjection_models",
"entities_id",
$entity,
false,
) . ")
OR (`is_private` = '" . self::MODEL_PRIVATE . "' AND `users_id` = '$user_id'))
ORDER BY `is_private` DESC,
`entities_id`, " . ($order == "`name`" ? "`name`" : $order);

foreach ($DB->doQuery($query) as $data) {
$restrict = getEntitiesRestrictCriteria(
'glpi_plugin_datainjection_models',
'entities_id',
$entity,
true,
);

$where[] = [
'OR' => [
[
'is_private' => self::MODEL_PUBLIC,
] + $restrict,
[
'is_private' => self::MODEL_PRIVATE,
'users_id' => $user_id,
],
],
];

$query['WHERE'] = $where;
$query['ORDER'] = ['is_private DESC', 'entities_id', $order == "`name`" ? "name" : $order];
Comment thread
Rom1-B marked this conversation as resolved.
Outdated

foreach ($DB->request($query) as $data) {
if (
self::checkRightOnModel($data['id'])
&& class_exists($data['itemtype'])
Expand Down