You are here

function drush_config_import_import in Config Importer and Tools 8.0

Same name and namespace in other branches
  1. 8.2 config_import.drush.inc \drush_config_import_import()
  2. 8 config_import.drush.inc \drush_config_import_import()

Implements drush_COMMAND().

File

./config_import.drush.inc, line 196
Drush integration.

Code

function drush_config_import_import() {
  try {

    // Do not forget:
    // - the "destination" option will contain fully qualified path to file;
    // - the "name" option will be prefixed by configuration prefix;
    $options = _drush_config_import_get_options();
    if (!file_exists($options['destination'])) {
      throw new RuntimeException(dt('The "@destination" file with configuration does not exists!', [
        '@destination' => $options['destination'],
      ]));
    }
    $import_confirmed = drush_confirm(dt('Do you confirm an import of configuration from the "@destination" file?', [
      '@destination' => $options['destination'],
    ]));
    if ($import_confirmed) {
      Drupal::service('config_import.importer')
        ->importConfigs([
        $options['destination'],
      ]);
      $message = dt('The "@name" configuration has been successfully imported.', [
        '@name' => $options['name'],
      ]);
    }
    else {
      $message = dt('Import of the "@name" configuration has been canceled.', [
        '@name' => $options['name'],
      ]);
    }
    drush_log($message, 'status');
  } catch (Exception $e) {
    drush_log($e
      ->getMessage(), 'error');
  }
}