function ConfigImportCommand::__invoke

Export the configuration.

Parameters

\Symfony\Component\Console\Style\SymfonyStyle $io: The symfony style.

bool $yes: The command option to skip the confirmation question.

Return value

int The command result.

File

core/lib/Drupal/Core/Config/Command/ConfigImportCommand.php, line 55

Class

ConfigImportCommand
Import configuration.

Namespace

Drupal\Core\Config\Command

Code

public function __invoke(SymfonyStyle $io, #[Option(description: 'Answer the confirmation question with yes.', shortcut: 'y')] bool $yes = FALSE) : int {
  // Do the import storage transformation.
  $import = $this->transformer
    ->transform($this->sync);
  $comparer = new StorageComparer($import, $this->active);
  $comparer->createChangelist();
  if (!$comparer->hasChanges()) {
    $io->success((string) $this->t('There are no changes to import.'));
    return self::SUCCESS;
  }
  $this->renderTable($comparer, $io);
  if (!$yes && !$io->confirm((string) $this->t('Import the listed configuration changes?'))) {
    throw new UserAbortException('Cancelled');
  }
  $importer = $this->importerFactory
    ->get($comparer);
  if ($importer->alreadyImporting()) {
    $io->warning((string) $this->t('Another request may be synchronizing configuration already.'));
    return Command::FAILURE;
  }
  try {
    $importer->validate();
    $importer->import();
  } catch (ConfigImporterException $e) {
    $io->error($e->getMessage());
    return Command::FAILURE;
  }
  $errors = $importer->getErrors();
  if (empty($errors)) {
    $io->success((string) $this->t('The configuration was imported successfully.'));
    return Command::SUCCESS;
  }
  $io->error((string) $this->t('The configuration was imported with errors.'));
  foreach ($errors as $error) {
    $io->error((string) $error);
  }
  return Command::FAILURE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.