55 */
66namespace Magento \ImportExport \Model \Import ;
77
8+ use Magento \Framework \App \Config \ScopeConfigInterface ;
89use Magento \Framework \App \ObjectManager ;
910use Magento \Framework \App \ResourceConnection ;
11+ use Magento \Framework \DB \Adapter \AdapterInterface ;
1012use Magento \Framework \Serialize \Serializer \Json ;
13+ use Magento \Framework \Stdlib \StringUtils ;
1114use Magento \ImportExport \Model \Import ;
1215use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingError ;
1316use 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 ;
1420
1521/**
1622 * Import entity abstract model
1723 *
1824 * phpcs:disable Magento2.Classes.AbstractApi
1925 * @api
20- *
2126 * @SuppressWarnings(PHPMD.TooManyFields)
2227 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2328 * @since 100.0.2
@@ -34,20 +39,24 @@ abstract class AbstractEntity
3439 */
3540 const COLUMN_ACTION_VALUE_DELETE = 'delete ' ;
3641
37- /**#@+
38- * XML paths to parameters
42+ /**
43+ * Path to bunch size configuration
3944 */
4045 const XML_PATH_BUNCH_SIZE = 'import/format_v2/bunch_size ' ;
4146
47+ /**
48+ * Path to page size configuration
49+ */
4250 const XML_PATH_PAGE_SIZE = 'import/format_v2/page_size ' ;
4351
44- /**#@-*/
45-
46- /**#@+
47- * Database constants
52+ /**
53+ * Size of varchar value
4854 */
4955 const DB_MAX_VARCHAR_LENGTH = 256 ;
5056
57+ /**
58+ * Size of text value
59+ */
5160 const DB_MAX_TEXT_LENGTH = 65536 ;
5261
5362 const ERROR_CODE_SYSTEM_EXCEPTION = 'systemException ' ;
@@ -84,9 +93,9 @@ abstract class AbstractEntity
8493 . ", see acceptable values on settings specified for Admin " ,
8594 ];
8695
87- /**#@-*/
88-
89- /**#@- */
96+ /**
97+ * @var AdapterInterface
98+ */
9099 protected $ _connection ;
91100
92101 /**
@@ -97,9 +106,7 @@ abstract class AbstractEntity
97106 protected $ _dataValidated = false ;
98107
99108 /**
100- * Valid column names
101- *
102- * @array
109+ * @var array
103110 */
104111 protected $ validColumnNames = [];
105112
@@ -132,7 +139,7 @@ abstract class AbstractEntity
132139 /**
133140 * Magento string lib
134141 *
135- * @var \Magento\Framework\Stdlib\ StringUtils
142+ * @var StringUtils
136143 */
137144 protected $ string ;
138145
@@ -252,7 +259,7 @@ abstract class AbstractEntity
252259 /**
253260 * Core store config
254261 *
255- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
262+ * @var ScopeConfigInterface
256263 */
257264 protected $ _scopeConfig ;
258265
@@ -285,54 +292,45 @@ abstract class AbstractEntity
285292 private $ serializer ;
286293
287294 /**
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
293300 * @param ProcessingErrorAggregatorInterface $errorAggregator
294301 * @param array $data
302+ * @param Json|null $serializer
295303 * @SuppressWarnings(PHPMD.NPathComplexity)
296304 */
297305 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 ,
302310 ResourceConnection $ resource ,
303311 ProcessingErrorAggregatorInterface $ errorAggregator ,
304- array $ data = []
312+ array $ data = [],
313+ Json $ serializer = null
305314 ) {
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 ();
314315 $ 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 (
318322 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 (
327326 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 );
332329
333330 foreach ($ this ->errorMessageTemplates as $ errorCode => $ message ) {
334331 $ this ->getErrorAggregator ()->addErrorMessageTemplate ($ errorCode , $ message );
335332 }
333+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
336334 }
337335
338336 /**
@@ -462,7 +460,7 @@ protected function _saveValidatedBunches()
462460 foreach ($ entityGroup as $ key => $ value ) {
463461 $ bunchRows [$ key ] = $ value ;
464462 }
465- $ productDataSize = strlen ($ this ->getSerializer () ->serialize ($ bunchRows ));
463+ $ productDataSize = strlen ($ this ->serializer ->serialize ($ bunchRows ));
466464
467465 /* Check if the new bunch should be started */
468466 $ isBunchSizeExceeded = ($ this ->_bunchSize > 0 && count ($ bunchRows ) >= $ this ->_bunchSize );
@@ -473,7 +471,7 @@ protected function _saveValidatedBunches()
473471 $ entityGroup = [];
474472 }
475473
476- if (isset ($ entityGroup ) && $ this ->validateRow ($ rowData , $ source ->key ())) {
474+ if (isset ($ entityGroup ) && isset ( $ rowData ) && $ this ->validateRow ($ rowData , $ source ->key ())) {
477475 /* Add row to entity group */
478476 $ entityGroup [$ source ->key ()] = $ this ->_prepareRowForDb ($ rowData );
479477 } elseif (isset ($ entityGroup )) {
@@ -488,22 +486,6 @@ protected function _saveValidatedBunches()
488486 return $ this ;
489487 }
490488
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-
507489 /**
508490 * Add error with corresponding current data source row number.
509491 *
@@ -553,7 +535,7 @@ public function addMessageTemplate($errorCode, $message)
553535 /**
554536 * Import behavior getter
555537 *
556- * @param array $rowData
538+ * @param array|null $rowData
557539 * @return string
558540 */
559541 public function getBehavior (array $ rowData = null )
@@ -569,7 +551,9 @@ public function getBehavior(array $rowData = null)
569551 if ($ rowData !== null && $ behavior == \Magento \ImportExport \Model \Import::BEHAVIOR_CUSTOM ) {
570552 // try analyze value in self::COLUMN_CUSTOM column and return behavior for given $rowData
571553 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+ ) {
573557 $ behavior = \Magento \ImportExport \Model \Import::BEHAVIOR_DELETE ;
574558 } else {
575559 // as per task description, if column value is different to self::COLUMN_CUSTOM_VALUE_DELETE,
0 commit comments