You are here

public function ConfigSplitCliService::ioImport in Configuration Split 8

Same name and namespace in other branches
  1. 2.0.x src/ConfigSplitCliService.php \Drupal\config_split\ConfigSplitCliService::ioImport()

Handle the import interaction.

Parameters

string|null $split: The split name to import, null for standard import.

\Symfony\Component\Console\Style\StyleInterface|\ConfigSplitDrush8Io $io: The $io interface of the cli tool calling.

callable $t: The translation function akin to t().

bool $confirmed: Whether the import is already confirmed by the console input.

File

src/ConfigSplitCliService.php, line 238

Class

ConfigSplitCliService
The CLI service class for interoperability.

Namespace

Drupal\config_split

Code

public function ioImport($split, $io, callable $t, $confirmed = FALSE) {
  if (!$split) {
    $io
      ->text('Please consider using `drush config:import` instead for importing all config.');
    $message = $t('Do a normal (including filters) config import?');
    $storage = $this->syncStorage;
    if (!$storage instanceof FilteredStorageInterface) {
      throw new \RuntimeException('Only importing splits is supported when not using Config Filter 8.x-1.x');
    }
  }
  else {
    $config_name = $this
      ->getSplitName($split);
    $filter = $this->configFilterManager
      ->getFilterInstance($this
      ->getPluginIdFromConfigName($config_name));

    // Filter the active storage so we only import the split.
    $storage = new FilteredStorage($this->activeStorage, [
      $filter,
    ]);
    $message = $t('The following directory will be used to merge config into the active storage:');
    $message .= "\n";
    $message .= $this
      ->getDestination($config_name);
    $message .= "\n";
    $message .= $t('Import the configuration?');
  }
  try {
    if ($confirmed || $io
      ->confirm($message)) {
      $status = $this
        ->import($storage);
      switch ($status) {
        case ConfigSplitCliService::COMPLETE:
          $io
            ->success($t("Configuration successfully imported."));
          break;
        case ConfigSplitCliService::NO_CHANGES:
          $io
            ->text($t("There are no changes to import."));
          break;
        case ConfigSplitCliService::ALREADY_IMPORTING:
          $io
            ->error($t("Another request may be synchronizing configuration already."));
          break;
        default:
          $io
            ->error($t("Something unexpected happened"));
          break;
      }
    }
  } catch (ConfigImporterException $e) {
    $io
      ->error($t('There have been errors importing: @errors', [
      '@errors' => strip_tags(implode("\n", $this
        ->getErrors())),
    ]));
  }
}