From ef8a1a861c0afa327f8607447bab1d925f2516f1 Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Mon, 4 Mar 2019 13:06:45 +0000 Subject: [PATCH 1/7] Introduce SourceTypePool and remove source_type declaration from SourceProcessorPool --- .../Processor/AbstractSourceProcessor.php | 50 ++++++ .../Processor/Base64EncodedDataProcessor.php | 64 +------ .../Processor/ExternalFileProcessor.php | 46 ++--- .../Processor/LocalPathFileProcessor.php | 164 ++---------------- .../Processor/SourceProcessorInterface.php | 3 - .../Model/Import/SourceProcessorPool.php | 11 +- .../Model/Import/SourceTypePool.php | 51 ++++++ .../ImportService/Model/Import/Type/Csv.php | 117 +++++++++++++ .../Model/Import/Type/SourceTypeInterface.php | 29 ++++ app/code/Magento/ImportService/etc/di.xml | 21 ++- 10 files changed, 307 insertions(+), 249 deletions(-) create mode 100644 app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php create mode 100644 app/code/Magento/ImportService/Model/Import/SourceTypePool.php create mode 100644 app/code/Magento/ImportService/Model/Import/Type/Csv.php create mode 100644 app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php diff --git a/app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php new file mode 100644 index 00000000000..5ac0fb9a92c --- /dev/null +++ b/app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php @@ -0,0 +1,50 @@ +sourceTypePool = $sourceTypePool; + } + + /** + * {@inheritdoc} + * + * @throws ImportServiceException + * @return SourceTypeInterface + */ + public function processUpload(SourceInterface $source, SourceUploadResponseInterface $response) + { + /** @var \Magento\ImportService\Model\Import\Type\SourceTypeInterface $sourceType */ + $sourceType = $this->sourceTypePool->getSourceType($source); + + /** save processed content get updated source object */ + $source = $sourceType->save($source); + + /** return response with details */ + return $response->setSource($source)->setSourceId($source->getSourceId())->setStatus($source->getStatus()); + } +} diff --git a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php index d97dcc758da..1784a5898b0 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php @@ -9,79 +9,31 @@ use Magento\Framework\Filesystem; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\ImportService\Exception as ImportServiceException; +use Magento\ImportService\Api\Data\SourceInterface; +use Magento\ImportService\Api\Data\SourceUploadResponseInterface; /** * Base64 encoded data processor for asynchronous import */ -class Base64EncodedDataProcessor implements SourceProcessorInterface +class Base64EncodedDataProcessor extends AbstractSourceProcessor { /** * Import Type */ const IMPORT_TYPE = 'base64_encoded_data'; - /** - * CSV Source Type - */ - const SOURCE_TYPE_CSV = 'csv'; - - /** - * The destination directory - */ - const DIR_IMPORT_DESTINATION = 'import/'; - - /** - * @var \Magento\Framework\Filesystem - */ - private $filesystem; - - /** - * LocalPathFileProcessor constructor. - * @param Filesystem $filesystem - */ - public function __construct( - Filesystem $filesystem - ) { - $this->filesystem = $filesystem; - } - /** * {@inheritdoc} */ - public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $source, \Magento\ImportService\Api\Data\SourceUploadResponseInterface $response) + public function processUpload(SourceInterface $source, SourceUploadResponseInterface $response) { - /** @var string $fileName */ - $fileName = rand(); - - /** @var string $contentFilePath */ - $contentFilePath = self::DIR_IMPORT_DESTINATION - . $fileName - . '.' - . $source->getSourceType(); - /** @var string $content */ $content = base64_decode($source->getImportData()); - /** @var Magento\Framework\Filesystem\Directory\Write $var */ - $var = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - - if(!$var->writeFile($contentFilePath, $content)) - { - /** @var array $lastError */ - $lastError = error_get_last(); - - /** @var string $errorMessage */ - $errorMessage = isset($lastError['message']) ? $lastError['message'] : ''; - - throw new ImportServiceException( - __('Cannot copy the remote file: %1', $errorMessage) - ); - } - - /** Update source's import data */ - $source->setImportData($fileName); + /** Set decoded imported data */ + $source->setImportData($content); - return $response->setSource($source)->setSourceId($fileName)->setStatus($response::STATUS_UPLOADED); + /** process source and get response details */ + return parent::processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php index 43b4938cd7d..2fa55fb68c9 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php @@ -7,17 +7,25 @@ namespace Magento\ImportService\Model\Import\Processor; +use Magento\Framework\Filesystem\Io\File; +use Magento\ImportService\Api\Data\SourceInterface; +use Magento\ImportService\Api\Data\SourceUploadResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; -use Magento\ImportService\Exception as ImportServiceException; -use Magento\ImportService\Model\Import\SourceProcessorPool; +use Magento\ImportService\Model\Import\SourceTypePool; use Magento\ImportService\Model\Source\Validator; +use Magento\ImportService\ImportServiceException; /** * CSV files processor for asynchronous import */ -class ExternalFileProcessor implements SourceProcessorInterface +class ExternalFileProcessor extends AbstractSourceProcessor { + /** + * Import Type + */ + const IMPORT_TYPE = 'external'; + /** * @var \Magento\Framework\Filesystem */ @@ -31,15 +39,18 @@ class ExternalFileProcessor implements SourceProcessorInterface /** * LocalPathFileProcessor constructor * - * @param FileSystem $fileSystem + * @param Filesystem $fileSystem * @param Validator $validator + * @param SourceTypePool $sourceTypePool */ public function __construct( - FileSystem $fileSystem, - Validator $validator + Filesystem $fileSystem, + Validator $validator, + SourceTypePool $sourceTypePool ) { $this->fileSystem = $fileSystem; $this->validator = $validator; + parent::__construct($sourceTypePool); } /** @@ -68,25 +79,16 @@ public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $s ); } - /** @var string $workingDirectory */ - $workingDirectory = SourceProcessorPool::WORKING_DIR; - - /** @var string $fileName */ - $fileName = uniqid() . '.' . $source->getSourceType(); - /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $writeInterface */ - $writeInterface = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR); - - /** If the directory is not present, it will be created */ - $writeInterface->create($workingDirectory); + $writeInterface = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT); - /** @var string $copyFileFullPath*/ - $copyFileFullPath = $writeInterface->getAbsolutePath($workingDirectory) . $fileName; + /** read content from external link */ + $content = $writeInterface->getDriver()->fileGetContents($source->getImportData()); - /** Attempt a copy, may throw \Magento\Framework\Exception\FileSystemException */ - $writeInterface->getDriver()->copy($source->getImportData(), $copyFileFullPath); + /** Set downloaded data */ + $source->setImportData($content); - return $response->setSource($source->setImportData($fileName)) - ->setStatus($response::STATUS_UPLOADED); + /** process source and get response details */ + return parent::processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php index e178d81fa15..13beffffc06 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php @@ -7,38 +7,23 @@ namespace Magento\ImportService\Model\Import\Processor; -use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Filesystem\Io\File; use Magento\ImportService\Api\Data\SourceInterface; use Magento\ImportService\Api\Data\SourceUploadResponseInterface; -use Magento\Framework\Filesystem\Directory\WriteInterface; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem; -use Magento\ImportService\Api\SourceRepositoryInterface; -use Magento\ImportService\ImportServiceException; -use Magento\ImportService\Model\Import\SourceTypesValidatorInterface; +use Magento\ImportService\Model\Import\SourceTypePool; /** * CSV files processor for asynchronous import */ -class LocalPathFileProcessor implements SourceProcessorInterface +class LocalPathFileProcessor extends AbstractSourceProcessor { /** * Import Type */ const IMPORT_TYPE = 'local_path'; - /** - * CSV Source Type - */ - const SOURCE_TYPE_CSV = 'csv'; - - /** - * @var SourceTypesValidatorInterface - */ - private $sourceTypesValidator; - /** * @var File */ @@ -49,158 +34,41 @@ class LocalPathFileProcessor implements SourceProcessorInterface */ private $fileSystem; - /** - * @var WriteInterface - */ - private $directoryWrite; - - /** - * @var SourceRepositoryInterface - */ - private $sourceRepository; - - /** - * @var string - */ - private $newFileName; - - /** - * @var SourceInterface - */ - private $source; - /** * LocalPathFileProcessor constructor * * @param File $fileSystemIo * @param Filesystem $fileSystem - * @param SourceTypesValidatorInterface $sourceTypesValidator - * @param SourceRepositoryInterface $sourceRepository + * @param SourceTypePool $sourceTypePool */ public function __construct( File $fileSystemIo, Filesystem $fileSystem, - SourceTypesValidatorInterface $sourceTypesValidator, - SourceRepositoryInterface $sourceRepository + SourceTypePool $sourceTypePool ) { $this->fileSystemIo = $fileSystemIo; - $this->sourceTypesValidator = $sourceTypesValidator; $this->fileSystem = $fileSystem; - $this->sourceRepository = $sourceRepository; + parent::__construct($sourceTypePool); } /** - * Uploads process - * - * @inheritdoc - * @throws FileSystemException - * @throws ImportServiceException + * {@inheritdoc} */ public function processUpload(SourceInterface $source, SourceUploadResponseInterface $response) { - $this->source = $source; - try { - $this->validateSource(); - $this->saveFile(); - $source = $this->saveSource(); - $response->setStatus($source->getStatus()); - $response->setSourceId($source->getSourceId()); - } catch (CouldNotSaveException $e) { - $this->removeFile($source->getImportData()); - throw new ImportServiceException(__($e->getMessage())); - } + /** @var \Magento\Framework\Filesystem\Directory\Write $write */ + $write = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT); - return $response; - } + /** create absolute path */ + $absoluteSourcePath = $write->getAbsolutePath($source->getImportData()); - /** - * Saves source in DB - * - * @return SourceInterface - */ - private function saveSource() - { - $this->source->setImportData($this->getNewFileName()); - $this->source->setStatus(SourceInterface::STATUS_UPLOADED); + /** read content from system */ + $content = $this->fileSystemIo->read($absoluteSourcePath); - return $this->sourceRepository->save($this->source); - } + /** Set downloaded data */ + $source->setImportData($content); - /** - * Saves file at the storage - * - * @return string - * @throws FileSystemException - */ - private function saveFile() - { - $this->directoryWrite->copyFile( - $this->source->getImportData(), - $this->getNewFileName() - ); - - return $this->getNewFileName(); - } - - /** - * Generates new file name - * - * @return string - */ - private function getNewFileName() - { - if (!$this->newFileName) { - $this->newFileName = self::IMPORT_SOURCE_FILE_PATH . '/' - . uniqid() - . '.' . $this->source->getSourceType(); - } - - return $this->newFileName; - } - - /** - * Provides configured directoryWrite - * - * @return WriteInterface - * @throws FileSystemException - */ - private function getDirectoryWrite() - { - if (!$this->directoryWrite) { - $this->directoryWrite = $this->fileSystem - ->getDirectoryWrite(DirectoryList::ROOT); - } - - return $this->directoryWrite; - } - - /** - * Validates source - * - * @throws FileSystemException - * @throws ImportServiceException - */ - private function validateSource() - { - $absoluteSourcePath = $this->getDirectoryWrite() - ->getAbsolutePath($this->source->getImportData()); - if (!$this->fileSystemIo->read($absoluteSourcePath)) { - throw new ImportServiceException( - __("Cannot read from file system. File not existed or cannot be read") - ); - } - $this->sourceTypesValidator->execute($this->source); - } - - /** - * Removes source - * - * @param string $filename - * @return bool - * @throws FileSystemException - */ - private function removeFile($filename) - { - return $this->getDirectoryWrite()->delete($filename); + /** process source and get response details */ + return parent::processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/SourceProcessorInterface.php b/app/code/Magento/ImportService/Model/Import/Processor/SourceProcessorInterface.php index 5864feb6dfc..90f8a45700b 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/SourceProcessorInterface.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/SourceProcessorInterface.php @@ -17,9 +17,6 @@ */ interface SourceProcessorInterface { - // todo discuss the name of constant - const IMPORT_SOURCE_FILE_PATH = "var/import"; - /** * @param SourceInterface $source * @param SourceUploadResponseInterface $response diff --git a/app/code/Magento/ImportService/Model/Import/SourceProcessorPool.php b/app/code/Magento/ImportService/Model/Import/SourceProcessorPool.php index dcf844df019..a37edb70045 100644 --- a/app/code/Magento/ImportService/Model/Import/SourceProcessorPool.php +++ b/app/code/Magento/ImportService/Model/Import/SourceProcessorPool.php @@ -16,13 +16,6 @@ */ class SourceProcessorPool { - /** - * Working directory - * - * @var string - */ - const WORKING_DIR = 'importservice/'; - /** * @var array */ @@ -47,12 +40,12 @@ public function __construct($sourceProcessors = []) public function getProcessor(SourceInterface $source) { foreach ($this->sourceProcessors as $key => $processorInformation) { - if ($processorInformation['import_type'] === $source->getImportType() && in_array($source->getSourceType(), $processorInformation['source_type'])) { + if ($processorInformation['import_type'] === $source->getImportType()) { return $processorInformation['processor']; } } throw new ImportServiceException( - __('Specified Import type "%1" or Source type "%2" is wrong.', $source->getImportType(), $source->getSourceType()) + __('Specified Import type "%1" is wrong.', $source->getImportType()) ); } } diff --git a/app/code/Magento/ImportService/Model/Import/SourceTypePool.php b/app/code/Magento/ImportService/Model/Import/SourceTypePool.php new file mode 100644 index 00000000000..58396577fa7 --- /dev/null +++ b/app/code/Magento/ImportService/Model/Import/SourceTypePool.php @@ -0,0 +1,51 @@ +sourceTypes = $sourceTypes; + } + + /** + * {@inheritdoc} + * + * @throws ImportServiceException + * @return SourceTypeInterface + */ + public function getSourceType(SourceInterface $source) + { + foreach ($this->sourceTypes as $key => $sourceTypeInformation) { + if ($source->getSourceType() == $key) { + return $sourceTypeInformation['processor']; + } + } + throw new ImportServiceException( + __('Specified Source type "%1" is wrong.', $source->getSourceType()) + ); + } +} diff --git a/app/code/Magento/ImportService/Model/Import/Type/Csv.php b/app/code/Magento/ImportService/Model/Import/Type/Csv.php new file mode 100644 index 00000000000..02d9fff2d8a --- /dev/null +++ b/app/code/Magento/ImportService/Model/Import/Type/Csv.php @@ -0,0 +1,117 @@ +sourceRepository = $sourceRepository; + $this->filesystem = $filesystem; + } + + /** + * get file name with extension + * + * @return string + */ + private function getFileName() + { + if(is_null($this->fileName)) + { + $this->fileName = uniqid() + . '.' + . self::SOURCE_TYPE; + } + + return $this->fileName; + } + + /** + * save source content + * + * @param SourceInterface $source + * @throws ImportServiceException + * @return SourceInterface + */ + public function save(SourceInterface $source) + { + /** @var string $fileName */ + $fileName = $this->getFileName(); + + /** @var string $contentFilePath */ + $contentFilePath = SourceTypeInterface::IMPORT_SOURCE_FILE_PATH . $fileName; + + /** @var Magento\Framework\Filesystem\Directory\Write $var */ + $var = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + + if(!$var->writeFile($contentFilePath, $source->getImportData())) + { + /** @var array $lastError */ + $lastError = error_get_last(); + + /** @var string $errorMessage */ + $errorMessage = isset($lastError['message']) ? $lastError['message'] : ''; + + throw new ImportServiceException( + __('Cannot copy the remote file: %1', $errorMessage) + ); + } + + /** set updated data to source */ + $source->setImportData($fileName) + ->setStatus(SourceInterface::STATUS_UPLOADED); + + /** save processed source with status */ + $source = $this->sourceRepository->save($source); + + return $source; + } +} diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php new file mode 100644 index 00000000000..39741206445 --- /dev/null +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php @@ -0,0 +1,29 @@ + - + + + + + Magento\ImportService\Model\Import\Type\Csv + + + + Magento\ImportService\Model\Import\Processor\LocalPathFileProcessor\Proxy Magento\ImportService\Model\Import\Processor\LocalPathFileProcessor::IMPORT_TYPE - - Magento\ImportService\Model\Import\Processor\LocalPathFileProcessor::SOURCE_TYPE_CSV - Magento\ImportService\Model\Import\Processor\Base64EncodedDataProcessor\Proxy Magento\ImportService\Model\Import\Processor\Base64EncodedDataProcessor::IMPORT_TYPE - - Magento\ImportService\Model\Import\Processor\Base64EncodedDataProcessor::SOURCE_TYPE_CSV - Magento\ImportService\Model\Import\Processor\ExternalFileProcessor\Proxy - external - - Magento\ImportService\Model\Import\Processor\Base64EncodedDataProcessor::SOURCE_TYPE_CSV - + Magento\ImportService\Model\Import\Processor\ExternalFileProcessor::IMPORT_TYPE From b1e0c5b4a2c0e02f543fb8d6b3b81f9a38c000d3 Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Tue, 5 Mar 2019 07:50:15 +0000 Subject: [PATCH 2/7] Resolve Travis Error --- .../Model/Import/Processor/ExternalFileProcessor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php index 2fa55fb68c9..ed627422465 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php @@ -39,14 +39,14 @@ class ExternalFileProcessor extends AbstractSourceProcessor /** * LocalPathFileProcessor constructor * + * @param SourceTypePool $sourceTypePool * @param Filesystem $fileSystem * @param Validator $validator - * @param SourceTypePool $sourceTypePool */ public function __construct( + SourceTypePool $sourceTypePool, Filesystem $fileSystem, - Validator $validator, - SourceTypePool $sourceTypePool + Validator $validator ) { $this->fileSystem = $fileSystem; $this->validator = $validator; From 8c3efd4b7aa14c4157caa88d58d5bd497bb75a3e Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Tue, 5 Mar 2019 11:22:37 +0000 Subject: [PATCH 3/7] Changes based on comments --- .../Processor/Base64EncodedDataProcessor.php | 18 ++++++++- .../Processor/ExternalFileProcessor.php | 19 +++++---- .../Processor/LocalPathFileProcessor.php | 17 +++++--- ...ssor.php => PersistentSourceProcessor.php} | 2 +- .../Model/Import/SourceTypePool.php | 4 +- .../Import/Type/{Csv.php => SourceType.php} | 40 +++++++++++-------- app/code/Magento/ImportService/etc/di.xml | 10 +++-- 7 files changed, 72 insertions(+), 38 deletions(-) rename app/code/Magento/ImportService/Model/Import/Processor/{AbstractSourceProcessor.php => PersistentSourceProcessor.php} (94%) rename app/code/Magento/ImportService/Model/Import/Type/{Csv.php => SourceType.php} (80%) diff --git a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php index 1784a5898b0..18004663d9e 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php @@ -15,13 +15,27 @@ /** * Base64 encoded data processor for asynchronous import */ -class Base64EncodedDataProcessor extends AbstractSourceProcessor +class Base64EncodedDataProcessor implements SourceProcessorInterface { /** * Import Type */ const IMPORT_TYPE = 'base64_encoded_data'; + /** + * @var PersistentSourceProcessor + */ + protected $persistantUploader; + + /** + * @param PersistentSourceProcessor $persistantUploader + */ + public function __construct( + PersistentSourceProcessor $persistantUploader + ) { + $this->persistantUploader = $persistantUploader; + } + /** * {@inheritdoc} */ @@ -34,6 +48,6 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter $source->setImportData($content); /** process source and get response details */ - return parent::processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php index ed627422465..af165c31a76 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php @@ -19,7 +19,7 @@ /** * CSV files processor for asynchronous import */ -class ExternalFileProcessor extends AbstractSourceProcessor +class ExternalFileProcessor implements SourceProcessorInterface { /** * Import Type @@ -27,30 +27,35 @@ class ExternalFileProcessor extends AbstractSourceProcessor const IMPORT_TYPE = 'external'; /** - * @var \Magento\Framework\Filesystem + * @var PersistentSourceProcessor + */ + protected $persistantUploader; + + /** + * @var Filesystem */ private $fileSystem; /** - * @var \Magento\ImportService\Model\Source\Validator + * @var Validator */ private $validator; /** * LocalPathFileProcessor constructor * - * @param SourceTypePool $sourceTypePool + * @param PersistentSourceProcessor $persistantUploader * @param Filesystem $fileSystem * @param Validator $validator */ public function __construct( - SourceTypePool $sourceTypePool, + PersistentSourceProcessor $persistantUploader, Filesystem $fileSystem, Validator $validator ) { + $this->persistantUploader = $persistantUploader; $this->fileSystem = $fileSystem; $this->validator = $validator; - parent::__construct($sourceTypePool); } /** @@ -89,6 +94,6 @@ public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $s $source->setImportData($content); /** process source and get response details */ - return parent::processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php index 13beffffc06..4de5f6f088e 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php @@ -17,13 +17,18 @@ /** * CSV files processor for asynchronous import */ -class LocalPathFileProcessor extends AbstractSourceProcessor +class LocalPathFileProcessor implements SourceProcessorInterface { /** * Import Type */ const IMPORT_TYPE = 'local_path'; + /** + * @var PersistentSourceProcessor + */ + protected $persistantUploader; + /** * @var File */ @@ -37,18 +42,18 @@ class LocalPathFileProcessor extends AbstractSourceProcessor /** * LocalPathFileProcessor constructor * + * @param PersistentSourceProcessor $persistantUploader * @param File $fileSystemIo * @param Filesystem $fileSystem - * @param SourceTypePool $sourceTypePool */ public function __construct( + PersistentSourceProcessor $persistantUploader, File $fileSystemIo, - Filesystem $fileSystem, - SourceTypePool $sourceTypePool + Filesystem $fileSystem ) { + $this->persistantUploader = $persistantUploader; $this->fileSystemIo = $fileSystemIo; $this->fileSystem = $fileSystem; - parent::__construct($sourceTypePool); } /** @@ -69,6 +74,6 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter $source->setImportData($content); /** process source and get response details */ - return parent::processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php similarity index 94% rename from app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php rename to app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php index 5ac0fb9a92c..7831ae7ce32 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/AbstractSourceProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php @@ -14,7 +14,7 @@ /** * Define the source type pool and process the request */ -abstract class AbstractSourceProcessor implements SourceProcessorInterface +class PersistentSourceProcessor implements SourceProcessorInterface { /** * @var SourceTypePool diff --git a/app/code/Magento/ImportService/Model/Import/SourceTypePool.php b/app/code/Magento/ImportService/Model/Import/SourceTypePool.php index 58396577fa7..d99889fd28e 100644 --- a/app/code/Magento/ImportService/Model/Import/SourceTypePool.php +++ b/app/code/Magento/ImportService/Model/Import/SourceTypePool.php @@ -39,9 +39,9 @@ public function __construct($sourceTypes = []) */ public function getSourceType(SourceInterface $source) { - foreach ($this->sourceTypes as $key => $sourceTypeInformation) { + foreach ($this->sourceTypes as $key => $object) { if ($source->getSourceType() == $key) { - return $sourceTypeInformation['processor']; + return $object; } } throw new ImportServiceException( diff --git a/app/code/Magento/ImportService/Model/Import/Type/Csv.php b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php similarity index 80% rename from app/code/Magento/ImportService/Model/Import/Type/Csv.php rename to app/code/Magento/ImportService/Model/Import/Type/SourceType.php index 02d9fff2d8a..7d68088b7ed 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/Csv.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php @@ -14,61 +14,67 @@ use Magento\ImportService\Api\Data\SourceInterface; /** - * CSV Source Operations + * Generic Source Type */ -class Csv implements SourceTypeInterface +class SourceType implements SourceTypeInterface { /** - * Source Type + * @var SourceRepositoryInterface */ - const SOURCE_TYPE = 'csv'; + private $sourceRepository; /** - * Mime + * @var Filesystem */ - const MIME = 'text/csv'; + private $filesystem; /** - * @var SourceRepositoryInterface + * @var string */ - private $sourceRepository; + private $fileName; /** - * @var Filesystem + * @var string */ - private $filesystem; + private $sourceType; /** * @var string */ - private $fileName; + private $mime; /** * CSV File Type constructor. * * @param SourceRepositoryInterface $sourceRepository * @param Filesystem $filesystem + * @param string $sourceType + * @param string $mime */ public function __construct( SourceRepositoryInterface $sourceRepository, - Filesystem $filesystem + Filesystem $filesystem, + $sourceType = null, + $mime = null ) { $this->sourceRepository = $sourceRepository; $this->filesystem = $filesystem; + $this->sourceType = $sourceType; + $this->mime = $mime; } /** - * get file name with extension + * generate file name with source type * * @return string */ - private function getFileName() + private function generateFileName() { if(is_null($this->fileName)) { $this->fileName = uniqid() . '.' - . self::SOURCE_TYPE; + . $this->sourceType; } return $this->fileName; @@ -84,7 +90,7 @@ private function getFileName() public function save(SourceInterface $source) { /** @var string $fileName */ - $fileName = $this->getFileName(); + $fileName = $this->generateFileName(); /** @var string $contentFilePath */ $contentFilePath = SourceTypeInterface::IMPORT_SOURCE_FILE_PATH . $fileName; @@ -101,7 +107,7 @@ public function save(SourceInterface $source) $errorMessage = isset($lastError['message']) ? $lastError['message'] : ''; throw new ImportServiceException( - __('Cannot copy the remote file: %1', $errorMessage) + __('Cannot create file with given source: %1', $errorMessage) ); } diff --git a/app/code/Magento/ImportService/etc/di.xml b/app/code/Magento/ImportService/etc/di.xml index 8ac287bd10f..25960d54b2e 100644 --- a/app/code/Magento/ImportService/etc/di.xml +++ b/app/code/Magento/ImportService/etc/di.xml @@ -15,12 +15,16 @@ type="Magento\ImportService\Model\SourceUploadResponse" /> + + + csv + text/csv + + - - Magento\ImportService\Model\Import\Type\Csv - + Magento\ImportService\Model\Import\Type\Csv From b7c5d0fd6d83347cbe0d172c53d69a0503f6ce40 Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Wed, 6 Mar 2019 23:33:26 +0530 Subject: [PATCH 4/7] Change concept of generating file name --- .../ImportService/Model/Import/Type/SourceType.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php index 7d68088b7ed..2f7a53d00f2 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php @@ -28,11 +28,6 @@ class SourceType implements SourceTypeInterface */ private $filesystem; - /** - * @var string - */ - private $fileName; - /** * @var string */ @@ -70,14 +65,7 @@ public function __construct( */ private function generateFileName() { - if(is_null($this->fileName)) - { - $this->fileName = uniqid() - . '.' - . $this->sourceType; - } - - return $this->fileName; + return uniqid() . '.' . $this->sourceType; } /** From b81c21d876ad7b2d215bc0acb5d89c661926b0c6 Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Mon, 11 Mar 2019 10:42:47 +0000 Subject: [PATCH 5/7] Change the concept of providing processed content to persistant processor class --- .../Processor/Base64EncodedDataProcessor.php | 13 ++++---- .../Processor/ExternalFileProcessor.php | 13 ++++---- .../Processor/LocalPathFileProcessor.php | 13 ++++---- .../Processor/PersistentSourceProcessor.php | 30 +++++++++++++++++-- .../Model/Import/Type/SourceType.php | 8 ++--- .../Model/Import/Type/SourceTypeInterface.php | 3 +- 6 files changed, 49 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php index 18004663d9e..ff63aa0b9bf 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php @@ -25,15 +25,15 @@ class Base64EncodedDataProcessor implements SourceProcessorInterface /** * @var PersistentSourceProcessor */ - protected $persistantUploader; + private $persistantUploader; /** - * @param PersistentSourceProcessor $persistantUploader + * @param PersistentSourceProcessorFactory $persistantUploaderFactory */ public function __construct( - PersistentSourceProcessor $persistantUploader + PersistentSourceProcessorFactory $persistantUploaderFactory ) { - $this->persistantUploader = $persistantUploader; + $this->persistantUploader = $persistantUploaderFactory->create(); } /** @@ -44,10 +44,7 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter /** @var string $content */ $content = base64_decode($source->getImportData()); - /** Set decoded imported data */ - $source->setImportData($content); - /** process source and get response details */ - return $this->persistantUploader->processUpload($source, $response); + return $this->persistantUploader->setContent($content)->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php index af165c31a76..2a3191abf6d 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php @@ -29,7 +29,7 @@ class ExternalFileProcessor implements SourceProcessorInterface /** * @var PersistentSourceProcessor */ - protected $persistantUploader; + private $persistantUploader; /** * @var Filesystem @@ -44,16 +44,16 @@ class ExternalFileProcessor implements SourceProcessorInterface /** * LocalPathFileProcessor constructor * - * @param PersistentSourceProcessor $persistantUploader + * @param PersistentSourceProcessorFactory $persistantUploaderFactory * @param Filesystem $fileSystem * @param Validator $validator */ public function __construct( - PersistentSourceProcessor $persistantUploader, + PersistentSourceProcessorFactory $persistantUploaderFactory, Filesystem $fileSystem, Validator $validator ) { - $this->persistantUploader = $persistantUploader; + $this->persistantUploader = $persistantUploaderFactory->create(); $this->fileSystem = $fileSystem; $this->validator = $validator; } @@ -90,10 +90,7 @@ public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $s /** read content from external link */ $content = $writeInterface->getDriver()->fileGetContents($source->getImportData()); - /** Set downloaded data */ - $source->setImportData($content); - /** process source and get response details */ - return $this->persistantUploader->processUpload($source, $response); + return $this->persistantUploader->setContent($content)->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php index 4de5f6f088e..f003c1307ed 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php @@ -27,7 +27,7 @@ class LocalPathFileProcessor implements SourceProcessorInterface /** * @var PersistentSourceProcessor */ - protected $persistantUploader; + private $persistantUploader; /** * @var File @@ -42,16 +42,16 @@ class LocalPathFileProcessor implements SourceProcessorInterface /** * LocalPathFileProcessor constructor * - * @param PersistentSourceProcessor $persistantUploader + * @param PersistentSourceProcessorFactory $persistantUploaderFactory * @param File $fileSystemIo * @param Filesystem $fileSystem */ public function __construct( - PersistentSourceProcessor $persistantUploader, + PersistentSourceProcessorFactory $persistantUploaderFactory, File $fileSystemIo, Filesystem $fileSystem ) { - $this->persistantUploader = $persistantUploader; + $this->persistantUploader = $persistantUploaderFactory->create(); $this->fileSystemIo = $fileSystemIo; $this->fileSystem = $fileSystem; } @@ -70,10 +70,7 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter /** read content from system */ $content = $this->fileSystemIo->read($absoluteSourcePath); - /** Set downloaded data */ - $source->setImportData($content); - /** process source and get response details */ - return $this->persistantUploader->processUpload($source, $response); + return $this->persistantUploader->setContent($content)->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php index 7831ae7ce32..afa715b6988 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php @@ -10,6 +10,7 @@ use Magento\ImportService\Api\Data\SourceInterface; use Magento\ImportService\Api\Data\SourceUploadResponseInterface; use Magento\ImportService\Model\Import\SourceTypePool; +use Magento\ImportService\ImportServiceException; /** * Define the source type pool and process the request @@ -19,7 +20,12 @@ class PersistentSourceProcessor implements SourceProcessorInterface /** * @var SourceTypePool */ - protected $sourceTypePool; + private $sourceTypePool; + + /** + * @var string + */ + private $content; /** * @param SourceTypePool $sourceTypePool @@ -30,6 +36,18 @@ public function __construct( $this->sourceTypePool = $sourceTypePool; } + /** + * Set processed content to save the source request + * + * @param string $content + * @return $this + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + /** * {@inheritdoc} * @@ -38,11 +56,19 @@ public function __construct( */ public function processUpload(SourceInterface $source, SourceUploadResponseInterface $response) { + if(is_null($this->content)) + { + /** Throw error when content is null */ + throw new ImportServiceException( + __('Invalid content, unable to upload source data.') + ); + } + /** @var \Magento\ImportService\Model\Import\Type\SourceTypeInterface $sourceType */ $sourceType = $this->sourceTypePool->getSourceType($source); /** save processed content get updated source object */ - $source = $sourceType->save($source); + $source = $sourceType->save($source, $this->content); /** return response with details */ return $response->setSource($source)->setSourceId($source->getSourceId())->setStatus($source->getStatus()); diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php index 2f7a53d00f2..13d0e70864f 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php @@ -72,10 +72,11 @@ private function generateFileName() * save source content * * @param SourceInterface $source + * @param string $content * @throws ImportServiceException * @return SourceInterface */ - public function save(SourceInterface $source) + public function save(SourceInterface $source, $content) { /** @var string $fileName */ $fileName = $this->generateFileName(); @@ -86,7 +87,7 @@ public function save(SourceInterface $source) /** @var Magento\Framework\Filesystem\Directory\Write $var */ $var = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - if(!$var->writeFile($contentFilePath, $source->getImportData())) + if(!$var->writeFile($contentFilePath, $content)) { /** @var array $lastError */ $lastError = error_get_last(); @@ -100,8 +101,7 @@ public function save(SourceInterface $source) } /** set updated data to source */ - $source->setImportData($fileName) - ->setStatus(SourceInterface::STATUS_UPLOADED); + $source->setImportData($fileName)->setStatus(SourceInterface::STATUS_UPLOADED); /** save processed source with status */ $source = $this->sourceRepository->save($source); diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php index 39741206445..4147ea7595e 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php @@ -22,8 +22,9 @@ interface SourceTypeInterface * save source content * * @param SourceInterface $source + * @param string $content * @throws ImportServiceException * @return SourceInterface */ - public function save(SourceInterface $source); + public function save(SourceInterface $source, $content); } From 55d6a4d6aca4b4672ff1d77d0b9d8be0db2367ce Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Mon, 11 Mar 2019 21:45:36 +0530 Subject: [PATCH 6/7] Rollback to previous version with SourceInterface::setImportData used --- .../Processor/Base64EncodedDataProcessor.php | 11 +++++--- .../Processor/ExternalFileProcessor.php | 11 +++++--- .../Processor/LocalPathFileProcessor.php | 11 +++++--- .../Processor/PersistentSourceProcessor.php | 27 +------------------ .../Model/Import/Type/SourceType.php | 5 ++-- .../Model/Import/Type/SourceTypeInterface.php | 3 +-- 6 files changed, 25 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php index ff63aa0b9bf..f6aaa7dfe6a 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/Base64EncodedDataProcessor.php @@ -28,12 +28,12 @@ class Base64EncodedDataProcessor implements SourceProcessorInterface private $persistantUploader; /** - * @param PersistentSourceProcessorFactory $persistantUploaderFactory + * @param PersistentSourceProcessor $persistantUploader */ public function __construct( - PersistentSourceProcessorFactory $persistantUploaderFactory + PersistentSourceProcessor $persistantUploader ) { - $this->persistantUploader = $persistantUploaderFactory->create(); + $this->persistantUploader = $persistantUploader; } /** @@ -44,7 +44,10 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter /** @var string $content */ $content = base64_decode($source->getImportData()); + /** Set downloaded data */ + $source->setImportData($content); + /** process source and get response details */ - return $this->persistantUploader->setContent($content)->processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php index 2a3191abf6d..617d8f10936 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/ExternalFileProcessor.php @@ -44,16 +44,16 @@ class ExternalFileProcessor implements SourceProcessorInterface /** * LocalPathFileProcessor constructor * - * @param PersistentSourceProcessorFactory $persistantUploaderFactory + * @param PersistentSourceProcessor $persistantUploader * @param Filesystem $fileSystem * @param Validator $validator */ public function __construct( - PersistentSourceProcessorFactory $persistantUploaderFactory, + PersistentSourceProcessor $persistantUploader, Filesystem $fileSystem, Validator $validator ) { - $this->persistantUploader = $persistantUploaderFactory->create(); + $this->persistantUploader = $persistantUploader; $this->fileSystem = $fileSystem; $this->validator = $validator; } @@ -90,7 +90,10 @@ public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $s /** read content from external link */ $content = $writeInterface->getDriver()->fileGetContents($source->getImportData()); + /** Set downloaded data */ + $source->setImportData($content); + /** process source and get response details */ - return $this->persistantUploader->setContent($content)->processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php index f003c1307ed..756a533b764 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/LocalPathFileProcessor.php @@ -42,16 +42,16 @@ class LocalPathFileProcessor implements SourceProcessorInterface /** * LocalPathFileProcessor constructor * - * @param PersistentSourceProcessorFactory $persistantUploaderFactory + * @param PersistentSourceProcessor $persistantUploader * @param File $fileSystemIo * @param Filesystem $fileSystem */ public function __construct( - PersistentSourceProcessorFactory $persistantUploaderFactory, + PersistentSourceProcessor $persistantUploader, File $fileSystemIo, Filesystem $fileSystem ) { - $this->persistantUploader = $persistantUploaderFactory->create(); + $this->persistantUploader = $persistantUploader; $this->fileSystemIo = $fileSystemIo; $this->fileSystem = $fileSystem; } @@ -70,7 +70,10 @@ public function processUpload(SourceInterface $source, SourceUploadResponseInter /** read content from system */ $content = $this->fileSystemIo->read($absoluteSourcePath); + /** Set downloaded data */ + $source->setImportData($content); + /** process source and get response details */ - return $this->persistantUploader->setContent($content)->processUpload($source, $response); + return $this->persistantUploader->processUpload($source, $response); } } diff --git a/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php index afa715b6988..c3892146211 100644 --- a/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php +++ b/app/code/Magento/ImportService/Model/Import/Processor/PersistentSourceProcessor.php @@ -22,11 +22,6 @@ class PersistentSourceProcessor implements SourceProcessorInterface */ private $sourceTypePool; - /** - * @var string - */ - private $content; - /** * @param SourceTypePool $sourceTypePool */ @@ -36,18 +31,6 @@ public function __construct( $this->sourceTypePool = $sourceTypePool; } - /** - * Set processed content to save the source request - * - * @param string $content - * @return $this - */ - public function setContent($content) - { - $this->content = $content; - return $this; - } - /** * {@inheritdoc} * @@ -56,19 +39,11 @@ public function setContent($content) */ public function processUpload(SourceInterface $source, SourceUploadResponseInterface $response) { - if(is_null($this->content)) - { - /** Throw error when content is null */ - throw new ImportServiceException( - __('Invalid content, unable to upload source data.') - ); - } - /** @var \Magento\ImportService\Model\Import\Type\SourceTypeInterface $sourceType */ $sourceType = $this->sourceTypePool->getSourceType($source); /** save processed content get updated source object */ - $source = $sourceType->save($source, $this->content); + $source = $sourceType->save($source); /** return response with details */ return $response->setSource($source)->setSourceId($source->getSourceId())->setStatus($source->getStatus()); diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php index 13d0e70864f..1c1739e626a 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceType.php @@ -72,11 +72,10 @@ private function generateFileName() * save source content * * @param SourceInterface $source - * @param string $content * @throws ImportServiceException * @return SourceInterface */ - public function save(SourceInterface $source, $content) + public function save(SourceInterface $source) { /** @var string $fileName */ $fileName = $this->generateFileName(); @@ -87,7 +86,7 @@ public function save(SourceInterface $source, $content) /** @var Magento\Framework\Filesystem\Directory\Write $var */ $var = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - if(!$var->writeFile($contentFilePath, $content)) + if(!$var->writeFile($contentFilePath, $source->getImportData())) { /** @var array $lastError */ $lastError = error_get_last(); diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php index 4147ea7595e..39741206445 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php +++ b/app/code/Magento/ImportService/Model/Import/Type/SourceTypeInterface.php @@ -22,9 +22,8 @@ interface SourceTypeInterface * save source content * * @param SourceInterface $source - * @param string $content * @throws ImportServiceException * @return SourceInterface */ - public function save(SourceInterface $source, $content); + public function save(SourceInterface $source); } From 9dbe281b9ba8300048815ce47a476cb77809d6d2 Mon Sep 17 00:00:00 2001 From: hitarthpattani Date: Tue, 12 Mar 2019 21:21:05 +0530 Subject: [PATCH 7/7] Rename file from SourceType to FileSourceType --- .../Model/Import/Type/{SourceType.php => FileSourceType.php} | 2 +- app/code/Magento/ImportService/etc/di.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/code/Magento/ImportService/Model/Import/Type/{SourceType.php => FileSourceType.php} (98%) diff --git a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php b/app/code/Magento/ImportService/Model/Import/Type/FileSourceType.php similarity index 98% rename from app/code/Magento/ImportService/Model/Import/Type/SourceType.php rename to app/code/Magento/ImportService/Model/Import/Type/FileSourceType.php index 1c1739e626a..fabbc53ae7b 100644 --- a/app/code/Magento/ImportService/Model/Import/Type/SourceType.php +++ b/app/code/Magento/ImportService/Model/Import/Type/FileSourceType.php @@ -16,7 +16,7 @@ /** * Generic Source Type */ -class SourceType implements SourceTypeInterface +class FileSourceType implements SourceTypeInterface { /** * @var SourceRepositoryInterface diff --git a/app/code/Magento/ImportService/etc/di.xml b/app/code/Magento/ImportService/etc/di.xml index 8813c16b066..82f4507a281 100644 --- a/app/code/Magento/ImportService/etc/di.xml +++ b/app/code/Magento/ImportService/etc/di.xml @@ -15,7 +15,7 @@ type="Magento\ImportService\Model\SourceUploadResponse" /> - + csv text/csv