9
9
namespace Magento \Theme \Model \Indexer \Design ;
10
10
11
11
use Magento \Framework \App \ResourceConnection ;
12
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
12
13
use Magento \Framework \Indexer \IndexStructureInterface ;
13
14
use Magento \Framework \Indexer \SaveHandler \Batch ;
14
15
use Magento \Framework \Indexer \SaveHandler \Grid ;
@@ -22,51 +23,53 @@ class IndexerHandler extends Grid
22
23
*/
23
24
private $ flatScopeResolver ;
24
25
26
+ /**
27
+ * @param IndexStructureInterface $indexStructure
28
+ * @param ResourceConnection $resource
29
+ * @param Batch $batch
30
+ * @param IndexScopeResolver $indexScopeResolver
31
+ * @param FlatScopeResolver $flatScopeResolver
32
+ * @param array $data
33
+ * @param int $batchSize
34
+ */
25
35
public function __construct (
26
36
IndexStructureInterface $ indexStructure ,
27
37
ResourceConnection $ resource ,
28
38
Batch $ batch ,
29
39
IndexScopeResolver $ indexScopeResolver ,
30
40
FlatScopeResolver $ flatScopeResolver ,
31
41
array $ data ,
32
- $ batchSize = 100 )
33
- {
42
+ $ batchSize = 100
43
+ ) {
34
44
parent ::__construct (
35
45
$ indexStructure ,
36
46
$ resource ,
37
47
$ batch ,
38
48
$ indexScopeResolver ,
39
49
$ flatScopeResolver ,
40
50
$ data ,
41
- $ batchSize );
51
+ $ batchSize
52
+ );
42
53
43
54
$ this ->flatScopeResolver = $ flatScopeResolver ;
44
55
}
45
56
46
57
/**
47
- * @return bool
48
- */
49
- private function isFlatTableExists ()
50
- {
51
- $ adapter = $ this ->resource ->getConnection ('write ' );
52
- $ tableName = $ this ->flatScopeResolver ->resolve ($ this ->getIndexName (), []);
53
-
54
- return $ adapter ->isTableExists ($ tableName );
55
- }
56
-
57
- /**
58
- * Clean index table by deleting all records
58
+ * Clean index table by deleting all records unconditionally or create the index table if not exists
59
59
*
60
- * @inheritdoc
60
+ * @param $dimensions
61
+ * @return IndexerHandler
61
62
*/
62
63
public function cleanIndex ($ dimensions )
63
64
{
64
- if ($ this ->isFlatTableExists ()) {
65
- $ adapter = $ this -> resource -> getConnection ( ' write ' );
66
- $ tableName = $ this ->flatScopeResolver -> resolve ( $ this -> getIndexName (), $ dimensions );
67
- $ adapter ->delete ($ tableName );
65
+ $ tableName = $ this -> flatScopeResolver -> resolve ($ this ->getIndexName (), $ dimensions );
66
+
67
+ if ( $ this ->connection -> isTableExists ( $ tableName )) {
68
+ $ this -> connection ->delete ($ tableName );
68
69
} else {
69
70
$ this ->indexStructure ->create ($ this ->getIndexName (), $ this ->fields , $ dimensions );
70
71
}
72
+
73
+ return $ this ;
71
74
}
72
75
}
0 commit comments