Skip to content

Commit

Permalink
Add --recursive option for config Import
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksold committed Feb 10, 2021
1 parent 701ee5c commit f86c816
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ protected function configure()
'Do not clear cache after config data import.'
);

$this->addOption(
'recursive',
'r',
InputOption::VALUE_NONE,
'Recursively go over subdirectories and import configs.'
);

parent::configure();
}

Expand Down Expand Up @@ -147,13 +154,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$folder = $input->getArgument('folder');
$baseFolder = $input->getOption('base');
$environment = $input->getArgument('environment');
$depth = ($input->getOption('recursive') === false) ? '0' : '>= 1';

// Configure the finder
$finder = $this->finder;
$finder->setFolder($folder);
$finder->setBaseFolder($baseFolder);
$finder->setEnvironment($environment);
$finder->setFormat($format);
$finder->setDepth($depth);

// Process the import
$this->importProcessor->setFormat($format);
Expand Down
17 changes: 15 additions & 2 deletions Model/File/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ class Finder implements FinderInterface
*/
private $environment;

/**
* @var string
*/
private $depth;

/**
* @return array
*/
public function find()
{
$baseFiles = $this->search($this->folder . DIRECTORY_SEPARATOR . $this->baseFolder . DIRECTORY_SEPARATOR);
$baseFiles = $this->search($this->folder . DIRECTORY_SEPARATOR . $this->baseFolder . DIRECTORY_SEPARATOR, $this->depth);
if (0 === count($baseFiles)) {
throw new \InvalidArgumentException('No base files found for format: *.' . $this->format);
}
Expand All @@ -49,7 +54,7 @@ public function find()
$envFiles = [];
foreach ($this->environment as $envPath) {
$fullEnvPath .= $envPath . DIRECTORY_SEPARATOR;
$find = $this->search($this->folder . DIRECTORY_SEPARATOR . $fullEnvPath, '0');
$find = $this->search($this->folder . DIRECTORY_SEPARATOR . $fullEnvPath, $this->depth);
$envFiles = array_merge($envFiles, $find);
}

Expand Down Expand Up @@ -130,4 +135,12 @@ private function search($path, $depth = null)

return $files;
}

/**
* @param string $depth
*/
public function setDepth($depth): void
{
$this->depth = $depth;
}
}
5 changes: 5 additions & 0 deletions Model/File/FinderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public function setBaseFolder($baseFolder);
* @param mixed $format
*/
public function setFormat($format);

/**
* @param mixed $depth
*/
public function setDepth($depth);
}
5 changes: 3 additions & 2 deletions docs/config-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $ php bin/magento config:data:import --help
--base Base folder name (default: "base")
--format (-m) Format: yaml, json (Default: yaml) (default: "yaml")
--no-cache Do not clear cache after config data import.
--recursive (-r) Recursively go over subdirectories and import configs.
```
:exclamation: Only use the `no-cache` option if you clear the cache afterwards, e.g. in a deployment process. Otherwise the changes will have no effect.
Expand Down Expand Up @@ -49,9 +50,9 @@ magento_root
└── pub
```
To import my ([@therouv](https://github.com/therouv)) specific Magento configuration settings,
To import my ([@therouv](https://github.com/therouv)) specific Magento configuration settings,
I would run the following command in the "magento_root" directory:
```bash
```bash
php bin/magento config:data:import config/store dev/therouv
```

0 comments on commit f86c816

Please sign in to comment.