6
6
namespace Magento \Catalog \Model \Indexer \Product \Flat ;
7
7
8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Catalog \Helper \Product \Flat \Indexer ;
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
9
11
use Magento \Framework \App \ResourceConnection ;
12
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
13
+ use Magento \Framework \DB \Ddl \Table ;
10
14
use Magento \Framework \EntityManager \MetadataPool ;
15
+ use Magento \Framework \Exception \LocalizedException ;
16
+ use Magento \Framework \Exception \NoSuchEntityException ;
17
+ use Magento \Store \Model \StoreManagerInterface ;
18
+ use Magento \Catalog \Model \Product \Attribute \Source \Status ;
19
+ use Magento \Framework \App \ObjectManager ;
20
+ use Magento \Eav \Model \Entity \Attribute ;
21
+ use Magento \Framework \DB \Select ;
11
22
12
23
/**
13
24
* Class for building flat index
@@ -27,22 +38,22 @@ class FlatTableBuilder
27
38
const XML_NODE_MAX_INDEX_COUNT = 'catalog/product/flat/max_index_count ' ;
28
39
29
40
/**
30
- * @var \Magento\Catalog\Helper\Product\Flat\ Indexer
41
+ * @var Indexer
31
42
*/
32
43
protected $ _productIndexerHelper ;
33
44
34
45
/**
35
- * @var \Magento\Framework\DB\Adapter\ AdapterInterface
46
+ * @var AdapterInterface
36
47
*/
37
48
protected $ _connection ;
38
49
39
50
/**
40
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface $config
51
+ * @var ScopeConfigInterface $config
41
52
*/
42
53
protected $ _config ;
43
54
44
55
/**
45
- * @var \Magento\Store\Model\ StoreManagerInterface
56
+ * @var StoreManagerInterface
46
57
*/
47
58
protected $ _storeManager ;
48
59
@@ -52,23 +63,23 @@ class FlatTableBuilder
52
63
protected $ _tableData ;
53
64
54
65
/**
55
- * @var \Magento\Framework\App\ ResourceConnection
66
+ * @var ResourceConnection
56
67
*/
57
68
protected $ resource ;
58
69
59
70
/**
60
- * @param \Magento\Catalog\Helper\Product\Flat\ Indexer $productIndexerHelper
71
+ * @param Indexer $productIndexerHelper
61
72
* @param ResourceConnection $resource
62
- * @param \Magento\Framework\App\Config\ ScopeConfigInterface $config
63
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
73
+ * @param ScopeConfigInterface $config
74
+ * @param StoreManagerInterface $storeManager
64
75
* @param TableDataInterface $tableData
65
76
*/
66
77
public function __construct (
67
- \ Magento \ Catalog \ Helper \ Product \ Flat \ Indexer $ productIndexerHelper ,
68
- \ Magento \ Framework \ App \ ResourceConnection $ resource ,
69
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ config ,
70
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
71
- \ Magento \ Catalog \ Model \ Indexer \ Product \ Flat \ TableDataInterface $ tableData
78
+ Indexer $ productIndexerHelper ,
79
+ ResourceConnection $ resource ,
80
+ ScopeConfigInterface $ config ,
81
+ StoreManagerInterface $ storeManager ,
82
+ TableDataInterface $ tableData
72
83
) {
73
84
$ this ->_productIndexerHelper = $ productIndexerHelper ;
74
85
$ this ->resource = $ resource ;
@@ -114,7 +125,7 @@ public function build($storeId, $changedIds, $valueFieldSuffix, $tableDropSuffix
114
125
*
115
126
* @param int|string $storeId
116
127
* @return void
117
- * @throws \Magento\Framework\Exception\ LocalizedException
128
+ * @throws LocalizedException
118
129
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
119
130
* @SuppressWarnings(PHPMD.NPathComplexity)
120
131
*/
@@ -128,7 +139,7 @@ protected function _createTemporaryFlatTable($storeId)
128
139
self ::XML_NODE_MAX_INDEX_COUNT
129
140
);
130
141
if ($ maxIndex && count ($ indexesNeed ) > $ maxIndex ) {
131
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
142
+ throw new LocalizedException (
132
143
__ (
133
144
'The Flat Catalog module has a limit of %2$d filterable and/or sortable attributes. '
134
145
. 'Currently there are %1$d of them. '
@@ -141,7 +152,7 @@ protected function _createTemporaryFlatTable($storeId)
141
152
142
153
$ indexKeys = [];
143
154
$ indexProps = array_values ($ indexesNeed );
144
- $ upperPrimaryKey = strtoupper (\ Magento \ Framework \ DB \ Adapter \ AdapterInterface::INDEX_TYPE_PRIMARY );
155
+ $ upperPrimaryKey = strtoupper (AdapterInterface::INDEX_TYPE_PRIMARY );
145
156
foreach ($ indexProps as $ i => $ indexProp ) {
146
157
$ indexName = $ this ->_connection ->getIndexName (
147
158
$ this ->_getTemporaryTableName ($ this ->_productIndexerHelper ->getFlatTableName ($ storeId )),
@@ -164,7 +175,7 @@ protected function _createTemporaryFlatTable($storeId)
164
175
}
165
176
$ indexesNeed = array_combine ($ indexKeys , $ indexProps );
166
177
167
- /** @var $table \Magento\Framework\DB\Ddl\ Table */
178
+ /** @var $table Table */
168
179
$ table = $ this ->_connection ->newTable (
169
180
$ this ->_getTemporaryTableName ($ this ->_productIndexerHelper ->getFlatTableName ($ storeId ))
170
181
);
@@ -212,7 +223,7 @@ protected function _createTemporaryFlatTable($storeId)
212
223
* @param string $valueFieldSuffix
213
224
* @return void
214
225
* @throws LocalizedException
215
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
226
+ * @throws NoSuchEntityException
216
227
*/
217
228
protected function _fillTemporaryFlatTable (array $ tables , $ storeId , $ valueFieldSuffix )
218
229
{
@@ -228,8 +239,8 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
228
239
$ websiteId = (int )$ this ->_storeManager ->getStore ($ storeId )->getWebsiteId ();
229
240
230
241
unset($ tables [$ entityTableName ]);
231
-
232
- $ allColumns = array_values (
242
+ $ allColumns = [];
243
+ $ allColumns[] = array_values (
233
244
array_unique (
234
245
array_merge (['entity_id ' , $ linkField , 'type_id ' , 'attribute_set_id ' ], $ columnsList )
235
246
)
@@ -278,7 +289,7 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
278
289
sprintf ('e.%1$s = %2$s.%1$s ' , $ linkField , $ temporaryTableName ),
279
290
$ columnsNames
280
291
);
281
- $ allColumns = array_merge ( $ allColumns , $ columnsNames) ;
292
+ $ allColumns[] = $ columnsNames ;
282
293
283
294
foreach ($ columnsNames as $ name ) {
284
295
$ columnValueName = $ name . $ valueFieldSuffix ;
@@ -292,10 +303,10 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
292
303
sprintf ('e.%1$s = %2$s.%1$s ' , $ linkField , $ temporaryValueTableName ),
293
304
$ columnValueNames
294
305
);
295
- $ allColumns = array_merge ( $ allColumns , $ columnValueNames) ;
306
+ $ allColumns[] = $ columnValueNames ;
296
307
}
297
308
}
298
- $ sql = $ select ->insertFromSelect ($ temporaryFlatTableName , $ allColumns , false );
309
+ $ sql = $ select ->insertFromSelect ($ temporaryFlatTableName , array_merge (... $ allColumns) , false );
299
310
$ this ->_connection ->query ($ sql );
300
311
}
301
312
@@ -368,8 +379,12 @@ protected function _updateTemporaryTableByStoreValues(
368
379
)->where ($ columnValue . ' IS NOT NULL ' );
369
380
if (!empty ($ changedIds )) {
370
381
$ select ->where (
371
- $ this ->_connection ->quoteInto ('et.entity_id IN (?) ' , $ changedIds , \Zend_Db::BIGINT_TYPE ))
372
- ;
382
+ $ this ->_connection ->quoteInto (
383
+ 'et.entity_id IN (?) ' ,
384
+ $ changedIds ,
385
+ \Zend_Db::BIGINT_TYPE
386
+ )
387
+ );
373
388
}
374
389
$ sql = $ select ->crossUpdateFromSelect (['et ' => $ temporaryFlatTableName ]);
375
390
$ this ->_connection ->query ($ sql );
0 commit comments