@@ -1708,46 +1708,54 @@ public static function findContainers($itemtype, $type = 'tab', $subtype = '', $
17081708
17091709 $ entityRestriction = getEntitiesRestrictCriteria ('' , '' , $ glpiActiveEntities , true , true );
17101710
1711- if (count ($ entityIds ) === 0 ) {
1712- $ entityIds = [$ entityId ];
1713- }
1714- $ entityIdList = implode (", " , $ entityIds );
1715-
1716- $ sql = "SELECT id FROM glpi_plugin_fields_containers
1717- WHERE is_active = 1
1718- AND type = ' $ type'
1719- AND JSON_CONTAINS(itemtypes, ' \"$ itemtype \"')
1720- AND (
1721- (is_recursive = 1 AND entities_id IN ( $ entityIdList))
1722- OR (is_recursive = 0 AND entities_id = ' $ entityId')
1723- ) " ;
1711+ $ where = [
1712+ 'is_active ' => 1 ,
1713+ 'type ' => $ type ,
1714+ new \QueryExpression ("JSON_CONTAINS(itemtypes, " . $ DB ->quote ('" ' . $ itemtype . '" ' ) . ") " ),
1715+ 'AND ' => [
1716+ 'OR ' => [
1717+ [
1718+ 'is_recursive ' => 1 ,
1719+ 'entities_id ' => $ entityIds ,
1720+ ],
1721+ [
1722+ 'is_recursive ' => 0 ,
1723+ 'entities_id ' => $ entityId ,
1724+ ]
1725+ ]
1726+ ]
1727+ ];
17241728
17251729 if ($ subtype !== '' ) {
17261730 if ($ subtype === $ itemtype . '$main ' ) {
1727- $ sql .= " AND type = 'dom'" ;
1731+ $ where [ ' type ' ] = 'dom ' ;
17281732 } else {
1729- $ sql .= " AND type != 'dom' AND subtype = ' $ subtype' " ;
1733+ $ where ['type ' ] = ['!= ' , 'dom ' ];
1734+ $ where ['subtype ' ] = $ subtype ;
17301735 }
17311736 } else {
1732- $ sql .= " AND type = ' $ type' " ;
1737+ $ where [ ' type ' ] = $ type ;
17331738 }
17341739
1735- if (!empty ($ entityRestriction )) {
1740+ if (is_array ( $ entityRestriction ) && !empty ($ entityRestriction )) {
17361741 $ allowedEntities = [];
17371742 foreach ($ entityRestriction as $ restriction ) {
17381743 if (isset ($ restriction ['entities_id ' ]) && is_array ($ restriction ['entities_id ' ])) {
17391744 $ allowedEntities = array_merge ($ allowedEntities , $ restriction ['entities_id ' ]);
17401745 }
17411746 }
17421747 if (!empty ($ allowedEntities )) {
1743- $ allowedEntitiesStr = implode (", " , $ allowedEntities );
1744- $ sql .= " AND entities_id IN ( $ allowedEntitiesStr) " ;
1748+ $ where ['entities_id ' ] = $ allowedEntities ;
17451749 }
17461750 }
17471751
1748- $ res = $ DB ->query ($ sql );
1752+ $ iterator = $ DB ->request ([
1753+ 'SELECT ' => 'id ' ,
1754+ 'FROM ' => self ::getTable (),
1755+ 'WHERE ' => $ where ,
1756+ ]);
17491757
1750- while ($ row = $ DB -> fetchAssoc ( $ res ) ) {
1758+ foreach ($ iterator as $ row ) {
17511759 $ containerId = (int ) $ row ['id ' ];
17521760
17531761 //profiles restriction
0 commit comments