Skip to content

Commit ab81c24

Browse files
author
Rocket Web
authored
Merge pull request #3 from rocketweb/ICP-4_remove_all
adding removeAll flag [#4]
2 parents 1d9c7a6 + f1e261d commit ab81c24

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
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
}

Model/Service/DumpCmsDataService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public function __construct(
4949
$this->categoryList = $categoryList;
5050
}
5151

52-
public function execute(array $types, ?array $identifiers)
52+
public function execute(array $types, ?array $identifiers, bool $removeAll)
5353
{
5454
$varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
5555
$varPath = $this->directoryList->getPath(DirectoryList::VAR_DIR);
5656
$workingDirPath = $varPath . '/sync_cms_data';
57-
if ($varDirectory->isExist($workingDirPath)) {
57+
if ($varDirectory->isExist($workingDirPath) && $removeAll) {
5858
$varDirectory->delete($workingDirPath);
5959
}
6060

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ 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+
-r, --removeAll Flag to remove all existing data
3132
```
3233

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

8889
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!
90+
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)