5
5
*/
6
6
namespace Magento \ImportExport \Model \Import ;
7
7
8
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
8
9
use Magento \Framework \App \ObjectManager ;
9
10
use Magento \Framework \App \ResourceConnection ;
11
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
10
12
use Magento \Framework \Serialize \Serializer \Json ;
13
+ use Magento \Framework \Stdlib \StringUtils ;
11
14
use Magento \ImportExport \Model \Import ;
12
15
use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingError ;
13
16
use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingErrorAggregatorInterface ;
17
+ use Magento \ImportExport \Model \ImportFactory ;
18
+ use Magento \ImportExport \Model \ResourceModel \Helper ;
19
+ use Magento \Store \Model \ScopeInterface ;
14
20
15
21
/**
16
22
* Import entity abstract model
17
23
*
18
24
* phpcs:disable Magento2.Classes.AbstractApi
19
25
* @api
20
- *
21
26
* @SuppressWarnings(PHPMD.TooManyFields)
22
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23
28
* @since 100.0.2
@@ -34,20 +39,24 @@ abstract class AbstractEntity
34
39
*/
35
40
const COLUMN_ACTION_VALUE_DELETE = 'delete ' ;
36
41
37
- /**#@+
38
- * XML paths to parameters
42
+ /**
43
+ * Path to bunch size configuration
39
44
*/
40
45
const XML_PATH_BUNCH_SIZE = 'import/format_v2/bunch_size ' ;
41
46
47
+ /**
48
+ * Path to page size configuration
49
+ */
42
50
const XML_PATH_PAGE_SIZE = 'import/format_v2/page_size ' ;
43
51
44
- /**#@-*/
45
-
46
- /**#@+
47
- * Database constants
52
+ /**
53
+ * Size of varchar value
48
54
*/
49
55
const DB_MAX_VARCHAR_LENGTH = 256 ;
50
56
57
+ /**
58
+ * Size of text value
59
+ */
51
60
const DB_MAX_TEXT_LENGTH = 65536 ;
52
61
53
62
const ERROR_CODE_SYSTEM_EXCEPTION = 'systemException ' ;
@@ -84,9 +93,9 @@ abstract class AbstractEntity
84
93
. ", see acceptable values on settings specified for Admin " ,
85
94
];
86
95
87
- /**#@-*/
88
-
89
- /**#@- */
96
+ /**
97
+ * @var AdapterInterface
98
+ */
90
99
protected $ _connection ;
91
100
92
101
/**
@@ -97,9 +106,7 @@ abstract class AbstractEntity
97
106
protected $ _dataValidated = false ;
98
107
99
108
/**
100
- * Valid column names
101
- *
102
- * @array
109
+ * @var array
103
110
*/
104
111
protected $ validColumnNames = [];
105
112
@@ -132,7 +139,7 @@ abstract class AbstractEntity
132
139
/**
133
140
* Magento string lib
134
141
*
135
- * @var \Magento\Framework\Stdlib\ StringUtils
142
+ * @var StringUtils
136
143
*/
137
144
protected $ string ;
138
145
@@ -252,7 +259,7 @@ abstract class AbstractEntity
252
259
/**
253
260
* Core store config
254
261
*
255
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
262
+ * @var ScopeConfigInterface
256
263
*/
257
264
protected $ _scopeConfig ;
258
265
@@ -285,54 +292,45 @@ abstract class AbstractEntity
285
292
private $ serializer ;
286
293
287
294
/**
288
- * @param \Magento\Framework\Stdlib\ StringUtils $string
289
- * @param \Magento\Framework\App\Config\ ScopeConfigInterface $scopeConfig
290
- * @param \Magento\ImportExport\Model\ ImportFactory $importFactory
291
- * @param \Magento\ImportExport\Model\ResourceModel\ Helper $resourceHelper
292
- * @param \Magento\Framework\App\ ResourceConnection $resource
295
+ * @param StringUtils $string
296
+ * @param ScopeConfigInterface $scopeConfig
297
+ * @param ImportFactory $importFactory
298
+ * @param Helper $resourceHelper
299
+ * @param ResourceConnection $resource
293
300
* @param ProcessingErrorAggregatorInterface $errorAggregator
294
301
* @param array $data
302
+ * @param Json|null $serializer
295
303
* @SuppressWarnings(PHPMD.NPathComplexity)
296
304
*/
297
305
public function __construct (
298
- \ Magento \ Framework \ Stdlib \ StringUtils $ string ,
299
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
300
- \ Magento \ ImportExport \ Model \ ImportFactory $ importFactory ,
301
- \ Magento \ ImportExport \ Model \ ResourceModel \ Helper $ resourceHelper ,
306
+ StringUtils $ string ,
307
+ ScopeConfigInterface $ scopeConfig ,
308
+ ImportFactory $ importFactory ,
309
+ Helper $ resourceHelper ,
302
310
ResourceConnection $ resource ,
303
311
ProcessingErrorAggregatorInterface $ errorAggregator ,
304
- array $ data = []
312
+ array $ data = [],
313
+ Json $ serializer = null
305
314
) {
306
- $ this ->_scopeConfig = $ scopeConfig ;
307
- $ this ->_dataSourceModel = isset (
308
- $ data ['data_source_model ' ]
309
- ) ? $ data ['data_source_model ' ] : $ importFactory ->create ()->getDataSourceModel ();
310
- $ this ->_connection =
311
- isset ($ data ['connection ' ]) ?
312
- $ data ['connection ' ] :
313
- $ resource ->getConnection ();
314
315
$ this ->string = $ string ;
315
- $ this ->_pageSize = isset (
316
- $ data ['page_size ' ]
317
- ) ? $ data ['page_size ' ] : (static ::XML_PATH_PAGE_SIZE ? (int )$ this ->_scopeConfig ->getValue (
316
+ $ this ->_scopeConfig = $ scopeConfig ;
317
+ $ this ->_dataSourceModel = $ data ['data_source_model ' ] ?? $ importFactory ->create ()->getDataSourceModel ();
318
+ $ this ->_maxDataSize = $ data ['max_data_size ' ] ?? $ resourceHelper ->getMaxDataSize ();
319
+ $ this ->_connection = $ data ['connection ' ] ?? $ resource ->getConnection ();
320
+ $ this ->errorAggregator = $ errorAggregator ;
321
+ $ this ->_pageSize = $ data ['page_size ' ] ?? ((int ) $ this ->_scopeConfig ->getValue (
318
322
static ::XML_PATH_PAGE_SIZE ,
319
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
320
- ) : 0 );
321
- $ this ->_maxDataSize = isset (
322
- $ data ['max_data_size ' ]
323
- ) ? $ data ['max_data_size ' ] : $ resourceHelper ->getMaxDataSize ();
324
- $ this ->_bunchSize = isset (
325
- $ data ['bunch_size ' ]
326
- ) ? $ data ['bunch_size ' ] : (static ::XML_PATH_BUNCH_SIZE ? (int )$ this ->_scopeConfig ->getValue (
323
+ ScopeInterface::SCOPE_STORE
324
+ ) ?: 0 );
325
+ $ this ->_bunchSize = $ data ['bunch_size ' ] ?? ((int ) $ this ->_scopeConfig ->getValue (
327
326
static ::XML_PATH_BUNCH_SIZE ,
328
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
329
- ) : 0 );
330
-
331
- $ this ->errorAggregator = $ errorAggregator ;
327
+ ScopeInterface::SCOPE_STORE
328
+ ) ?: 0 );
332
329
333
330
foreach ($ this ->errorMessageTemplates as $ errorCode => $ message ) {
334
331
$ this ->getErrorAggregator ()->addErrorMessageTemplate ($ errorCode , $ message );
335
332
}
333
+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
336
334
}
337
335
338
336
/**
@@ -462,7 +460,7 @@ protected function _saveValidatedBunches()
462
460
foreach ($ entityGroup as $ key => $ value ) {
463
461
$ bunchRows [$ key ] = $ value ;
464
462
}
465
- $ productDataSize = strlen ($ this ->getSerializer () ->serialize ($ bunchRows ));
463
+ $ productDataSize = strlen ($ this ->serializer ->serialize ($ bunchRows ));
466
464
467
465
/* Check if the new bunch should be started */
468
466
$ isBunchSizeExceeded = ($ this ->_bunchSize > 0 && count ($ bunchRows ) >= $ this ->_bunchSize );
@@ -473,7 +471,7 @@ protected function _saveValidatedBunches()
473
471
$ entityGroup = [];
474
472
}
475
473
476
- if (isset ($ entityGroup ) && $ this ->validateRow ($ rowData , $ source ->key ())) {
474
+ if (isset ($ entityGroup ) && isset ( $ rowData ) && $ this ->validateRow ($ rowData , $ source ->key ())) {
477
475
/* Add row to entity group */
478
476
$ entityGroup [$ source ->key ()] = $ this ->_prepareRowForDb ($ rowData );
479
477
} elseif (isset ($ entityGroup )) {
@@ -488,22 +486,6 @@ protected function _saveValidatedBunches()
488
486
return $ this ;
489
487
}
490
488
491
- /**
492
- * Get Serializer instance
493
- *
494
- * Workaround. Only way to implement dependency and not to break inherited child classes
495
- *
496
- * @return Json
497
- * @deprecated 100.2.0
498
- */
499
- private function getSerializer ()
500
- {
501
- if (null === $ this ->serializer ) {
502
- $ this ->serializer = ObjectManager::getInstance ()->get (Json::class);
503
- }
504
- return $ this ->serializer ;
505
- }
506
-
507
489
/**
508
490
* Add error with corresponding current data source row number.
509
491
*
@@ -553,7 +535,7 @@ public function addMessageTemplate($errorCode, $message)
553
535
/**
554
536
* Import behavior getter
555
537
*
556
- * @param array $rowData
538
+ * @param array|null $rowData
557
539
* @return string
558
540
*/
559
541
public function getBehavior (array $ rowData = null )
@@ -569,7 +551,9 @@ public function getBehavior(array $rowData = null)
569
551
if ($ rowData !== null && $ behavior == \Magento \ImportExport \Model \Import::BEHAVIOR_CUSTOM ) {
570
552
// try analyze value in self::COLUMN_CUSTOM column and return behavior for given $rowData
571
553
if (array_key_exists (self ::COLUMN_ACTION , $ rowData )) {
572
- if (strtolower ($ rowData [self ::COLUMN_ACTION ]) == self ::COLUMN_ACTION_VALUE_DELETE ) {
554
+ if ($ rowData [self ::COLUMN_ACTION ]
555
+ && strtolower ($ rowData [self ::COLUMN_ACTION ]) == self ::COLUMN_ACTION_VALUE_DELETE
556
+ ) {
573
557
$ behavior = \Magento \ImportExport \Model \Import::BEHAVIOR_DELETE ;
574
558
} else {
575
559
// as per task description, if column value is different to self::COLUMN_CUSTOM_VALUE_DELETE,
0 commit comments