Skip to content

Commit 936a849

Browse files
authored
Merge pull request #3777 from magento-performance/MC-5953-2
Performance async export and coupon generation
2 parents 9cdc1b7 + c3ec2e0 commit 936a849

File tree

49 files changed

+1705
-1511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1705
-1511
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Api\Data;
9+
10+
/**
11+
* Basic interface with data needed for export operation.
12+
* @api
13+
*/
14+
interface ExportInfoInterface
15+
{
16+
/**
17+
* Return filename.
18+
*
19+
* @return string
20+
*/
21+
public function getFileName();
22+
23+
/**
24+
* Set filename into local variable.
25+
*
26+
* @param string $fileName
27+
* @return void
28+
*/
29+
public function setFileName($fileName);
30+
31+
/**
32+
* Override standard entity getter.
33+
*
34+
* @return string
35+
*/
36+
public function getFileFormat();
37+
38+
/**
39+
* Set file format.
40+
*
41+
* @param string $fileFormat
42+
* @return void
43+
*/
44+
public function setFileFormat($fileFormat);
45+
46+
/**
47+
* Return content type.
48+
*
49+
* @return string
50+
*/
51+
public function getContentType();
52+
53+
/**
54+
* Set content type.
55+
*
56+
* @param string $contentType
57+
* @return void
58+
*/
59+
public function setContentType($contentType);
60+
61+
/**
62+
* Returns entity.
63+
*
64+
* @return string
65+
*/
66+
public function getEntity();
67+
68+
/**
69+
* Set entity for export logic.
70+
*
71+
* @param string $entity
72+
* @return void
73+
*/
74+
public function setEntity($entity);
75+
76+
/**
77+
* Returns export filter.
78+
*
79+
* @return string
80+
*/
81+
public function getExportFilter();
82+
83+
/**
84+
* Set filter for export result.
85+
*
86+
* @param string $exportFilter
87+
* @return void
88+
*/
89+
public function setExportFilter($exportFilter);
90+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Api;
9+
10+
use Magento\ImportExport\Api\Data\ExportInfoInterface;
11+
12+
/**
13+
* Describes how to do export operation with data interface.
14+
* @api
15+
*/
16+
interface ExportManagementInterface
17+
{
18+
/**
19+
* Return export data.
20+
*
21+
* @param ExportInfoInterface $exportInfo
22+
* @return string
23+
*/
24+
public function export(ExportInfoInterface $exportInfo);
25+
}

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
use Magento\Backend\App\Action\Context;
1212
use Magento\Framework\App\Response\Http\FileFactory;
1313
use Magento\ImportExport\Model\Export as ExportModel;
14-
use Magento\Framework\App\Filesystem\DirectoryList;
15-
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\MessageQueue\PublisherInterface;
15+
use Magento\ImportExport\Model\Export\Entity\ExportInfoFactory;
1616

17+
/**
18+
* Controller for export operation.
19+
*/
1720
class Export extends ExportController implements HttpPostActionInterface
1821
{
1922
/**
@@ -27,18 +30,38 @@ class Export extends ExportController implements HttpPostActionInterface
2730
private $sessionManager;
2831

2932
/**
30-
* @param \Magento\Backend\App\Action\Context $context
31-
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
32-
* @param \Magento\Framework\Session\SessionManagerInterface $sessionManager [optional]
33+
* @var PublisherInterface
34+
*/
35+
private $messagePublisher;
36+
37+
/**
38+
* @var ExportInfoFactory
39+
*/
40+
private $exportInfoFactory;
41+
42+
/**
43+
* @param Context $context
44+
* @param FileFactory $fileFactory
45+
* @param \Magento\Framework\Session\SessionManagerInterface|null $sessionManager
46+
* @param PublisherInterface|null $publisher
47+
* @param ExportInfoFactory|null $exportInfoFactory
3348
*/
3449
public function __construct(
3550
Context $context,
3651
FileFactory $fileFactory,
37-
\Magento\Framework\Session\SessionManagerInterface $sessionManager = null
52+
\Magento\Framework\Session\SessionManagerInterface $sessionManager = null,
53+
PublisherInterface $publisher = null,
54+
ExportInfoFactory $exportInfoFactory = null
3855
) {
3956
$this->fileFactory = $fileFactory;
4057
$this->sessionManager = $sessionManager ?: \Magento\Framework\App\ObjectManager::getInstance()
4158
->get(\Magento\Framework\Session\SessionManagerInterface::class);
59+
$this->messagePublisher = $publisher ?: \Magento\Framework\App\ObjectManager::getInstance()
60+
->get(PublisherInterface::class);
61+
$this->exportInfoFactory = $exportInfoFactory ?:
62+
\Magento\Framework\App\ObjectManager::getInstance()->get(
63+
ExportInfoFactory::class
64+
);
4265
parent::__construct($context);
4366
}
4467

@@ -51,19 +74,19 @@ public function execute()
5174
{
5275
if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) {
5376
try {
54-
/** @var $model \Magento\ImportExport\Model\Export */
55-
$model = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
56-
$model->setData($this->getRequest()->getParams());
77+
$params = $this->getRequest()->getParams();
78+
79+
/** @var ExportInfoFactory $dataObject */
80+
$dataObject = $this->exportInfoFactory->create(
81+
$params['file_format'],
82+
$params['entity'],
83+
$params['export_filter']
84+
);
5785

58-
$this->sessionManager->writeClose();
59-
return $this->fileFactory->create(
60-
$model->getFileName(),
61-
$model->export(),
62-
DirectoryList::VAR_DIR,
63-
$model->getContentType()
86+
$this->messagePublisher->publish('import_export.export', $dataObject);
87+
$this->messageManager->addSuccessMessage(
88+
__('Message is added to queue, wait to get your file soon')
6489
);
65-
} catch (LocalizedException $e) {
66-
$this->messageManager->addError($e->getMessage());
6790
} catch (\Exception $e) {
6891
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
6992
$this->messageManager->addError(__('Please correct the data sent value.'));
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Framework\App\Action\HttpGetActionInterface;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\Exception\FileSystemException;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\App\Filesystem\DirectoryList;
16+
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
17+
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Filesystem\DriverInterface;
19+
20+
/**
21+
* Controller that delete file by name.
22+
*/
23+
class Delete extends ExportController implements HttpGetActionInterface
24+
{
25+
/**
26+
* url to this controller
27+
*/
28+
const URL = 'admin/export_file/delete';
29+
30+
/**
31+
* @var Filesystem
32+
*/
33+
private $filesystem;
34+
35+
/**
36+
* @var DriverInterface
37+
*/
38+
private $file;
39+
40+
/**
41+
* Delete constructor.
42+
* @param Action\Context $context
43+
* @param Filesystem $filesystem
44+
* @param DriverInterface $file
45+
*/
46+
public function __construct(
47+
Action\Context $context,
48+
Filesystem $filesystem,
49+
DriverInterface $file
50+
) {
51+
$this->filesystem = $filesystem;
52+
$this->file = $file;
53+
parent::__construct($context);
54+
}
55+
56+
/**
57+
* Controller basic method implementation.
58+
*
59+
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
60+
* @throws LocalizedException
61+
*/
62+
public function execute()
63+
{
64+
try {
65+
if (empty($fileName = $this->getRequest()->getParam('filename'))) {
66+
throw new LocalizedException(__('Please provide export file name'));
67+
}
68+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
69+
$path = $directory->getAbsolutePath() . 'export/' . $fileName;
70+
$this->file->deleteFile($path);
71+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
72+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
73+
$resultRedirect->setPath('adminhtml/export/index');
74+
return $resultRedirect;
75+
} catch (FileSystemException $exception) {
76+
throw new LocalizedException(__('There are no export file with such name %1', $fileName));
77+
}
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Framework\App\Action\HttpGetActionInterface;
12+
use Magento\Framework\App\Response\Http\FileFactory;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
16+
use Magento\Framework\Filesystem;
17+
18+
/**
19+
* Controller that download file by name.
20+
*/
21+
class Download extends ExportController implements HttpGetActionInterface
22+
{
23+
/**
24+
* url to this controller
25+
*/
26+
const URL = 'admin/export_file/download/';
27+
28+
/**
29+
* @var FileFactory
30+
*/
31+
private $fileFactory;
32+
33+
/**
34+
* @var Filesystem
35+
*/
36+
private $filesystem;
37+
38+
/**
39+
* DownloadFile constructor.
40+
* @param Action\Context $context
41+
* @param FileFactory $fileFactory
42+
* @param Filesystem $filesystem
43+
*/
44+
public function __construct(
45+
Action\Context $context,
46+
FileFactory $fileFactory,
47+
Filesystem $filesystem
48+
) {
49+
$this->fileFactory = $fileFactory;
50+
$this->filesystem = $filesystem;
51+
parent::__construct($context);
52+
}
53+
54+
/**
55+
* Controller basic method implementation.
56+
*
57+
* @return \Magento\Framework\App\ResponseInterface
58+
* @throws LocalizedException
59+
*/
60+
public function execute()
61+
{
62+
if (empty($fileName = $this->getRequest()->getParam('filename'))) {
63+
throw new LocalizedException(__('Please provide export file name'));
64+
}
65+
try {
66+
$path = 'export/' . $fileName;
67+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
68+
if ($directory->isFile($path)) {
69+
return $this->fileFactory->create(
70+
$path,
71+
$directory->readFile($path),
72+
DirectoryList::VAR_DIR
73+
);
74+
}
75+
} catch (LocalizedException | \Exception $exception) {
76+
throw new LocalizedException(__('There are no export file with such name %1', $fileName));
77+
}
78+
}
79+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1515
* @since 100.0.2
16+
* @deprecated
1617
*/
1718
class Export extends \Magento\ImportExport\Model\AbstractModel
1819
{

0 commit comments

Comments
 (0)