You are here

public function ConfigSyncCommands::syncUpdate in Configuration Synchronizer 8

Apply configuration updates.

@command config-sync-update @option discard-overrides The active configuration will be reverted to the new configuration state as defined by distributions and modules, discarding any changes that have been made in the active configuration. If this option is omitted, the overrides will be merged with the configuration updates. @usage drush config-sync-update Apply updates to all extensions. @aliases cs-update

File

src/Commands/ConfigSyncCommands.php, line 146

Class

ConfigSyncCommands
Drush integration for the Configuration Synchronizer module.

Namespace

Drupal\config_sync\Commands

Code

public function syncUpdate($options = [
  'discard-overrides' => FALSE,
]) {
  $this->configSyncInitializer
    ->initialize(!$options['discard-overrides']);
  $storage_comparer = new StorageComparer($this->mergedStorage, $this->activeStorage, $this->configManager);
  if (!$storage_comparer
    ->createChangelist()
    ->hasChanges()) {
    $this
      ->logger()
      ->notice('There are no changes to import.');
    return;
  }

  // Output the changes that will be performed to the config.
  $change_list = [];
  foreach ($storage_comparer
    ->getAllCollectionNames() as $collection) {
    $change_list[$collection] = $storage_comparer
      ->getChangelist(NULL, $collection);
  }
  $table = ConfigCommands::configChangesTable($change_list, $this
    ->io());
  $table
    ->render();
  if ($this
    ->io()
    ->confirm(dt('Import the listed configuration changes?'))) {

    // Import the config using the default Drush command.
    // @see \Drush\Drupal\Commands\config\ConfigImportCommands::doImport()
    $results = drush_op([
      $this->configImportCommands,
      'doImport',
    ], $storage_comparer);

    // Perform a clean snapshot refresh after the import.
    $this->configSyncSnapshotter
      ->deleteSnapshot();
    $this->configSyncSnapshotter
      ->refreshSnapshot();
    return $results;
  }
  throw new UserAbortException();
}