6
6
7
7
namespace Magento \Catalog \Model \Indexer \Category \Flat ;
8
8
9
+ use Magento \Catalog \Api \Data \CategoryInterface ;
10
+ use Magento \Catalog \Model \Category ;
11
+ use Magento \Catalog \Model \ResourceModel \Helper ;
12
+ use Magento \Framework \App \ObjectManager ;
9
13
use Magento \Framework \App \ResourceConnection ;
14
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
15
+ use Magento \Framework \DB \Ddl \Table ;
16
+ use Magento \Framework \EntityManager \EntityMetadata ;
17
+ use Magento \Store \Model \Store ;
18
+ use Magento \Store \Model \StoreManagerInterface ;
10
19
11
20
/**
12
21
* Abstract action class for category flat indexers.
22
+ *
23
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
24
*/
14
25
class AbstractAction
15
26
{
@@ -31,14 +42,14 @@ class AbstractAction
31
42
protected $ resource ;
32
43
33
44
/**
34
- * @var \Magento\Store\Model\ StoreManagerInterface
45
+ * @var StoreManagerInterface
35
46
*/
36
47
protected $ storeManager ;
37
48
38
49
/**
39
50
* Catalog resource helper
40
51
*
41
- * @var \Magento\Catalog\Model\ResourceModel\ Helper
52
+ * @var Helper
42
53
*/
43
54
protected $ resourceHelper ;
44
55
@@ -50,12 +61,12 @@ class AbstractAction
50
61
protected $ columns = [];
51
62
52
63
/**
53
- * @var \Magento\Framework\DB\Adapter\ AdapterInterface
64
+ * @var AdapterInterface
54
65
*/
55
66
protected $ connection ;
56
67
57
68
/**
58
- * @var \Magento\Framework\EntityManager\ EntityMetadata
69
+ * @var EntityMetadata
59
70
*/
60
71
protected $ categoryMetadata ;
61
72
@@ -68,13 +79,13 @@ class AbstractAction
68
79
69
80
/**
70
81
* @param ResourceConnection $resource
71
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
72
- * @param \Magento\Catalog\Model\ResourceModel\ Helper $resourceHelper
82
+ * @param StoreManagerInterface $storeManager
83
+ * @param Helper $resourceHelper
73
84
*/
74
85
public function __construct (
75
86
ResourceConnection $ resource ,
76
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
77
- \ Magento \ Catalog \ Model \ ResourceModel \ Helper $ resourceHelper
87
+ StoreManagerInterface $ storeManager ,
88
+ Helper $ resourceHelper
78
89
) {
79
90
$ this ->resource = $ resource ;
80
91
$ this ->connection = $ resource ->getConnection ();
@@ -110,23 +121,22 @@ public function getColumns()
110
121
* @param integer $storeId
111
122
* @return string
112
123
*/
113
- public function getMainStoreTable ($ storeId = \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID )
124
+ public function getMainStoreTable ($ storeId = Store::DEFAULT_STORE_ID )
114
125
{
115
126
if (is_string ($ storeId )) {
116
127
$ storeId = (int ) $ storeId ;
117
128
}
118
129
119
130
$ suffix = sprintf ('store_%d ' , $ storeId );
120
- $ table = $ this ->connection ->getTableName ($ this ->getTableName ('catalog_category_flat_ ' . $ suffix ));
121
-
122
- return $ table ;
131
+ return $ this ->connection ->getTableName ($ this ->getTableName ('catalog_category_flat_ ' . $ suffix ));
123
132
}
124
133
125
134
/**
126
135
* Return structure for flat catalog table
127
136
*
128
137
* @param string $tableName
129
- * @return \Magento\Framework\DB\Ddl\Table
138
+ * @return Table
139
+ * @throws \Zend_Db_Exception
130
140
*/
131
141
protected function getFlatTableStructure ($ tableName )
132
142
{
@@ -139,10 +149,10 @@ protected function getFlatTableStructure($tableName)
139
149
//Adding columns
140
150
foreach ($ this ->getColumns () as $ fieldName => $ fieldProp ) {
141
151
$ default = $ fieldProp ['default ' ];
142
- if ($ fieldProp ['type ' ][0 ] == \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_TIMESTAMP
152
+ if ($ fieldProp ['type ' ][0 ] == Table::TYPE_TIMESTAMP
143
153
&& $ default == 'CURRENT_TIMESTAMP '
144
154
) {
145
- $ default = \ Magento \ Framework \ DB \ Ddl \ Table::TIMESTAMP_INIT ;
155
+ $ default = Table::TIMESTAMP_INIT ;
146
156
}
147
157
$ table ->addColumn (
148
158
$ fieldName ,
@@ -205,37 +215,37 @@ protected function getStaticColumns()
205
215
$ ddlType = $ this ->resourceHelper ->getDdlTypeByColumnType ($ column ['DATA_TYPE ' ]);
206
216
$ column ['DEFAULT ' ] = trim ($ column ['DEFAULT ' ], "' " );
207
217
switch ($ ddlType ) {
208
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_SMALLINT :
209
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_INTEGER :
210
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_BIGINT :
218
+ case Table::TYPE_SMALLINT :
219
+ case Table::TYPE_INTEGER :
220
+ case Table::TYPE_BIGINT :
211
221
$ isUnsigned = (bool )$ column ['UNSIGNED ' ];
212
222
if ($ column ['DEFAULT ' ] === '' ) {
213
223
$ column ['DEFAULT ' ] = null ;
214
224
}
215
225
216
226
$ options = null ;
217
227
if ($ column ['SCALE ' ] > 0 ) {
218
- $ ddlType = \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_DECIMAL ;
228
+ $ ddlType = Table::TYPE_DECIMAL ;
219
229
} else {
220
230
break ;
221
231
}
222
232
// fall-through intentional
223
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_DECIMAL :
233
+ case Table::TYPE_DECIMAL :
224
234
$ options = $ column ['PRECISION ' ] . ', ' . $ column ['SCALE ' ];
225
235
$ isUnsigned = null ;
226
236
if ($ column ['DEFAULT ' ] === '' ) {
227
237
$ column ['DEFAULT ' ] = null ;
228
238
}
229
239
break ;
230
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_TEXT :
240
+ case Table::TYPE_TEXT :
231
241
$ options = $ column ['LENGTH ' ];
232
242
$ isUnsigned = null ;
233
243
break ;
234
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_TIMESTAMP :
244
+ case Table::TYPE_TIMESTAMP :
235
245
$ options = null ;
236
246
$ isUnsigned = null ;
237
247
break ;
238
- case \ Magento \ Framework \ DB \ Ddl \ Table::TYPE_DATETIME :
248
+ case Table::TYPE_DATETIME :
239
249
$ isUnsigned = null ;
240
250
break ;
241
251
}
@@ -248,7 +258,7 @@ protected function getStaticColumns()
248
258
];
249
259
}
250
260
$ columns ['store_id ' ] = [
251
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_SMALLINT , 5 ],
261
+ 'type ' => [Table::TYPE_SMALLINT , 5 ],
252
262
'unsigned ' => true ,
253
263
'nullable ' => false ,
254
264
'default ' => '0 ' ,
@@ -274,7 +284,7 @@ protected function getEavColumns()
274
284
switch ($ attribute ['backend_type ' ]) {
275
285
case 'varchar ' :
276
286
$ columns [$ attribute ['attribute_code ' ]] = [
277
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_TEXT , 255 ],
287
+ 'type ' => [Table::TYPE_TEXT , 255 ],
278
288
'unsigned ' => null ,
279
289
'nullable ' => true ,
280
290
'default ' => null ,
@@ -283,7 +293,7 @@ protected function getEavColumns()
283
293
break ;
284
294
case 'int ' :
285
295
$ columns [$ attribute ['attribute_code ' ]] = [
286
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_INTEGER , null ],
296
+ 'type ' => [Table::TYPE_INTEGER , null ],
287
297
'unsigned ' => null ,
288
298
'nullable ' => true ,
289
299
'default ' => null ,
@@ -292,7 +302,7 @@ protected function getEavColumns()
292
302
break ;
293
303
case 'text ' :
294
304
$ columns [$ attribute ['attribute_code ' ]] = [
295
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_TEXT , '64k ' ],
305
+ 'type ' => [Table::TYPE_TEXT , '64k ' ],
296
306
'unsigned ' => null ,
297
307
'nullable ' => true ,
298
308
'default ' => null ,
@@ -301,7 +311,7 @@ protected function getEavColumns()
301
311
break ;
302
312
case 'datetime ' :
303
313
$ columns [$ attribute ['attribute_code ' ]] = [
304
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_DATETIME , null ],
314
+ 'type ' => [Table::TYPE_DATETIME , null ],
305
315
'unsigned ' => null ,
306
316
'nullable ' => true ,
307
317
'default ' => null ,
@@ -310,7 +320,7 @@ protected function getEavColumns()
310
320
break ;
311
321
case 'decimal ' :
312
322
$ columns [$ attribute ['attribute_code ' ]] = [
313
- 'type ' => [\ Magento \ Framework \ DB \ Ddl \ Table::TYPE_DECIMAL , '12,4 ' ],
323
+ 'type ' => [Table::TYPE_DECIMAL , '12,4 ' ],
314
324
'unsigned ' => null ,
315
325
'nullable ' => true ,
316
326
'default ' => null ,
@@ -346,7 +356,7 @@ protected function getAttributes()
346
356
$ this ->connection ->getTableName (
347
357
$ this ->getTableName ('eav_entity_type ' )
348
358
) . '.entity_type_code = ? ' ,
349
- \ Magento \ Catalog \ Model \ Category::ENTITY
359
+ Category::ENTITY
350
360
);
351
361
$ this ->attributeCodes = [];
352
362
foreach ($ this ->connection ->fetchAll ($ select ) as $ attribute ) {
@@ -414,7 +424,8 @@ private function getLinkIds(array $entityIds)
414
424
[$ linkField ]
415
425
)->where (
416
426
'e.entity_id IN (?) ' ,
417
- $ entityIds
427
+ $ entityIds ,
428
+ \Zend_Db::INT_TYPE
418
429
);
419
430
420
431
return $ this ->connection ->fetchCol ($ select );
@@ -459,10 +470,12 @@ protected function getAttributeTypeValues($type, $entityIds, $storeId)
459
470
]
460
471
)->where (
461
472
"e.entity_id IN (?) " ,
462
- $ entityIds
473
+ $ entityIds ,
474
+ \Zend_Db::INT_TYPE
463
475
)->where (
464
476
'def.store_id IN (?) ' ,
465
- [\Magento \Store \Model \Store::DEFAULT_STORE_ID , $ storeId ]
477
+ [Store::DEFAULT_STORE_ID , $ storeId ],
478
+ \Zend_Db::INT_TYPE
466
479
);
467
480
468
481
return $ this ->connection ->fetchAll ($ select );
@@ -501,14 +514,14 @@ protected function getTableName($name)
501
514
/**
502
515
* Get category metadata instance.
503
516
*
504
- * @return \Magento\Framework\EntityManager\ EntityMetadata
517
+ * @return EntityMetadata
505
518
*/
506
519
private function getCategoryMetadata ()
507
520
{
508
521
if (null === $ this ->categoryMetadata ) {
509
- $ metadataPool = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
522
+ $ metadataPool = ObjectManager::getInstance ()
510
523
->get (\Magento \Framework \EntityManager \MetadataPool::class);
511
- $ this ->categoryMetadata = $ metadataPool ->getMetadata (\ Magento \ Catalog \ Api \ Data \ CategoryInterface::class);
524
+ $ this ->categoryMetadata = $ metadataPool ->getMetadata (CategoryInterface::class);
512
525
}
513
526
return $ this ->categoryMetadata ;
514
527
}
@@ -521,8 +534,8 @@ private function getCategoryMetadata()
521
534
private function getSkipStaticColumns ()
522
535
{
523
536
if (null === $ this ->skipStaticColumns ) {
524
- $ provider = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
525
- ->get (\ Magento \ Catalog \ Model \ Indexer \ Category \ Flat \ SkipStaticColumnsProvider::class);
537
+ $ provider = ObjectManager::getInstance ()
538
+ ->get (SkipStaticColumnsProvider::class);
526
539
$ this ->skipStaticColumns = $ provider ->get ();
527
540
}
528
541
return $ this ->skipStaticColumns ;
0 commit comments