Commit 08d8c2b7 authored by Joe Parsons's avatar Joe Parsons
Browse files

Issue #2997360 by nedjo, joegraduate, claudiu.cristea: Add Drush command for...

Issue #2997360 by nedjo, joegraduate, claudiu.cristea: Add Drush command for the "reset" update mode.
parent f22435fa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,5 +6,6 @@ services:
      - '@config.storage'
      - '@config.manager'
      - '@config.import.commands'
      - '@state'
    tags:
      - { name: drush.command }
+36 −1
Original line number Diff line number Diff line
@@ -2,10 +2,12 @@

namespace Drupal\config_sync\Commands;

use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\config_sync\ConfigSyncListerInterface;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\State\StateInterface;
use Drush\Commands\DrushCommands;
use Drush\Drupal\Commands\config\ConfigCommands;
use Drush\Drupal\Commands\config\ConfigImportCommands;
@@ -44,6 +46,13 @@ class ConfigSyncCommands extends DrushCommands {
   */
  protected $configImportCommands;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a new ConfigSyncCommands object.
   *
@@ -55,13 +64,16 @@ class ConfigSyncCommands extends DrushCommands {
   *   The configuration manager.
   * @param \Drush\Drupal\Commands\config\ConfigImportCommands $configImportCommands
   *   The service containing Drush commands for regular core config imports.
   * @param \Drupal\Core\State\StateInterface $state.
   *   The state service.
   */
  public function __construct(ConfigSyncListerInterface $configSyncLister, StorageInterface $activeStorage, ConfigManagerInterface $configManager, ConfigImportCommands $configImportCommands) {
  public function __construct(ConfigSyncListerInterface $configSyncLister, StorageInterface $activeStorage, ConfigManagerInterface $configManager, ConfigImportCommands $configImportCommands, StateInterface $state) {
    parent::__construct();
    $this->configSyncLister = $configSyncLister;
    $this->activeStorage = $activeStorage;
    $this->configManager = $configManager;
    $this->configImportCommands = $configImportCommands;
    $this->state = $state;
  }

  /**
@@ -105,4 +117,27 @@ class ConfigSyncCommands extends DrushCommands {
    return new RowsOfFields($rows);
  }

  /**
   * Adds an option to the config-distro-update command.
   *
   * @hook option config-distro-update
   * @option update-mode Specify a mode for updates. Options are 1 (merge), 2 (partial reset), and 3 (full reset).
   * @usage drush config-distro-update --update-mode=2
   *   Run a config distro update with the update mode of 2 (partial reset).
   */
  public function optionsetConfigDistroUpdate($options = ['update-mode' => self::OPT]) {
  }

  /**
   * Sets the specified update mode in the state.
   *
   * @hook pre-command config-distro-update
   */
  public function preConfigDistroUpdate(CommandData $commandData) {
    $updateMode = $commandData->input()->getOption('update-mode');
    if (!empty($updateMode)) {
      $this->state->set('config_sync.update_mode', (int) $updateMode);
    }
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ interface ConfigSyncSnapshotterInterface {
  const SNAPSHOT_MODE_IMPORT = 'import';

  /**
   * Install snapshot mode.
   * Name of snapshot set for config_sync.
   */
  const CONFIG_SNAPSHOT_SET = 'config_sync';