@@ -1606,46 +1606,54 @@ public static function findContainers($itemtype, $type = 'tab', $subtype = '', $
16061606
16071607 $ entityRestriction = getEntitiesRestrictCriteria ('' , '' , $ glpiActiveEntities , true , true );
16081608
1609- if (count ($ entityIds ) === 0 ) {
1610- $ entityIds = [$ entityId ];
1611- }
1612- $ entityIdList = implode (", " , $ entityIds );
1613-
1614- $ sql = "SELECT id FROM glpi_plugin_fields_containers
1615- WHERE is_active = 1
1616- AND type = ' $ type'
1617- AND JSON_CONTAINS(itemtypes, ' \"$ itemtype \"')
1618- AND (
1619- (is_recursive = 1 AND entities_id IN ( $ entityIdList))
1620- OR (is_recursive = 0 AND entities_id = ' $ entityId')
1621- ) " ;
1609+ $ where = [
1610+ 'is_active ' => 1 ,
1611+ 'type ' => $ type ,
1612+ new \QueryExpression ("JSON_CONTAINS(itemtypes, " . $ DB ->quote ('" ' . $ itemtype . '" ' ) . ") " ),
1613+ 'AND ' => [
1614+ 'OR ' => [
1615+ [
1616+ 'is_recursive ' => 1 ,
1617+ 'entities_id ' => $ entityIds ,
1618+ ],
1619+ [
1620+ 'is_recursive ' => 0 ,
1621+ 'entities_id ' => $ entityId ,
1622+ ]
1623+ ]
1624+ ]
1625+ ];
16221626
16231627 if ($ subtype !== '' ) {
16241628 if ($ subtype === $ itemtype . '$main ' ) {
1625- $ sql .= " AND type = 'dom'" ;
1629+ $ where [ ' type ' ] = 'dom ' ;
16261630 } else {
1627- $ sql .= " AND type != 'dom' AND subtype = ' $ subtype' " ;
1631+ $ where ['type ' ] = ['!= ' , 'dom ' ];
1632+ $ where ['subtype ' ] = $ subtype ;
16281633 }
16291634 } else {
1630- $ sql .= " AND type = ' $ type' " ;
1635+ $ where [ ' type ' ] = $ type ;
16311636 }
16321637
1633- if (!empty ($ entityRestriction )) {
1638+ if (is_array ( $ entityRestriction ) && !empty ($ entityRestriction )) {
16341639 $ allowedEntities = [];
16351640 foreach ($ entityRestriction as $ restriction ) {
16361641 if (isset ($ restriction ['entities_id ' ]) && is_array ($ restriction ['entities_id ' ])) {
16371642 $ allowedEntities = array_merge ($ allowedEntities , $ restriction ['entities_id ' ]);
16381643 }
16391644 }
16401645 if (!empty ($ allowedEntities )) {
1641- $ allowedEntitiesStr = implode (", " , $ allowedEntities );
1642- $ sql .= " AND entities_id IN ( $ allowedEntitiesStr) " ;
1646+ $ where ['entities_id ' ] = $ allowedEntities ;
16431647 }
16441648 }
16451649
1646- $ res = $ DB ->query ($ sql );
1650+ $ iterator = $ DB ->request ([
1651+ 'SELECT ' => 'id ' ,
1652+ 'FROM ' => self ::getTable (),
1653+ 'WHERE ' => $ where ,
1654+ ]);
16471655
1648- while ($ row = $ DB -> fetchAssoc ( $ res ) ) {
1656+ foreach ($ iterator as $ row ) {
16491657 $ containerId = (int ) $ row ['id ' ];
16501658
16511659 //profiles restriction
0 commit comments