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
@@ -78,6 +79,11 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
78
79
*/
79
80
const FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR = '_import_multiple_value_separator ' ;
80
81
82
+ /**
83
+ * Import empty attribute value constant.
84
+ */
85
+ const FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT = '_import_empty_attribute_value_constant ' ;
86
+
81
87
/**
82
88
* Allow multiple values wrapping in double quotes for additional attributes.
83
89
*/
@@ -90,6 +96,11 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
90
96
*/
91
97
const DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR = ', ' ;
92
98
99
+ /**
100
+ * default empty attribute value constant
101
+ */
102
+ const DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT = '__EMPTY__VALUE__ ' ;
103
+
93
104
/**#@+
94
105
* Import constants
95
106
*/
@@ -162,6 +173,16 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
162
173
*/
163
174
protected $ _filesystem ;
164
175
176
+ /**
177
+ * @var History
178
+ */
179
+ private $ importHistoryModel ;
180
+
181
+ /**
182
+ * @var DateTime
183
+ */
184
+ private $ localeDate ;
185
+
165
186
/**
166
187
* @param \Psr\Log\LoggerInterface $logger
167
188
* @param \Magento\Framework\Filesystem $filesystem
@@ -176,7 +197,7 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
176
197
* @param Source\Import\Behavior\Factory $behaviorFactory
177
198
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
178
199
* @param History $importHistoryModel
179
- * @param \Magento\Framework\Stdlib\ DateTime\DateTime
200
+ * @param DateTime $localeDate
180
201
* @param array $data
181
202
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
182
203
*/
@@ -194,7 +215,7 @@ public function __construct(
194
215
\Magento \ImportExport \Model \Source \Import \Behavior \Factory $ behaviorFactory ,
195
216
\Magento \Framework \Indexer \IndexerRegistry $ indexerRegistry ,
196
217
\Magento \ImportExport \Model \History $ importHistoryModel ,
197
- \ Magento \ Framework \ Stdlib \ DateTime \ DateTime $ localeDate ,
218
+ DateTime $ localeDate ,
198
219
array $ data = []
199
220
) {
200
221
$ this ->_importExportData = $ importExportData ;
@@ -221,7 +242,6 @@ public function __construct(
221
242
*/
222
243
protected function _getEntityAdapter ()
223
244
{
224
-
225
245
if (!$ this ->_entityAdapter ) {
226
246
$ entities = $ this ->_importConfig ->getEntities ();
227
247
if (isset ($ entities [$ this ->getEntity ()])) {
@@ -239,8 +259,8 @@ protected function _getEntityAdapter()
239
259
throw new \Magento \Framework \Exception \LocalizedException (
240
260
__ (
241
261
'The entity adapter object must be an instance of %1 or %2. ' ,
242
- ' Magento\ImportExport\Model\Import\Entity\AbstractEntity ' ,
243
- ' Magento\ImportExport\Model\Import\AbstractEntity '
262
+ \ Magento \ImportExport \Model \Import \Entity \AbstractEntity::class ,
263
+ \ Magento \ImportExport \Model \Import \AbstractEntity::class
244
264
)
245
265
);
246
266
}
@@ -435,7 +455,6 @@ public function importSource()
435
455
$ this ->importHistoryModel ->invalidateReport ($ this );
436
456
}
437
457
438
-
439
458
return $ result ;
440
459
}
441
460
@@ -537,14 +556,28 @@ public function uploadSource()
537
556
}
538
557
$ this ->_removeBom ($ sourceFile );
539
558
$ this ->createHistoryReport ($ sourceFileRelative , $ entity , $ extension , $ result );
540
- // trying to create source adapter for file and catch possible exception to be convinced in its adequacy
559
+
560
+ return $ sourceFile ;
561
+ }
562
+
563
+ /**
564
+ * Move uploaded file and provide source instance.
565
+ *
566
+ * @return Import\AbstractSource
567
+ * @throws \Magento\Framework\Exception\FileSystemException
568
+ * @throws \Magento\Framework\Exception\LocalizedException
569
+ */
570
+ public function uploadFileAndGetSource ()
571
+ {
572
+ $ sourceFile = $ this ->uploadSource ();
541
573
try {
542
- $ this ->_getSourceAdapter ($ sourceFile );
574
+ $ source = $ this ->_getSourceAdapter ($ sourceFile );
543
575
} catch (\Exception $ e ) {
544
- $ this ->_varDirectory ->delete ($ sourceFileRelative );
576
+ $ this ->_varDirectory ->delete ($ this -> _varDirectory -> getRelativePath ( $ sourceFile ) );
545
577
throw new \Magento \Framework \Exception \LocalizedException (__ ($ e ->getMessage ()));
546
578
}
547
- return $ sourceFile ;
579
+
580
+ return $ source ;
548
581
}
549
582
550
583
/**
@@ -708,7 +741,9 @@ public function isReportEntityType($entity = null)
708
741
try {
709
742
$ result = $ this ->_getEntityAdapter ()->isNeedToLogInHistory ();
710
743
} catch (\Exception $ e ) {
711
- throw new \Magento \Framework \Exception \LocalizedException (__ ('Please enter a correct entity model ' ));
744
+ throw new \Magento \Framework \Exception \LocalizedException (
745
+ __ ('Please enter a correct entity model ' )
746
+ );
712
747
}
713
748
} else {
714
749
throw new \Magento \Framework \Exception \LocalizedException (__ ('Please enter a correct entity model ' ));
@@ -720,11 +755,11 @@ public function isReportEntityType($entity = null)
720
755
}
721
756
722
757
/**
723
- * Create history report
758
+ * Create history report.
724
759
*
760
+ * @param string $sourceFileRelative
725
761
* @param string $entity
726
762
* @param string $extension
727
- * @param string $sourceFileRelative
728
763
* @param array $result
729
764
* @return $this
730
765
* @throws \Magento\Framework\Exception\LocalizedException
@@ -737,7 +772,7 @@ protected function createHistoryReport($sourceFileRelative, $entity, $extension
737
772
$ sourceFileRelative = $ this ->_varDirectory ->getRelativePath (self ::IMPORT_DIR . $ fileName );
738
773
} elseif (isset ($ result ['name ' ])) {
739
774
$ fileName = $ result ['name ' ];
740
- } elseif (! is_null ( $ extension) ) {
775
+ } elseif ($ extension !== null ) {
741
776
$ fileName = $ entity . $ extension ;
742
777
} else {
743
778
$ fileName = basename ($ sourceFileRelative );
@@ -759,7 +794,6 @@ protected function createHistoryReport($sourceFileRelative, $entity, $extension
759
794
return $ this ;
760
795
}
761
796
762
-
763
797
/**
764
798
* Get count of created items
765
799
*
0 commit comments