7
7
8
8
namespace Magento \ImportService \Model \Import \Processor ;
9
9
10
+ use Magento \Framework \Filesystem \Io \File ;
11
+ use Magento \ImportService \Api \Data \SourceInterface ;
12
+ use Magento \ImportService \Api \Data \SourceUploadResponseInterface ;
10
13
use Magento \Framework \App \Filesystem \DirectoryList ;
11
14
use Magento \Framework \Filesystem ;
12
- use Magento \ImportService \Exception as ImportServiceException ;
13
- use Magento \ImportService \Model \Import \SourceProcessorPool ;
15
+ use Magento \ImportService \Model \Import \SourceTypePool ;
14
16
use Magento \ImportService \Model \Source \Validator ;
17
+ use Magento \ImportService \ImportServiceException ;
15
18
16
19
/**
17
20
* CSV files processor for asynchronous import
18
21
*/
19
- class ExternalFileProcessor implements SourceProcessorInterface
22
+ class ExternalFileProcessor extends AbstractSourceProcessor
20
23
{
24
+ /**
25
+ * Import Type
26
+ */
27
+ const IMPORT_TYPE = 'external ' ;
28
+
21
29
/**
22
30
* @var \Magento\Framework\Filesystem
23
31
*/
@@ -31,15 +39,18 @@ class ExternalFileProcessor implements SourceProcessorInterface
31
39
/**
32
40
* LocalPathFileProcessor constructor
33
41
*
34
- * @param FileSystem $fileSystem
42
+ * @param Filesystem $fileSystem
35
43
* @param Validator $validator
44
+ * @param SourceTypePool $sourceTypePool
36
45
*/
37
46
public function __construct (
38
- FileSystem $ fileSystem ,
39
- Validator $ validator
47
+ Filesystem $ fileSystem ,
48
+ Validator $ validator ,
49
+ SourceTypePool $ sourceTypePool
40
50
) {
41
51
$ this ->fileSystem = $ fileSystem ;
42
52
$ this ->validator = $ validator ;
53
+ parent ::__construct ($ sourceTypePool );
43
54
}
44
55
45
56
/**
@@ -68,25 +79,16 @@ public function processUpload(\Magento\ImportService\Api\Data\SourceInterface $s
68
79
);
69
80
}
70
81
71
- /** @var string $workingDirectory */
72
- $ workingDirectory = SourceProcessorPool::WORKING_DIR ;
73
-
74
- /** @var string $fileName */
75
- $ fileName = uniqid () . '. ' . $ source ->getSourceType ();
76
-
77
82
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $writeInterface */
78
- $ writeInterface = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::VAR_DIR );
79
-
80
- /** If the directory is not present, it will be created */
81
- $ writeInterface ->create ($ workingDirectory );
83
+ $ writeInterface = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::ROOT );
82
84
83
- /** @var string $copyFileFullPath */
84
- $ copyFileFullPath = $ writeInterface ->getAbsolutePath ( $ workingDirectory ) . $ fileName ;
85
+ /** read content from external link */
86
+ $ content = $ writeInterface ->getDriver ()-> fileGetContents ( $ source -> getImportData ()) ;
85
87
86
- /** Attempt a copy, may throw \Magento\Framework\Exception\FileSystemException */
87
- $ writeInterface -> getDriver ()-> copy ( $ source ->getImportData (), $ copyFileFullPath );
88
+ /** Set downloaded data */
89
+ $ source ->setImportData ( $ content );
88
90
89
- return $ response -> setSource ( $ source-> setImportData ( $ fileName ))
90
- -> setStatus ( $ response:: STATUS_UPLOADED );
91
+ /** process source and get response details */
92
+ return parent :: processUpload ( $ source , $ response );
91
93
}
92
94
}
0 commit comments