Skip to content

Commit 0b26d9d

Browse files
committed
Merge branch 'MAGETWO-66066' of github.com:magento-troll/magento2ce into MAGETWO-65622
2 parents b6ae51d + 0f0b5e5 commit 0b26d9d

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

app/code/Magento/ImportExport/Model/Import/AbstractEntity.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
99
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
1010
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Serialize\Serializer\Json;
1113

1214
/**
1315
* Import entity abstract model
@@ -271,6 +273,13 @@ abstract class AbstractEntity
271273
*/
272274
protected $countItemsDeleted = 0;
273275

276+
/**
277+
* Json Serializer Instance
278+
*
279+
* @var Json
280+
*/
281+
private $serializer;
282+
274283
/**
275284
* @param \Magento\Framework\Stdlib\StringUtils $string
276285
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -447,7 +456,7 @@ protected function _saveValidatedBunches()
447456
foreach ($entityGroup as $key => $value) {
448457
$bunchRows[$key] = $value;
449458
}
450-
$productDataSize = strlen(serialize($bunchRows));
459+
$productDataSize = strlen($this->getSerializer()->serialize($bunchRows));
451460

452461
/* Check if the new bunch should be started */
453462
$isBunchSizeExceeded = ($this->_bunchSize > 0 && count($bunchRows) >= $this->_bunchSize);
@@ -473,6 +482,22 @@ protected function _saveValidatedBunches()
473482
return $this;
474483
}
475484

485+
/**
486+
* Get Serializer instance
487+
*
488+
* Workaround. Only way to implement dependency and not to break inherited child classes
489+
*
490+
* @return Json
491+
* @deprecated
492+
*/
493+
private function getSerializer()
494+
{
495+
if (null === $this->serializer) {
496+
$this->serializer = ObjectManager::getInstance()->get(Json::class);
497+
}
498+
return $this->serializer;
499+
}
500+
476501
/**
477502
* Add error with corresponding current data source row number.
478503
*

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\ImportExport\Model\Import as ImportExport;
1111
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1212
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\Serialize\Serializer\Json;
1315

1416
/**
1517
* Import entity abstract model
@@ -246,6 +248,13 @@ abstract class AbstractEntity
246248
*/
247249
protected $metadataPool;
248250

251+
/**
252+
* Json Serializer Instance
253+
*
254+
* @var Json
255+
*/
256+
private $serializer;
257+
249258
/**
250259
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
251260
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -382,7 +391,7 @@ protected function _saveValidatedBunches()
382391
$this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows);
383392

384393
$bunchRows = $nextRowBackup;
385-
$currentDataSize = strlen(serialize($bunchRows));
394+
$currentDataSize = strlen($this->getSerializer()->serialize($bunchRows));
386395
$startNewBunch = false;
387396
$nextRowBackup = [];
388397
}
@@ -419,6 +428,22 @@ protected function _saveValidatedBunches()
419428
return $this;
420429
}
421430

431+
/**
432+
* Get Serializer instance
433+
*
434+
* Workaround. Only way to implement dependency and not to break inherited child classes
435+
*
436+
* @return Json
437+
* @deprecated
438+
*/
439+
private function getSerializer()
440+
{
441+
if (null === $this->serializer) {
442+
$this->serializer = ObjectManager::getInstance()->get(Json::class);
443+
}
444+
return $this->serializer;
445+
}
446+
422447
/**
423448
* Add error with corresponding current data source row number.
424449
*

app/code/Magento/ImportExport/Test/Unit/Model/Import/EntityAbstractTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function _getModelDependencies()
7676
'max_data_size' => 1,
7777
'bunch_size' => 1,
7878
'collection_by_pages_iterator' => 'not_used',
79-
],
79+
]
8080
];
8181

8282
return $data;

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,4 +1616,28 @@ public function validateRowDataProvider()
16161616
],
16171617
];
16181618
}
1619+
1620+
/**
1621+
* @covers \Magento\ImportExport\Model\Import\Entity\AbstractEntity::_saveValidatedBunches
1622+
*/
1623+
public function testValidateData()
1624+
{
1625+
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
1626+
->create(\Magento\Framework\Filesystem::class);
1627+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1628+
1629+
$source = $this->objectManager->create(
1630+
\Magento\ImportExport\Model\Import\Source\Csv::class,
1631+
[
1632+
'file' => __DIR__ . '/_files/products_to_import.csv',
1633+
'directory' => $directory
1634+
]
1635+
);
1636+
1637+
$errors = $this->_model->setParameters(
1638+
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product']
1639+
)->setSource($source)->validateData();
1640+
1641+
$this->assertTrue($errors->getErrorsCount() == 0);
1642+
}
16191643
}

0 commit comments

Comments
 (0)