Skip to content

Commit cdaaaba

Browse files
author
Rocket Web
authored
Merge branch 'main' into ICP-3-stores_support
2 parents a79a945 + b6ffbff commit cdaaaba

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

Console/Command/DumpCmsData.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DumpCmsData extends \Symfony\Component\Console\Command\Command
2525
private const INPUT_KEY_TYPE = 'type';
2626
private const INPUT_TYPE_VALUES = ['block', 'page', 'all'];
2727
private const INPUT_KEY_IDENTIFIER = 'identifier';
28+
private const INPUT_KEY_REMOVE_ALL = 'removeAll';
2829
private \RocketWeb\CmsImportExport\Model\Service\DumpCmsDataService $dumpCmsDataService;
2930

3031
public function __construct(
@@ -51,6 +52,12 @@ protected function configure()
5152
'i',
5253
InputOption::VALUE_OPTIONAL,
5354
'identifier to process (one or CSV list)'
55+
),
56+
new InputOption(
57+
self::INPUT_KEY_REMOVE_ALL,
58+
'r',
59+
InputOption::VALUE_NONE,
60+
'Flag to remove all existing data'
5461
)
5562
]);
5663
parent::configure();
@@ -59,6 +66,7 @@ protected function configure()
5966
protected function execute(InputInterface $input, OutputInterface $output): void
6067
{
6168
$type = $input->getOption(self::INPUT_KEY_TYPE);
69+
$removeAll = (bool)$input->getOption(self::INPUT_KEY_REMOVE_ALL);
6270
if ($type === null) {
6371
throw new \RuntimeException("Type ([-t|--type) is required");
6472
}
@@ -78,6 +86,6 @@ protected function execute(InputInterface $input, OutputInterface $output): void
7886
$identifiers = explode(',', $identifiers);
7987
}
8088

81-
$this->dumpCmsDataService->execute($types, $identifiers);
89+
$this->dumpCmsDataService->execute($types, $identifiers, $removeAll);
8290
}
8391
}

Console/Command/ImportCmsData.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ImportCmsData extends \Symfony\Component\Console\Command\Command
2727
private const INPUT_KEY_TYPE = 'type';
2828
private const INPUT_TYPE_VALUES = ['block', 'page', 'all'];
2929
private const INPUT_KEY_IDENTIFIER = 'identifier';
30+
private const INPUT_KEY_IMPORT_ALL = 'importAll';
3031
private \RocketWeb\CmsImportExport\Model\Service\ImportCmsDataService $importCmsDataService;
3132

3233
public function __construct(
@@ -53,6 +54,12 @@ protected function configure()
5354
'i',
5455
InputOption::VALUE_OPTIONAL,
5556
'identifier to process (one or CSV list)'
57+
),
58+
new InputOption(
59+
self::INPUT_KEY_IMPORT_ALL,
60+
'a',
61+
InputOption::VALUE_NONE,
62+
'Flag to import all files'
5663
)
5764
]);
5865
parent::configure();
@@ -61,6 +68,7 @@ protected function configure()
6168
protected function execute(InputInterface $input, OutputInterface $output): void
6269
{
6370
$type = $input->getOption(self::INPUT_KEY_TYPE);
71+
$importAll = (bool)$input->getOption(self::INPUT_KEY_IMPORT_ALL);
6472
if ($type === null) {
6573
throw new \RuntimeException("Type ([-t|--type) is required");
6674
}
@@ -80,6 +88,6 @@ protected function execute(InputInterface $input, OutputInterface $output): void
8088
$identifiers = explode(',', $identifiers);
8189
}
8290

83-
$this->importCmsDataService->execute($types, $identifiers);
91+
$this->importCmsDataService->execute($types, $identifiers, $importAll);
8492
}
8593
}

Model/Service/DumpCmsDataService.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function __construct(
5353
$this->storeManager = $storeManager;
5454
}
5555

56-
public function execute(array $types, ?array $identifiers)
56+
public function execute(array $types, ?array $identifiers, bool $removeAll)
5757
{
5858
$varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
5959
$varPath = $this->directoryList->getPath(DirectoryList::VAR_DIR);
6060
$workingDirPath = $varPath . '/sync_cms_data';
61-
if ($varDirectory->isExist($workingDirPath)) {
61+
if ($varDirectory->isExist($workingDirPath) && $removeAll) {
6262
$varDirectory->delete($workingDirPath);
6363
}
6464

@@ -130,6 +130,9 @@ private function dumpPages(string $path, WriteInterface $varDirectory, ?array $i
130130
'content_heading' => $page->getContentHeading(),
131131

132132
];
133+
if ($page->getIsTailwindcssJitEnabled() !== null) {
134+
$jsonContent['is_tailwindcss_jit_enabled'] = $page->getIsTailwindcssJitEnabled();
135+
}
133136
$this->write($varDirectory, $jsonPath, $this->serializer->serialize($jsonContent));
134137
}
135138
}
@@ -162,6 +165,9 @@ private function dumpBlocks(string $path, WriteInterface $varDirectory, ?array $
162165
'stores' => $storeCodes,
163166
'is_active' => $block->isActive()
164167
];
168+
if ($block->getIsTailwindcssJitEnabled() !== null) {
169+
$jsonContent['is_tailwindcss_jit_enabled'] = $block->getIsTailwindcssJitEnabled();
170+
}
165171
$this->write($varDirectory, $jsonPath, $this->serializer->serialize($jsonContent));
166172
}
167173
}

Model/Service/ImportCmsDataService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ public function __construct(
5151
$this->storeRepository = $storeRepository;
5252
}
5353

54-
public function execute(array $types, ?array $identifiers)
54+
public function execute(array $types, ?array $identifiers, bool $importAll)
5555
{
5656
$workingDirPath = 'sync_cms_data';
5757

5858
if (!$this->directoryRead->isExist($this->varPath . $workingDirPath)) {
5959
throw new \Exception('The sync folder does not exists! Path: ' . $workingDirPath);
6060
}
6161

62+
if (!$identifiers && !$importAll) {
63+
throw new \Exception('If you want to import all entries at once, use --importAll flag');
64+
}
65+
6266
foreach ($types as $type) {
6367
$typeDirPath = $workingDirPath . sprintf('/cms/%ss/', $type);
6468
if (!$this->directoryRead->isExist($this->varPath . $typeDirPath)) {
@@ -129,6 +133,10 @@ private function importBlocks(string $dirPath, ?array $identifiers): void
129133
$block->setIdentifier($jsonData['identifier']);
130134
$block->setIsActive((bool)$jsonData['is_active']);
131135
$block->setStores($storeIds);
136+
if (isset($jsonData['is_tailwindcss_jit_enabled'])) {
137+
$block->setIsTailwindcssJitEnabled($jsonData['is_tailwindcss_jit_enabled']);
138+
}
139+
132140
try {
133141
$this->blockRepository->save($block);
134142
} catch (\Exception $exception) {
@@ -178,6 +186,9 @@ private function importPages(string $dirPath, ?array $identifiers): void
178186
$page->setContentHeading($jsonData['content_heading']);
179187
$page->setIsActive((bool)$jsonData['is_active']);
180188
$page->setStores($storeIds);
189+
if (isset($jsonData['is_tailwindcss_jit_enabled'])) {
190+
$page->setIsTailwindcssJitEnabled($jsonData['is_tailwindcss_jit_enabled']);
191+
}
181192

182193
try {
183194
$this->pageRepository->save($page);

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Dumps cms pages/blocks to var/sync_cms_data for further import
2828
Options:
2929
-t, --type=TYPE Which type are we dumping - block/page/all
3030
-i, --identifier[=IDENTIFIER] identifier to process (one or CSV list)
31+
-a, --importAll Flag to import all files
32+
-r, --removeAll Flag to remove all existing data
3133
```
3234

3335
As you can see from the options, we need to define:
@@ -86,4 +88,4 @@ With the combination of these two, we can **import**:
8688
- specific CMS block or blocks (using --type=block --identifier=who-are-we,homepage-carousel)
8789

8890
Once you execute the command, the content will be created/updated in Magento Admin.
89-
By executing `php bin/magento cache:flush` you should be able to see the updated CMS content on frontend also!
91+
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)