|
8 | 8 | use Drush\Commands\DrushCommands; |
9 | 9 | use Drush\Drush; |
10 | 10 | use Drush\Exceptions\UserAbortException; |
11 | | -use Drush\Log\LogLevel; |
12 | 11 | use Drupal\Core\Config\FileStorage; |
13 | | -use Consolidation\SiteAlias\SiteAliasManager; |
14 | 12 | use Consolidation\SiteAlias\SiteAliasManagerAwareInterface; |
15 | 13 | use Consolidation\SiteAlias\SiteAliasManagerAwareTrait; |
16 | 14 | use Drush\Sql\SqlBase; |
@@ -237,17 +235,10 @@ public function validate(CommandData $commandData) |
237 | 235 | } |
238 | 236 |
|
239 | 237 | if ($config = $commandData->input()->getOption('config-dir')) { |
240 | | - if (!file_exists($config)) { |
241 | | - throw new \Exception('The config source directory does not exist.'); |
242 | | - } |
243 | | - if (!is_dir($config)) { |
244 | | - throw new \Exception('The config source is not a directory.'); |
245 | | - } |
246 | | - // Skip config import with a warning if specified config dir is empty. |
247 | | - if (!$this->hasConfigFiles($config)) { |
248 | | - $this->logger()->warning(dt('Configuration import directory @config does not contain any configuration; will skip import.', ['@config' => $config])); |
249 | | - $commandData->input()->setOption('config-dir', ''); |
250 | | - } |
| 238 | + $this->validateConfigDir($commandData, $config); |
| 239 | + } |
| 240 | + if ($existing = $commandData->input()->getOption('existing-config')) { |
| 241 | + $this->validateConfigDir($commandData, $existing); |
251 | 242 | } |
252 | 243 |
|
253 | 244 | try { |
@@ -436,4 +427,26 @@ public function serverGlobals($drupal_base_url) |
436 | 427 | $_SERVER['HTTP_USER_AGENT'] = null; |
437 | 428 | $_SERVER['SCRIPT_FILENAME'] = DRUPAL_ROOT . '/index.php'; |
438 | 429 | } |
| 430 | + |
| 431 | + /** |
| 432 | + * Assure that a config directory exists and is populated. |
| 433 | + * |
| 434 | + * @param CommandData $commandData |
| 435 | + * @param $directory |
| 436 | + * @throws \Exception |
| 437 | + */ |
| 438 | + protected function validateConfigDir(CommandData $commandData, $directory) |
| 439 | + { |
| 440 | + if (!file_exists($directory)) { |
| 441 | + throw new \Exception(dt('The config source directory @config does not exist.', ['@config' => $directory])); |
| 442 | + } |
| 443 | + if (!is_dir($directory)) { |
| 444 | + throw new \Exception(dt('The config source @config is not a directory.', ['@config' => $directory])); |
| 445 | + } |
| 446 | + // Skip config import with a warning if specified config dir is empty. |
| 447 | + if (!$this->hasConfigFiles($directory)) { |
| 448 | + $this->logger()->warning(dt('Configuration import directory @config does not contain any configuration; will skip import.', ['@config' => $directory])); |
| 449 | + $commandData->input()->setOption('config-dir', ''); |
| 450 | + } |
| 451 | + } |
439 | 452 | } |
0 commit comments