Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4705e23

Browse files
[2.3-develop] Forwardport of magento/magento2#12257
1 parent c7207f6 commit 4705e23

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1314
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
1415
use Magento\Framework\Stdlib\DateTime;
@@ -714,7 +715,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
714715
* @param \Magento\CatalogInventory\Model\Spi\StockStateProviderInterface $stockStateProvider
715716
* @param \Magento\Catalog\Helper\Data $catalogData
716717
* @param \Magento\ImportExport\Model\Import\Config $importConfig
717-
* @param Proxy\Product\ResourceFactory $resourceFactory
718+
* @param Proxy\Product\ResourceModelFactory $resourceFactory
718719
* @param Product\OptionFactory $optionFactory
719720
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setColFactory
720721
* @param Product\Type\Factory $productTypeFactory
@@ -1089,12 +1090,12 @@ protected function _initTypeModels()
10891090
$params = [$this, $productTypeName];
10901091
if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], ['params' => $params]))
10911092
) {
1092-
throw new \Magento\Framework\Exception\LocalizedException(
1093+
throw new LocalizedException(
10931094
__('Entity type model \'%1\' is not found', $productTypeConfig['model'])
10941095
);
10951096
}
10961097
if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
1097-
throw new \Magento\Framework\Exception\LocalizedException(
1098+
throw new LocalizedException(
10981099
__(
10991100
'Entity type model must be an instance of '
11001101
. \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType::class
@@ -1561,6 +1562,7 @@ public function getImagesFromRow(array $rowData)
15611562
* @SuppressWarnings(PHPMD.NPathComplexity)
15621563
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
15631564
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
1565+
* @throws LocalizedException
15641566
*/
15651567
protected function _saveProducts()
15661568
{
@@ -1621,7 +1623,7 @@ protected function _saveProducts()
16211623

16221624
// wrong attribute_set_code was received
16231625
if (!$attributeSetId) {
1624-
throw new \Magento\Framework\Exception\LocalizedException(
1626+
throw new LocalizedException(
16251627
__(
16261628
'Wrong attribute set code "%1", please correct it and try again.',
16271629
$rowData['attribute_set_code']
@@ -1826,7 +1828,7 @@ protected function _saveProducts()
18261828
) {
18271829
$attrValue = $this->dateTime->formatDate($attrValue, false);
18281830
} elseif ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1829-
$attrValue = $this->dateTime->gmDate(
1831+
$attrValue = gmdate(
18301832
'Y-m-d H:i:s',
18311833
$this->_localeDate->date($attrValue)->getTimestamp()
18321834
);
@@ -2008,7 +2010,7 @@ protected function _getUploader()
20082010
}
20092011

20102012
if (!$this->_fileUploader->setTmpDir($tmpPath)) {
2011-
throw new \Magento\Framework\Exception\LocalizedException(
2013+
throw new LocalizedException(
20122014
__('File directory \'%1\' is not readable.', $tmpPath)
20132015
);
20142016
}
@@ -2017,7 +2019,7 @@ protected function _getUploader()
20172019

20182020
$this->_mediaDirectory->create($destinationPath);
20192021
if (!$this->_fileUploader->setDestDir($destinationPath)) {
2020-
throw new \Magento\Framework\Exception\LocalizedException(
2022+
throw new LocalizedException(
20212023
__('File directory \'%1\' is not writable.', $destinationPath)
20222024
);
20232025
}
@@ -2039,6 +2041,8 @@ public function getUploader()
20392041
* Return a new file name if the same file is already exists.
20402042
*
20412043
* @param string $fileName
2044+
* @param bool $renameFileOff [optional] boolean to pass.
2045+
* Default is false which will set not to rename the file after import.
20422046
* @return string
20432047
*/
20442048
protected function uploadMediaFiles($fileName, $renameFileOff = false)
@@ -2247,7 +2251,7 @@ protected function _saveStockItem()
22472251
$stockItemDo->setData($row);
22482252
$row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo);
22492253
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
2250-
$row['low_stock_date'] = $this->dateTime->gmDate(
2254+
$row['low_stock_date'] = gmdate(
22512255
'Y-m-d H:i:s',
22522256
(new \DateTime())->getTimestamp()
22532257
);
@@ -2763,7 +2767,7 @@ private function _customFieldsMapping($rowData)
27632767
/**
27642768
* Validate data rows and save bunches to DB
27652769
*
2766-
* @return $this
2770+
* @return $this|AbstractEntity
27672771
*/
27682772
protected function _saveValidatedBunches()
27692773
{

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Framework\Serialize\Serializer\Json;
1112
use Magento\ImportExport\Model\Import\AbstractSource;
1213
use Magento\ImportExport\Model\Import as ImportExport;
@@ -310,7 +311,7 @@ public function __construct(
310311
protected function _getSource()
311312
{
312313
if (!$this->_source) {
313-
throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a source.'));
314+
throw new LocalizedException(__('Please specify a source.'));
314315
}
315316
return $this->_source;
316317
}
@@ -378,7 +379,7 @@ protected function addErrors($code, $errors)
378379
/**
379380
* Validate data rows and save bunches to DB.
380381
*
381-
* @return $this|void
382+
* @return $this
382383
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
383384
*/
384385
protected function _saveValidatedBunches()
@@ -548,11 +549,11 @@ public function getBehavior()
548549
if (!isset(
549550
$this->_parameters['behavior']
550551
) ||
551-
$this->_parameters['behavior'] != \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND &&
552-
$this->_parameters['behavior'] != \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE &&
553-
$this->_parameters['behavior'] != \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE
552+
$this->_parameters['behavior'] != ImportExport::BEHAVIOR_APPEND &&
553+
$this->_parameters['behavior'] != ImportExport::BEHAVIOR_REPLACE &&
554+
$this->_parameters['behavior'] != ImportExport::BEHAVIOR_DELETE
554555
) {
555-
return \Magento\ImportExport\Model\Import::getDefaultBehavior();
556+
return ImportExport::getDefaultBehavior();
556557
}
557558
return $this->_parameters['behavior'];
558559
}
@@ -604,7 +605,7 @@ public function getProcessedRowsCount()
604605
public function getSource()
605606
{
606607
if (!$this->_source) {
607-
throw new \Magento\Framework\Exception\LocalizedException(__('The source is not set.'));
608+
throw new LocalizedException(__('The source is not set.'));
608609
}
609610
return $this->_source;
610611
}
@@ -879,7 +880,7 @@ public function getValidColumnNames()
879880
protected function getMetadataPool()
880881
{
881882
if (!$this->metadataPool) {
882-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
883+
$this->metadataPool = ObjectManager::getInstance()
883884
->get(\Magento\Framework\EntityManager\MetadataPool::class);
884885
}
885886
return $this->metadataPool;

0 commit comments

Comments
 (0)