10
10
11
11
use Magento \Framework \App \Filesystem \DirectoryList ;
12
12
use Magento \Framework \HTTP \Adapter \FileTransferFactory ;
13
+ use Magento \Framework \Stdlib \DateTime \DateTime ;
13
14
use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingError ;
14
15
use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingErrorAggregatorInterface ;
15
16
@@ -79,6 +80,11 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
79
80
*/
80
81
const FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR = '_import_multiple_value_separator ' ;
81
82
83
+ /**
84
+ * Import empty attribute value constant.
85
+ */
86
+ const FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT = '_import_empty_attribute_value_constant ' ;
87
+
82
88
/**
83
89
* Allow multiple values wrapping in double quotes for additional attributes.
84
90
*/
@@ -91,6 +97,11 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
91
97
*/
92
98
const DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR = ', ' ;
93
99
100
+ /**
101
+ * default empty attribute value constant
102
+ */
103
+ const DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT = '__EMPTY__VALUE__ ' ;
104
+
94
105
/**#@+
95
106
* Import constants
96
107
*/
@@ -159,6 +170,16 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
159
170
*/
160
171
protected $ _filesystem ;
161
172
173
+ /**
174
+ * @var History
175
+ */
176
+ private $ importHistoryModel ;
177
+
178
+ /**
179
+ * @var DateTime
180
+ */
181
+ private $ localeDate ;
182
+
162
183
/**
163
184
* @param \Psr\Log\LoggerInterface $logger
164
185
* @param \Magento\Framework\Filesystem $filesystem
@@ -173,7 +194,7 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
173
194
* @param Source\Import\Behavior\Factory $behaviorFactory
174
195
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
175
196
* @param History $importHistoryModel
176
- * @param \Magento\Framework\Stdlib\ DateTime\DateTime
197
+ * @param DateTime $localeDate
177
198
* @param array $data
178
199
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
179
200
*/
@@ -191,7 +212,7 @@ public function __construct(
191
212
\Magento \ImportExport \Model \Source \Import \Behavior \Factory $ behaviorFactory ,
192
213
\Magento \Framework \Indexer \IndexerRegistry $ indexerRegistry ,
193
214
\Magento \ImportExport \Model \History $ importHistoryModel ,
194
- \ Magento \ Framework \ Stdlib \ DateTime \ DateTime $ localeDate ,
215
+ DateTime $ localeDate ,
195
216
array $ data = []
196
217
) {
197
218
$ this ->_importExportData = $ importExportData ;
@@ -234,7 +255,9 @@ protected function _getEntityAdapter()
234
255
) {
235
256
throw new \Magento \Framework \Exception \LocalizedException (
236
257
__ (
237
- 'The entity adapter object must be an instance of %1 or %2. ' , \Magento \ImportExport \Model \Import \Entity \AbstractEntity::class, \Magento \ImportExport \Model \Import \AbstractEntity::class
258
+ 'The entity adapter object must be an instance of %1 or %2. ' ,
259
+ \Magento \ImportExport \Model \Import \Entity \AbstractEntity::class,
260
+ \Magento \ImportExport \Model \Import \AbstractEntity::class
238
261
)
239
262
);
240
263
}
@@ -513,14 +536,27 @@ public function uploadSource()
513
536
}
514
537
$ this ->_removeBom ($ sourceFile );
515
538
$ this ->createHistoryReport ($ sourceFileRelative , $ entity , $ extension , $ result );
516
- // trying to create source adapter for file and catch possible exception to be convinced in its adequacy
539
+
540
+ return $ sourceFile ;
541
+ }
542
+
543
+ /**
544
+ * Move uploaded file and provide source instance.
545
+ *
546
+ * @return Import\AbstractSource
547
+ * @throws \Magento\Framework\Exception\LocalizedException
548
+ */
549
+ public function uploadFileAndGetSource ()
550
+ {
551
+ $ sourceFile = $ this ->uploadSource ();
517
552
try {
518
- $ this ->_getSourceAdapter ($ sourceFile );
553
+ $ source = $ this ->_getSourceAdapter ($ sourceFile );
519
554
} catch (\Exception $ e ) {
520
- $ this ->_varDirectory ->delete ($ sourceFileRelative );
555
+ $ this ->_varDirectory ->delete ($ this -> _varDirectory -> getRelativePath ( $ sourceFile ) );
521
556
throw new \Magento \Framework \Exception \LocalizedException (__ ($ e ->getMessage ()));
522
557
}
523
- return $ sourceFile ;
558
+
559
+ return $ source ;
524
560
}
525
561
526
562
/**
@@ -684,7 +720,9 @@ public function isReportEntityType($entity = null)
684
720
try {
685
721
$ result = $ this ->_getEntityAdapter ()->isNeedToLogInHistory ();
686
722
} catch (\Exception $ e ) {
687
- throw new \Magento \Framework \Exception \LocalizedException (__ ('Please enter a correct entity model ' ));
723
+ throw new \Magento \Framework \Exception \LocalizedException (
724
+ __ ('Please enter a correct entity model ' )
725
+ );
688
726
}
689
727
} else {
690
728
throw new \Magento \Framework \Exception \LocalizedException (__ ('Please enter a correct entity model ' ));
@@ -696,11 +734,11 @@ public function isReportEntityType($entity = null)
696
734
}
697
735
698
736
/**
699
- * Create history report
737
+ * Create history report.
700
738
*
739
+ * @param string $sourceFileRelative
701
740
* @param string $entity
702
741
* @param string $extension
703
- * @param string $sourceFileRelative
704
742
* @param array $result
705
743
* @return $this
706
744
* @throws \Magento\Framework\Exception\LocalizedException
@@ -713,7 +751,7 @@ protected function createHistoryReport($sourceFileRelative, $entity, $extension
713
751
$ sourceFileRelative = $ this ->_varDirectory ->getRelativePath (self ::IMPORT_DIR . $ fileName );
714
752
} elseif (isset ($ result ['name ' ])) {
715
753
$ fileName = $ result ['name ' ];
716
- } elseif (! is_null ( $ extension) ) {
754
+ } elseif ($ extension !== null ) {
717
755
$ fileName = $ entity . $ extension ;
718
756
} else {
719
757
$ fileName = basename ($ sourceFileRelative );
0 commit comments