Skip to content

Commit eb1919b

Browse files
committed
IP-314 Expand the CMS import / export module to cover store blocks/pages
1 parent e767da6 commit eb1919b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Model/Service/ImportCmsDataService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function getStoreIds($storeCodes): array
101101
return $storeIds;
102102
}
103103

104-
private function importBlocks(string $dirPath, ?array $identifiers, ?string $storeCode): void
104+
private function importBlocks(string $dirPath, ?array $identifiers, ?string $storeCode = null): void
105105
{
106106
$filePaths = $this->directoryRead->read($this->varPath . $dirPath);
107107
foreach ($filePaths as $filePath) {
@@ -161,7 +161,7 @@ private function importBlocks(string $dirPath, ?array $identifiers, ?string $sto
161161
}
162162
}
163163

164-
private function importPages(string $dirPath, ?array $identifiers, ?string $storeCode): void
164+
private function importPages(string $dirPath, ?array $identifiers, ?string $storeCode = null): void
165165
{
166166
$filePaths = $this->directoryRead->read($this->varPath . $dirPath);
167167
foreach ($filePaths as $filePath) {
@@ -221,7 +221,7 @@ private function importPages(string $dirPath, ?array $identifiers, ?string $stor
221221
try {
222222
$this->pageRepository->save($page);
223223
} catch (\Exception $exception) {
224-
echo $exception->getMessage() . ' | Block ID: ' . $identifier . "\n";
224+
echo $exception->getMessage() . ' | Page ID: ' . $identifier . "\n";
225225
}
226226
}
227227
}

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,21 @@ Import cms pages/blocks from var/sync_cms_data
8080
Options:
8181
-t, --type=TYPE Which type are we importing - block/page/all
8282
-i, --identifier[=IDENTIFIER] identifier to process (one or CSV list)
83+
-a, --importAll Flag to import all files
84+
-s, --store[STORE_CODE] Store code to process only pages/blocks specific to this store
8385
```
8486

8587
This command works by using files in `var/sync_cms_data/cms/` path. As you can see from the options, we need to define:
86-
- type - which can be CMS block, CMS page or both - **required**
88+
- type - which can be CMS block or CMS page - **required**
8789
- identifier - either a CMS block or CMS page identifier - **optional**
88-
90+
There are optional parameters:
91+
- importAll - when identifiers not specified we'll import all blocks or pages
92+
- store - store code (like default) to import block(s)/pages(s) only for specific store
8993
With the combination of these two, we can **import**:
90-
- all CMS content (using --type=all)
91-
- all CMS pages (using --type=page)
92-
- all CMS blocks (using --type=block)
93-
- specific CMS page or pages (using --type=page --identifier=about-us.html,homepage-new)
94+
- all CMS pages (using --type=page and importAll)
95+
- all CMS blocks (using --type=block and importAll)
96+
- specific CMS page or pages (using --type=page --identifier=about-us,homepage-new)
9497
- specific CMS block or blocks (using --type=block --identifier=who-are-we,homepage-carousel)
95-
98+
- specific CMS page by store (using --type=page --identifier=about-us-default --store=default)
9699
Once you execute the command, the content will be created/updated in Magento Admin.
97100
By executing `php bin/magento cache:flush` you should be able to see the updated CMS content on frontend also!

0 commit comments

Comments
 (0)