|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Glpi\DBAL\QueryExpression; |
4 | 3 | use Glpi\Error\ErrorHandler; |
5 | 4 | use Safe\Exceptions\InfoException; |
6 | 5 |
|
7 | 6 | use function Safe\ini_set; |
8 | 7 | use function Safe\json_decode; |
9 | | - |
10 | 8 | /** |
11 | 9 | * --------------------------------------------------------------------- |
12 | 10 | * GLPI Inventory Plugin |
|
38 | 36 | * --------------------------------------------------------------------- |
39 | 37 | */ |
40 | 38 |
|
41 | | -function plugin_glpiinventory_add_default_where($in) |
42 | | -{ |
43 | | - [$itemtype, $condition] = $in; |
44 | | - |
45 | | - if ($itemtype === Computer::class && str_contains($_SERVER['REQUEST_URI'] ?? '', 'deploypackage.public.php')) { |
46 | | - // Specific case related to Self-Service profile rights: |
47 | | - // - As Computer object has no read permission for Self-Service profile, |
48 | | - // Computer::getAssignableVisiblityCriteria() returns a QueryExpression("0"). |
49 | | - // - This leads to a "WHERE (0)" clause in the SQL query, which discards |
50 | | - // all results (e.g. no deployment packages shown in Self-Service). |
51 | | - // - To fix this in the plugin, we explicitly filter out QueryExpression |
52 | | - // instances with value "0", while keeping all other valid criteria |
53 | | - // generated by GLPI. |
54 | | - removeEmptyCondition($condition); |
55 | | - } |
56 | | - |
57 | | - return [$itemtype, $condition]; |
58 | | -} |
59 | | - |
60 | | -function removeEmptyCondition(array &$conditions): void |
61 | | -{ |
62 | | - foreach ($conditions as $key => $condition) { |
63 | | - if (is_array($condition)) { |
64 | | - removeEmptyCondition($condition); |
65 | | - if (empty($condition)) { |
66 | | - unset($conditions[$key]); |
67 | | - } |
68 | | - } elseif ($condition instanceof QueryExpression && $condition->getValue() == 0) { |
69 | | - unset($conditions[$key]); |
70 | | - } |
71 | | - } |
72 | | -} |
73 | | - |
74 | 39 | /** |
75 | 40 | * Add search options for GLPI objects |
76 | 41 | * |
|
0 commit comments