Skip to content

Commit d416993

Browse files
committed
fix export
1 parent f8a5ad8 commit d416993

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Controller/Adminhtml/Exporter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Backend\App\Action;
1111
use Magento\Framework\App\Filesystem\DirectoryList;
1212
use Magento\Framework\App\Response\Http\FileFactory;
13+
use Magento\Framework\Controller\Result\RedirectFactory;
1314
use Ronangr1\CmsImportExport\Api\ExporterInterface;
1415

1516
abstract class Exporter extends Action
@@ -21,14 +22,20 @@ abstract class Exporter extends Action
2122
public function __construct(
2223
Action\Context $context,
2324
protected readonly FileFactory $fileFactory,
24-
protected readonly ExporterInterface $exporter
25+
protected readonly ExporterInterface $exporter,
26+
protected readonly RedirectFactory $redirectFactory,
2527
) {
2628
parent::__construct($context);
2729
}
2830

2931
public function execute()
3032
{
3133
$id = (int) $this->getRequest()->getParam('id');
34+
if($id === 0) {
35+
$this->messageManager->addErrorMessage(__('You must save the entity before exporting.'));
36+
return $this->redirectFactory->create()->setPath('cms/*/new');
37+
}
38+
3239
[$fileName, $content, $mime] = $this->exporter->export($id, $this->type);
3340
return $this->fileFactory->create(
3441
$fileName, $content, DirectoryList::VAR_DIR, $mime

Model/Export/BlockExport.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
namespace Ronangr1\CmsImportExport\Model\Export;
99

10+
use Magento\Cms\Api\Data\BlockInterface;
1011
use Ronangr1\CmsImportExport\Model\Exporter;
1112

1213
class BlockExport extends Exporter
1314
{
1415
protected array $headers = [
15-
"block_id", "title", "identifier", "is_active", "content"
16+
BlockInterface::BLOCK_ID, BlockInterface::TITLE, BlockInterface::IDENTIFIER,
17+
BlockInterface::CONTENT, BlockInterface::CREATION_TIME, BlockInterface::UPDATE_TIME,
18+
BlockInterface::IS_ACTIVE
1619
];
1720
}

Model/Export/PageExport.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
namespace Ronangr1\CmsImportExport\Model\Export;
99

10+
use Magento\Cms\Api\Data\PageInterface;
1011
use Ronangr1\CmsImportExport\Model\Exporter;
1112

1213
class PageExport extends Exporter
1314
{
1415
protected array $headers = [
15-
"page_id", "title", "identifier", "is_active",
16-
"content_heading", "meta_keywords", "meta_description", "content"
16+
PageInterface::PAGE_ID, PageInterface::TITLE, PageInterface::IDENTIFIER, PageInterface::PAGE_LAYOUT,
17+
PageInterface::IS_ACTIVE, PageInterface::CONTENT_HEADING, PageInterface::META_KEYWORDS, PageInterface::META_DESCRIPTION,
18+
PageInterface::META_TITLE, PageInterface::CONTENT, PageInterface::CREATION_TIME, PageInterface::UPDATE_TIME, PageInterface::SORT_ORDER,
19+
PageInterface::LAYOUT_UPDATE_XML, PageInterface::CUSTOM_THEME, PageInterface::CUSTOM_ROOT_TEMPLATE,
20+
PageInterface::CUSTOM_LAYOUT_UPDATE_XML, PageInterface::CUSTOM_THEME_FROM, PageInterface::CUSTOM_THEME_TO,
1721
];
1822
}

Model/Exporter.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
private readonly IoFile $ioFile,
2828
private readonly FilterProvider $filterProvider,
2929
private readonly Config $config,
30-
private readonly ArchiveInterface $zip
30+
private readonly ArchiveInterface $zip,
3131
)
3232
{
3333
}
@@ -90,11 +90,22 @@ private function exportEntityCsv(string $type, int $id, $fp)
9090
'getId',
9191
'getTitle',
9292
'getIdentifier',
93+
'getPageLayout',
9394
'isActive',
9495
'getContentHeading',
9596
'getMetaKeywords',
9697
'getMetaDescription',
98+
'getMetaTitle',
9799
'getContent',
100+
'getCreationTime',
101+
'getUpdateTime',
102+
'getSortOrder',
103+
'getLayoutUpdateXml',
104+
'getCustomTheme',
105+
'getCustomRootTemplate',
106+
'getCustomLayoutUpdateXml',
107+
'getCustomThemeFrom',
108+
'getCustomThemeTo',
98109
],
99110
],
100111
'cms_block' => [
@@ -105,6 +116,8 @@ private function exportEntityCsv(string $type, int $id, $fp)
105116
'getIdentifier',
106117
'isActive',
107118
'getContent',
119+
'getCreationTime',
120+
'getUpdateTime'
108121
],
109122
],
110123
];

0 commit comments

Comments
 (0)