Skip to content

Commit b6ffbff

Browse files
author
Rocket Web
authored
Merge pull request #5 from rocketweb/ICP-7_import_all
adding importAll flag [#7]
2 parents ab81c24 + cf8c6aa commit b6ffbff

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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/ImportCmsDataService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ public function __construct(
4747
$this->pageFactory = $pageFactory;
4848
}
4949

50-
public function execute(array $types, ?array $identifiers)
50+
public function execute(array $types, ?array $identifiers, bool $importAll)
5151
{
5252
$workingDirPath = 'sync_cms_data';
5353

5454
if (!$this->directoryRead->isExist($this->varPath . $workingDirPath)) {
5555
throw new \Exception('The sync folder does not exists! Path: ' . $workingDirPath);
5656
}
5757

58+
if (!$identifiers && !$importAll) {
59+
throw new \Exception('If you want to import all entries at once, use --importAll flag');
60+
}
61+
5862
foreach ($types as $type) {
5963
$typeDirPath = $workingDirPath . sprintf('/cms/%ss/', $type);
6064
if (!$this->directoryRead->isExist($this->varPath . $typeDirPath)) {

README.md

Lines changed: 1 addition & 0 deletions
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+
-a, --importAll Flag to import all files
3132
-r, --removeAll Flag to remove all existing data
3233
```
3334

0 commit comments

Comments
 (0)