Skip to content

Commit

Permalink
[config:import] Add skip-uuid option flag. (#3638)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas authored Jan 7, 2018
1 parent 0b89228 commit 5076f18
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Command/Config/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\StorageComparerInterface;

class ImportCommand extends Command
{
Expand Down Expand Up @@ -71,6 +71,12 @@ protected function configure()
InputOption::VALUE_NONE,
$this->trans('commands.config.import.options.remove-files')
)
->addOption(
'skip-uuid',
null,
InputOption::VALUE_NONE,
$this->trans('commands.config.import.options.skip-uuid')
)
->setAliases(['ci']);
}

Expand All @@ -81,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$directory = $input->getOption('directory');
$skipUuid = $input->getOption('skip-uuid');

if ($directory) {
$configSyncDir = $directory;
Expand All @@ -92,7 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output)

$source_storage = new FileStorage($configSyncDir);

$storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
$storageComparer = '\Drupal\Core\Config\StorageComparer';
if ($skipUuid) {
$storageComparer = '\Drupal\Console\Override\StorageComparer';
}

$storage_comparer = new $storageComparer(
$source_storage,
$this->configStorage,
$this->configManager
);

if (!$storage_comparer->createChangelist()->hasChanges()) {
$io->success($this->trans('commands.config.import.messages.nothing-to-do'));
Expand All @@ -106,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}


private function configImport(DrupalStyle $io, StorageComparer $storage_comparer)
private function configImport(DrupalStyle $io, StorageComparerInterface $storage_comparer)
{
$config_importer = new ConfigImporter(
$storage_comparer,
Expand All @@ -128,12 +144,10 @@ private function configImport(DrupalStyle $io, StorageComparer $storage_comparer
$config_importer->import();
return true;
} catch (ConfigImporterException $e) {
$message = $this->trans('commands.config.import.messages.import-fail') . "\n";
$message .= implode("\n", $config_importer->getErrors());
$io->error(
sprintf(
$this->trans('commands.site.import.local.messages.error-writing'),
$message
implode("\n", $config_importer->getErrors())
)
);
} catch (\Exception $e) {
Expand Down
15 changes: 15 additions & 0 deletions src/Override/StorageComparer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Drupal\Console\Override;

class StorageComparer extends \Drupal\Core\Config\StorageComparer
{

/**
* {@inheritdoc}
*/
public function validateSiteUuid()
{
return true;
}
}

0 comments on commit 5076f18

Please sign in to comment.