-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7748 from magento-performance/ACPT-6
ACPT-6: Improve Data Import Performance
- Loading branch information
Showing
11 changed files
with
360 additions
and
125,841 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/code/Magento/ImportExport/Model/Import/Source/Base64EncodedCsvData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ImportExport\Model\Import\Source; | ||
|
||
use Magento\ImportExport\Model\Import\AbstractSource; | ||
|
||
class Base64EncodedCsvData extends AbstractSource | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $rows; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $delimiter = ','; | ||
|
||
/** | ||
* Read Data and detect column names | ||
* | ||
* @param string $file | ||
*/ | ||
public function __construct(string $file) | ||
{ | ||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
$source = trim(base64_decode($file)); | ||
$rowsData = preg_split("/\r\n|\n|\r/", $source); | ||
$colNames = explode($this->delimiter, $rowsData[0]); | ||
$this->rows = array_splice($rowsData, 1); | ||
parent::__construct($colNames); | ||
} | ||
|
||
/** | ||
* Read next line from CSV data | ||
* | ||
* @return array | ||
*/ | ||
public function _getNextRow() | ||
{ | ||
if ($this->_key===count($this->rows)) { | ||
return []; | ||
} | ||
$parsed =str_getcsv($this->rows[$this->_key], ',', '"'); | ||
if (is_array($parsed) && count($parsed) != $this->_colQty) { | ||
foreach ($parsed as $element) { | ||
if ($element && strpos($element, "'") !== false) { | ||
$this->_foundWrongQuoteFlag = true; | ||
break; | ||
} | ||
} | ||
} else { | ||
$this->_foundWrongQuoteFlag = false; | ||
} | ||
return is_array($parsed) ? $parsed : []; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/code/Magento/ImportExport/Model/Import/Source/Factory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\ImportExport\Model\Import\Source; | ||
|
||
use Magento\Framework\Filesystem\Directory\Write; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\ImportExport\Model\Import\AbstractSource; | ||
|
||
class Factory | ||
{ | ||
/** | ||
* Object Manager Instance | ||
* | ||
* @var \Magento\Framework\ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @param ObjectManagerInterface $objectManager | ||
*/ | ||
public function __construct( | ||
ObjectManagerInterface $objectManager | ||
) { | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* Create class instance with specified parameters | ||
* | ||
* @param string $source | ||
* @param Write $directory | ||
* @param mixed $options | ||
* @return AbstractSource | ||
* @phpcs:disable Magento2.Functions.DiscouragedFunction | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function create($source, $directory = null, $options = null): AbstractSource | ||
{ | ||
$adapterClass = 'Magento\ImportExport\Model\Import\Source\\'; | ||
if (file_exists($source)) { | ||
$type = ucfirst(strtolower(pathinfo($source, PATHINFO_EXTENSION))); | ||
} else { | ||
$type = 'Base64EncodedCsvData'; | ||
} | ||
if (!is_string($source) || !$source) { | ||
throw new \Magento\Framework\Exception\LocalizedException( | ||
__('The source type must be a non-empty string.') | ||
); | ||
} | ||
$adapterClass.= $type; | ||
if (!class_exists($adapterClass)) { | ||
throw new \Magento\Framework\Exception\LocalizedException( | ||
__('\'%1\' file extension is not supported', $type) | ||
); | ||
} | ||
return $this->objectManager->create( | ||
$adapterClass, | ||
[ | ||
'file' => $source, | ||
'directory' => $directory, | ||
'options' => $options | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.