@@ -123,6 +123,11 @@ abstract class AbstractAction
123
123
*/
124
124
private $ queryGenerator ;
125
125
126
+ /**
127
+ * @var int
128
+ */
129
+ private $ currentStoreId = 0 ;
130
+
126
131
/**
127
132
* @param ResourceConnection $resource
128
133
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -164,6 +169,7 @@ protected function reindex()
164
169
{
165
170
foreach ($ this ->storeManager ->getStores () as $ store ) {
166
171
if ($ this ->getPathFromCategoryId ($ store ->getRootCategoryId ())) {
172
+ $ this ->currentStoreId = $ store ->getId ();
167
173
$ this ->reindexRootCategory ($ store );
168
174
$ this ->reindexAnchorCategories ($ store );
169
175
$ this ->reindexNonAnchorCategories ($ store );
@@ -586,6 +592,8 @@ protected function createAnchorSelect(Store $store)
586
592
}
587
593
588
594
/**
595
+ * Get temporary table name
596
+ *
589
597
* Get temporary table name for concurrent indexing in persistent connection
590
598
* Temp table name is NOT shared between action instances and each action has it's own temp tree index
591
599
*
@@ -597,7 +605,7 @@ protected function getTemporaryTreeIndexTableName()
597
605
if (empty ($ this ->tempTreeIndexTableName )) {
598
606
$ this ->tempTreeIndexTableName = $ this ->connection ->getTableName ('temp_catalog_category_tree_index ' )
599
607
. '_ '
600
- . substr (md5 (time () . random_int (0 , 999999999 )), 0 , 8 );
608
+ . substr (sha1 (time () . random_int (0 , 999999999 )), 0 , 8 );
601
609
}
602
610
603
611
return $ this ->tempTreeIndexTableName ;
@@ -641,7 +649,6 @@ protected function makeTempCategoryTreeIndex()
641
649
['child_id ' ],
642
650
['type ' => \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_INDEX ]
643
651
);
644
-
645
652
// Drop the temporary table in case it already exists on this (persistent?) connection.
646
653
$ this ->connection ->dropTemporaryTable ($ temporaryName );
647
654
$ this ->connection ->createTemporaryTable ($ temporaryTable );
@@ -659,11 +666,31 @@ protected function makeTempCategoryTreeIndex()
659
666
*/
660
667
protected function fillTempCategoryTreeIndex ($ temporaryName )
661
668
{
669
+ $ isActiveAttributeId = $ this ->config ->getAttribute (
670
+ \Magento \Catalog \Model \Category::ENTITY ,
671
+ 'is_active '
672
+ )->getId ();
673
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \CategoryInterface::class);
674
+ $ categoryLinkField = $ categoryMetadata ->getLinkField ();
662
675
$ selects = $ this ->prepareSelectsByRange (
663
676
$ this ->connection ->select ()
664
677
->from (
665
678
['c ' => $ this ->getTable ('catalog_category_entity ' )],
666
679
['entity_id ' , 'path ' ]
680
+ )->joinInner (
681
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
682
+ 'ccacd. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
683
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
684
+ []
685
+ )->joinLeft (
686
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
687
+ 'ccacs. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField
688
+ . ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
689
+ $ this ->currentStoreId ,
690
+ []
691
+ )->where (
692
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
693
+ 1
667
694
),
668
695
'entity_id '
669
696
);
0 commit comments