Skip to content

Commit 71956ac

Browse files
committed
ACP2E-649: Invalid data is exported when we apply created at filter for customer export
1 parent 0763e06 commit 71956ac

File tree

11 files changed

+270
-76
lines changed

11 files changed

+270
-76
lines changed

app/code/Magento/ImportExport/Api/Data/ExtendedExportInfoInterface.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,30 @@ interface ExtendedExportInfoInterface extends ExportInfoInterface
1515
/**
1616
* Returns skipped attributes
1717
*
18-
* @return mixed
18+
* @return string[]|null
1919
*/
20-
public function getSkipAttr();
20+
public function getSkipAttr(): ?array;
2121

2222
/**
2323
* Set skipped attributes
2424
*
25-
* @param string $skipAttr
26-
* @return mixed
25+
* @param string[] $skipAttr
26+
* @return void
2727
*/
28-
public function setSkipAttr($skipAttr);
28+
public function setSkipAttr(array $skipAttr): void;
29+
30+
/**
31+
* Returns admin locale
32+
*
33+
* @return string|null
34+
*/
35+
public function getLocale(): ?string;
36+
37+
/**
38+
* Set admin locale
39+
*
40+
* @param string $locale
41+
* @return void
42+
*/
43+
public function setLocale(string $locale): void;
2944
}

app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\App\Response\Http\FileFactory;
1314
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Locale\ResolverInterface;
1416
use Magento\Framework\MessageQueue\PublisherInterface;
17+
use Magento\Framework\Session\SessionManagerInterface;
1518
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
1619
use Magento\ImportExport\Model\Export as ExportModel;
1720
use Magento\ImportExport\Model\Export\Entity\ExportInfoFactory;
@@ -27,7 +30,7 @@ class Export extends ExportController implements HttpPostActionInterface
2730
protected $fileFactory;
2831

2932
/**
30-
* @var \Magento\Framework\Session\SessionManagerInterface
33+
* @var SessionManagerInterface
3134
*/
3235
private $sessionManager;
3336

@@ -41,29 +44,37 @@ class Export extends ExportController implements HttpPostActionInterface
4144
*/
4245
private $exportInfoFactory;
4346

47+
/**
48+
* @var ResolverInterface
49+
*/
50+
private $localeResolver;
51+
4452
/**
4553
* @param Context $context
4654
* @param FileFactory $fileFactory
47-
* @param \Magento\Framework\Session\SessionManagerInterface|null $sessionManager
55+
* @param SessionManagerInterface|null $sessionManager
4856
* @param PublisherInterface|null $publisher
4957
* @param ExportInfoFactory|null $exportInfoFactory
58+
* @param ResolverInterface|null $localeResolver
5059
*/
5160
public function __construct(
5261
Context $context,
5362
FileFactory $fileFactory,
54-
\Magento\Framework\Session\SessionManagerInterface $sessionManager = null,
63+
SessionManagerInterface $sessionManager = null,
5564
PublisherInterface $publisher = null,
56-
ExportInfoFactory $exportInfoFactory = null
65+
ExportInfoFactory $exportInfoFactory = null,
66+
ResolverInterface $localeResolver = null
5767
) {
5868
$this->fileFactory = $fileFactory;
59-
$this->sessionManager = $sessionManager ?: \Magento\Framework\App\ObjectManager::getInstance()
60-
->get(\Magento\Framework\Session\SessionManagerInterface::class);
61-
$this->messagePublisher = $publisher ?: \Magento\Framework\App\ObjectManager::getInstance()
62-
->get(PublisherInterface::class);
63-
$this->exportInfoFactory = $exportInfoFactory ?:
64-
\Magento\Framework\App\ObjectManager::getInstance()->get(
65-
ExportInfoFactory::class
66-
);
69+
$this->sessionManager = $sessionManager
70+
?? ObjectManager::getInstance()->get(SessionManagerInterface::class);
71+
$this->messagePublisher = $publisher
72+
?? ObjectManager::getInstance()->get(PublisherInterface::class);
73+
$this->exportInfoFactory = $exportInfoFactory
74+
?? ObjectManager::getInstance()->get(ExportInfoFactory::class);
75+
$this->localeResolver = $localeResolver
76+
?? ObjectManager::getInstance()->get(ResolverInterface::class);
77+
6778
parent::__construct($context);
6879
}
6980

@@ -87,7 +98,8 @@ public function execute()
8798
$params['file_format'],
8899
$params['entity'],
89100
$params['export_filter'],
90-
$params['skip_attr']
101+
$params['skip_attr'],
102+
$this->localeResolver->getLocale()
91103
);
92104

93105
$this->messagePublisher->publish('import_export.export', $dataObject);

app/code/Magento/ImportExport/Model/Export/Consumer.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
use Magento\Framework\Exception\FileSystemException;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Locale\ResolverInterface;
15+
use Magento\ImportExport\Api\Data\ExtendedExportInfoInterface;
1416
use Magento\ImportExport\Api\ExportManagementInterface;
15-
use Magento\ImportExport\Api\Data\ExportInfoInterface;
1617
use Magento\Framework\Notification\NotifierInterface;
1718

1819
/**
@@ -40,33 +41,46 @@ class Consumer
4041
*/
4142
private $filesystem;
4243

44+
/**
45+
* @var ResolverInterface
46+
*/
47+
private $localeResolver;
48+
4349
/**
4450
* Consumer constructor.
4551
* @param \Psr\Log\LoggerInterface $logger
4652
* @param ExportManagementInterface $exportManager
4753
* @param Filesystem $filesystem
4854
* @param NotifierInterface $notifier
55+
* @param ResolverInterface $localeResolver
4956
*/
5057
public function __construct(
5158
\Psr\Log\LoggerInterface $logger,
5259
ExportManagementInterface $exportManager,
5360
Filesystem $filesystem,
54-
NotifierInterface $notifier
61+
NotifierInterface $notifier,
62+
ResolverInterface $localeResolver
5563
) {
5664
$this->logger = $logger;
5765
$this->exportManager = $exportManager;
5866
$this->filesystem = $filesystem;
5967
$this->notifier = $notifier;
68+
$this->localeResolver = $localeResolver;
6069
}
6170

6271
/**
6372
* Consumer logic.
6473
*
65-
* @param ExportInfoInterface $exportInfo
74+
* @param ExtendedExportInfoInterface $exportInfo
6675
* @return void
6776
*/
68-
public function process(ExportInfoInterface $exportInfo)
77+
public function process(ExtendedExportInfoInterface $exportInfo)
6978
{
79+
$currentLocale = $this->localeResolver->getLocale();
80+
if ($exportInfo->getLocale()) {
81+
$this->localeResolver->setLocale($exportInfo->getLocale());
82+
}
83+
7084
try {
7185
$data = $this->exportManager->export($exportInfo);
7286
$fileName = $exportInfo->getFileName();
@@ -83,6 +97,8 @@ public function process(ExportInfoInterface $exportInfo)
8397
__('Error during export process occurred. Please check logs for detail')
8498
);
8599
$this->logger->critical('Something went wrong while export process. ' . $exception->getMessage());
100+
} finally {
101+
$this->localeResolver->setLocale($currentLocale);
86102
}
87103
}
88104
}

app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/**
1515
* Export EAV entity abstract model
1616
*
17+
* phpcs:ignore Magento2.Classes.AbstractApi
1718
* @api
1819
*
1920
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -37,8 +38,6 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Export\AbstractEn
3738
protected $attributeTypes = [];
3839

3940
/**
40-
* Entity type id.
41-
*
4241
* @var int
4342
*/
4443
protected $_entityTypeId;
@@ -158,7 +157,7 @@ public function filterEntityCollection(AbstractCollection $collection)
158157
$attributeCode,
159158
['eq' => $exportFilter[$attributeCode]]
160159
);
161-
} else if (is_array($exportFilter[$attributeCode])) {
160+
} elseif (is_array($exportFilter[$attributeCode])) {
162161
$collection->addAttributeToFilter(
163162
$attributeCode,
164163
['in' => $exportFilter[$attributeCode]]
@@ -167,13 +166,11 @@ public function filterEntityCollection(AbstractCollection $collection)
167166
} elseif (Export::FILTER_TYPE_MULTISELECT == $attributeFilterType) {
168167
if (is_array($exportFilter[$attributeCode])) {
169168
array_filter($exportFilter[$attributeCode]);
170-
if (!empty($exportFilter[$attributeCode])) {
171-
foreach ($exportFilter[$attributeCode] as $val) {
172-
$collection->addAttributeToFilter(
173-
$attributeCode,
174-
['finset' => $val]
175-
);
176-
}
169+
foreach ($exportFilter[$attributeCode] as $val) {
170+
$collection->addAttributeToFilter(
171+
$attributeCode,
172+
['finset' => $val]
173+
);
177174
}
178175
}
179176
} elseif (Export::FILTER_TYPE_INPUT == $attributeFilterType) {
@@ -189,11 +186,11 @@ public function filterEntityCollection(AbstractCollection $collection)
189186
$to = array_shift($exportFilter[$attributeCode]);
190187

191188
if (is_scalar($from) && !empty($from)) {
192-
$date = (new \DateTime($from))->format('m/d/Y');
189+
$date = $this->_localeDate->date($from);
193190
$collection->addAttributeToFilter($attributeCode, ['from' => $date, 'date' => true]);
194191
}
195192
if (is_scalar($to) && !empty($to)) {
196-
$date = (new \DateTime($to))->format('m/d/Y');
193+
$date = $this->_localeDate->date($to);
197194
$collection->addAttributeToFilter($attributeCode, ['to' => $date, 'date' => true]);
198195
}
199196
}
@@ -255,6 +252,7 @@ public function getAttributeOptions(AbstractAttribute $attribute)
255252
}
256253
}
257254
}
255+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
258256
} catch (\Exception $e) {
259257
// ignore exceptions connected with source models
260258
}

app/code/Magento/ImportExport/Model/Export/Entity/ExportInfo.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class ExportInfo implements ExtendedExportInfoInterface
4444
*/
4545
private $skipAttr;
4646

47+
/**
48+
* @var string
49+
*/
50+
private $locale;
51+
4752
/**
4853
* @inheritdoc
4954
*/
@@ -127,16 +132,32 @@ public function setExportFilter($exportFilter)
127132
/**
128133
* @inheritdoc
129134
*/
130-
public function getSkipAttr()
135+
public function getSkipAttr(): ?array
131136
{
132137
return $this->skipAttr;
133138
}
134139

135140
/**
136141
* @inheritdoc
137142
*/
138-
public function setSkipAttr($skipAttr)
143+
public function setSkipAttr(array $skipAttr): void
139144
{
140145
$this->skipAttr = $skipAttr;
141146
}
147+
148+
/**
149+
* @inheritdoc
150+
*/
151+
public function getLocale(): ?string
152+
{
153+
return $this->locale;
154+
}
155+
156+
/**
157+
* @inheritdoc
158+
*/
159+
public function setLocale(string $locale): void
160+
{
161+
$this->locale = $locale;
162+
}
142163
}

app/code/Magento/ImportExport/Model/Export/Entity/ExportInfoFactory.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
class ExportInfoFactory
2323
{
2424
/**
25-
* Object Manager
26-
*
2725
* @var \Magento\Framework\ObjectManagerInterface
2826
*/
2927
private $objectManager;
@@ -54,7 +52,6 @@ class ExportInfoFactory
5452
private $logger;
5553

5654
/**
57-
* ExportInfoFactory constructor.
5855
* @param ObjectManagerInterface $objectManager
5956
* @param ConfigInterface $exportConfig
6057
* @param Factory $entityFactory
@@ -83,13 +80,19 @@ public function __construct(
8380
*
8481
* @param string $fileFormat
8582
* @param string $entity
86-
* @param string $exportFilter
83+
* @param array $exportFilter
8784
* @param array $skipAttr
85+
* @param string|null $locale
8886
* @return ExportInfoInterface
8987
* @throws \Magento\Framework\Exception\LocalizedException
9088
*/
91-
public function create($fileFormat, $entity, $exportFilter, $skipAttr)
92-
{
89+
public function create(
90+
string $fileFormat,
91+
string $entity,
92+
array $exportFilter,
93+
array $skipAttr = [],
94+
?string $locale = null
95+
) {
9396
$writer = $this->getWriter($fileFormat);
9497
$entityAdapter = $this->getEntityAdapter(
9598
$entity,
@@ -107,6 +110,9 @@ public function create($fileFormat, $entity, $exportFilter, $skipAttr)
107110
$exportInfo->setEntity($entity);
108111
$exportInfo->setFileFormat($fileFormat);
109112
$exportInfo->setContentType($writer->getContentType());
113+
if ($locale) {
114+
$exportInfo->setLocale($locale);
115+
}
110116

111117
return $exportInfo;
112118
}
@@ -137,7 +143,7 @@ private function generateFileName($entity, $entityAdapter, $fileExtensions)
137143
*
138144
* @param string $entity
139145
* @param string $fileFormat
140-
* @param string $exportFilter
146+
* @param array $exportFilter
141147
* @param array $skipAttr
142148
* @param string $contentType
143149
* @return \Magento\ImportExport\Model\Export\AbstractEntity|AbstractEntity

0 commit comments

Comments
 (0)