14
14
use Magento \Framework \DB \Adapter \AdapterInterface ;
15
15
use Magento \Framework \DB \Ddl \Table ;
16
16
use Magento \Framework \EntityManager \EntityMetadata ;
17
+ use Magento \Framework \EntityManager \MetadataPool ;
17
18
use Magento \Store \Model \Store ;
18
19
use Magento \Store \Model \StoreManagerInterface ;
19
20
@@ -27,11 +28,9 @@ class AbstractAction
27
28
/**
28
29
* Suffix for table to show it is temporary
29
30
*/
30
- const TEMPORARY_TABLE_SUFFIX = '_tmp ' ;
31
+ public const TEMPORARY_TABLE_SUFFIX = '_tmp ' ;
31
32
32
33
/**
33
- * Attribute codes
34
- *
35
34
* @var array
36
35
*/
37
36
protected $ attributeCodes ;
@@ -77,20 +76,33 @@ class AbstractAction
77
76
*/
78
77
protected $ skipStaticColumns = [];
79
78
79
+ /**
80
+ * @var SkipStaticColumnsProvider
81
+ */
82
+ private $ skipStaticColumnsProvider ;
83
+
80
84
/**
81
85
* @param ResourceConnection $resource
82
86
* @param StoreManagerInterface $storeManager
83
87
* @param Helper $resourceHelper
88
+ * @param MetadataPool|null $metadataPool
89
+ * @param SkipStaticColumnsProvider|null $skipStaticColumnsProvider
84
90
*/
85
91
public function __construct (
86
92
ResourceConnection $ resource ,
87
93
StoreManagerInterface $ storeManager ,
88
- Helper $ resourceHelper
94
+ Helper $ resourceHelper ,
95
+ MetadataPool $ metadataPool = null ,
96
+ SkipStaticColumnsProvider $ skipStaticColumnsProvider = null
89
97
) {
90
98
$ this ->resource = $ resource ;
91
99
$ this ->connection = $ resource ->getConnection ();
92
100
$ this ->storeManager = $ storeManager ;
93
101
$ this ->resourceHelper = $ resourceHelper ;
102
+ $ metadataPool = $ metadataPool ?? ObjectManager::getInstance ()->get (MetadataPool::class);
103
+ $ this ->categoryMetadata = $ metadataPool ->getMetadata (CategoryInterface::class);
104
+ $ this ->skipStaticColumnsProvider = $ skipStaticColumnsProvider
105
+ ?? ObjectManager::getInstance ()->get (SkipStaticColumnsProvider::class);
94
106
$ this ->columns = array_merge ($ this ->getStaticColumns (), $ this ->getEavColumns ());
95
107
}
96
108
@@ -213,7 +225,7 @@ protected function getStaticColumns()
213
225
$ isUnsigned = '' ;
214
226
$ options = null ;
215
227
$ ddlType = $ this ->resourceHelper ->getDdlTypeByColumnType ($ column ['DATA_TYPE ' ]);
216
- $ column ['DEFAULT ' ] = trim ($ column ['DEFAULT ' ], "' " );
228
+ $ column ['DEFAULT ' ] = $ column [ ' DEFAULT ' ] ? trim ($ column ['DEFAULT ' ], "' " ) : '' ;
217
229
switch ($ ddlType ) {
218
230
case Table::TYPE_SMALLINT :
219
231
case Table::TYPE_INTEGER :
@@ -388,7 +400,7 @@ protected function getAttributeValues($entityIds, $storeId)
388
400
389
401
$ attributes = $ this ->getAttributes ();
390
402
$ attributesType = ['varchar ' , 'int ' , 'decimal ' , 'text ' , 'datetime ' ];
391
- $ linkField = $ this ->getCategoryMetadata () ->getLinkField ();
403
+ $ linkField = $ this ->categoryMetadata ->getLinkField ();
392
404
foreach ($ attributesType as $ type ) {
393
405
foreach ($ this ->getAttributeTypeValues ($ type , $ entityIds , $ storeId ) as $ row ) {
394
406
if (isset ($ row [$ linkField ], $ row ['attribute_id ' ])) {
@@ -414,7 +426,7 @@ protected function getAttributeValues($entityIds, $storeId)
414
426
*/
415
427
private function getLinkIds (array $ entityIds )
416
428
{
417
- $ linkField = $ this ->getCategoryMetadata () ->getLinkField ();
429
+ $ linkField = $ this ->categoryMetadata ->getLinkField ();
418
430
if ($ linkField === 'entity_id ' ) {
419
431
return $ entityIds ;
420
432
}
@@ -441,7 +453,7 @@ private function getLinkIds(array $entityIds)
441
453
*/
442
454
protected function getAttributeTypeValues ($ type , $ entityIds , $ storeId )
443
455
{
444
- $ linkField = $ this ->getCategoryMetadata () ->getLinkField ();
456
+ $ linkField = $ this ->categoryMetadata ->getLinkField ();
445
457
$ select = $ this ->connection ->select ()->from (
446
458
[
447
459
'def ' => $ this ->connection ->getTableName ($ this ->getTableName ('catalog_category_entity_ ' . $ type )),
@@ -512,31 +524,14 @@ protected function getTableName($name)
512
524
}
513
525
514
526
/**
515
- * Get category metadata instance.
516
- *
517
- * @return EntityMetadata
518
- */
519
- private function getCategoryMetadata ()
520
- {
521
- if (null === $ this ->categoryMetadata ) {
522
- $ metadataPool = ObjectManager::getInstance ()
523
- ->get (\Magento \Framework \EntityManager \MetadataPool::class);
524
- $ this ->categoryMetadata = $ metadataPool ->getMetadata (CategoryInterface::class);
525
- }
526
- return $ this ->categoryMetadata ;
527
- }
528
-
529
- /**
530
- * Get skip static columns instance.
527
+ * Gets skipped static columns.
531
528
*
532
529
* @return array
533
530
*/
534
531
private function getSkipStaticColumns ()
535
532
{
536
- if (null === $ this ->skipStaticColumns ) {
537
- $ provider = ObjectManager::getInstance ()
538
- ->get (SkipStaticColumnsProvider::class);
539
- $ this ->skipStaticColumns = $ provider ->get ();
533
+ if ($ this ->skipStaticColumns === []) {
534
+ $ this ->skipStaticColumns = $ this ->skipStaticColumnsProvider ->get ();
540
535
}
541
536
return $ this ->skipStaticColumns ;
542
537
}
0 commit comments