@@ -659,25 +659,30 @@ protected function makeTempCategoryTreeIndex()
659
659
*/
660
660
protected function fillTempCategoryTreeIndex ($ temporaryName )
661
661
{
662
- // This finds all children (cc2) that descend from a parent (cc) by path.
663
- // For example, cc.path may be '1/2', and cc2.path may be '1/2/3/4/5'.
664
- $ temporarySelect = $ this ->connection ->select ()->from (
665
- ['cc ' => $ this ->getTable ('catalog_category_entity ' )],
666
- ['parent_id ' => 'entity_id ' ]
667
- )->joinInner (
668
- ['cc2 ' => $ this ->getTable ('catalog_category_entity ' )],
669
- 'cc2.path LIKE ' . $ this ->connection ->getConcatSql (
670
- [$ this ->connection ->quoteIdentifier ('cc.path ' ), $ this ->connection ->quote ('/% ' )]
671
- ),
672
- ['child_id ' => 'entity_id ' ]
662
+ $ selects = $ this ->prepareSelectsByRange (
663
+ $ this ->connection ->select ()
664
+ ->from (
665
+ ['c ' => $ this ->getTable ('catalog_category_entity ' )],
666
+ ['entity_id ' , 'path ' ]
667
+ ),
668
+ 'entity_id '
673
669
);
674
670
675
- $ this ->connection ->query (
676
- $ temporarySelect ->insertFromSelect (
677
- $ temporaryName ,
678
- ['parent_id ' , 'child_id ' ]
679
- )
680
- );
671
+ foreach ($ selects as $ select ) {
672
+ $ values = [];
673
+
674
+ foreach ($ this ->connection ->fetchAll ($ select ) as $ category ) {
675
+ foreach (explode ('/ ' , $ category ['path ' ]) as $ parentId ) {
676
+ if ($ parentId !== $ category ['entity_id ' ]) {
677
+ $ values [] = [$ parentId , $ category ['entity_id ' ]];
678
+ }
679
+ }
680
+ }
681
+
682
+ if (count ($ values ) > 0 ) {
683
+ $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' ], $ values );
684
+ }
685
+ }
681
686
}
682
687
683
688
/**
0 commit comments