@@ -1714,46 +1714,54 @@ public static function findContainers($itemtype, $type = 'tab', $subtype = '', $
17141714
17151715 $ entityRestriction = getEntitiesRestrictCriteria ('' , '' , $ glpiActiveEntities , true , true );
17161716
1717- if (count ($ entityIds ) === 0 ) {
1718- $ entityIds = [$ entityId ];
1719- }
1720- $ entityIdList = implode (", " , $ entityIds );
1721-
1722- $ sql = "SELECT id FROM glpi_plugin_fields_containers
1723- WHERE is_active = 1
1724- AND type = ' $ type'
1725- AND JSON_CONTAINS(itemtypes, ' \"$ itemtype \"')
1726- AND (
1727- (is_recursive = 1 AND entities_id IN ( $ entityIdList))
1728- OR (is_recursive = 0 AND entities_id = ' $ entityId')
1729- ) " ;
1717+ $ where = [
1718+ 'is_active ' => 1 ,
1719+ 'type ' => $ type ,
1720+ new \QueryExpression ("JSON_CONTAINS(itemtypes, " . $ DB ->quote ('" ' . $ itemtype . '" ' ) . ") " ),
1721+ 'AND ' => [
1722+ 'OR ' => [
1723+ [
1724+ 'is_recursive ' => 1 ,
1725+ 'entities_id ' => $ entityIds ,
1726+ ],
1727+ [
1728+ 'is_recursive ' => 0 ,
1729+ 'entities_id ' => $ entityId ,
1730+ ]
1731+ ]
1732+ ]
1733+ ];
17301734
17311735 if ($ subtype !== '' ) {
17321736 if ($ subtype === $ itemtype . '$main ' ) {
1733- $ sql .= " AND type = 'dom'" ;
1737+ $ where [ ' type ' ] = 'dom ' ;
17341738 } else {
1735- $ sql .= " AND type != 'dom' AND subtype = ' $ subtype' " ;
1739+ $ where ['type ' ] = ['!= ' , 'dom ' ];
1740+ $ where ['subtype ' ] = $ subtype ;
17361741 }
17371742 } else {
1738- $ sql .= " AND type = ' $ type' " ;
1743+ $ where [ ' type ' ] = $ type ;
17391744 }
17401745
1741- if (!empty ($ entityRestriction )) {
1746+ if (is_array ( $ entityRestriction ) && !empty ($ entityRestriction )) {
17421747 $ allowedEntities = [];
17431748 foreach ($ entityRestriction as $ restriction ) {
17441749 if (isset ($ restriction ['entities_id ' ]) && is_array ($ restriction ['entities_id ' ])) {
17451750 $ allowedEntities = array_merge ($ allowedEntities , $ restriction ['entities_id ' ]);
17461751 }
17471752 }
17481753 if (!empty ($ allowedEntities )) {
1749- $ allowedEntitiesStr = implode (", " , $ allowedEntities );
1750- $ sql .= " AND entities_id IN ( $ allowedEntitiesStr) " ;
1754+ $ where ['entities_id ' ] = $ allowedEntities ;
17511755 }
17521756 }
17531757
1754- $ res = $ DB ->query ($ sql );
1758+ $ iterator = $ DB ->request ([
1759+ 'SELECT ' => 'id ' ,
1760+ 'FROM ' => self ::getTable (),
1761+ 'WHERE ' => $ where ,
1762+ ]);
17551763
1756- while ($ row = $ DB -> fetchAssoc ( $ res ) ) {
1764+ foreach ($ iterator as $ row ) {
17571765 $ containerId = (int ) $ row ['id ' ];
17581766
17591767 //profiles restriction
0 commit comments