You are here

protected function ConfigFeaturesImporterService::import in Config Importer and Tools 8

Same name and namespace in other branches
  1. 8.2 src/ConfigFeaturesImporterService.php \Drupal\config_import\ConfigFeaturesImporterService::import()

Import/revert a package.

Parameters

Package $package: Package definition.

1 call to ConfigFeaturesImporterService::import()
ConfigFeaturesImporterService::importFeatures in src/ConfigFeaturesImporterService.php
Import features.

File

src/ConfigFeaturesImporterService.php, line 113

Class

ConfigFeaturesImporterService
Class ConfigFeaturesImporterService.

Namespace

Drupal\config_import

Code

protected function import(Package $package) {
  $missing = $this->featuresManager
    ->reorderMissing($this->featuresManager
    ->detectMissing($package));
  $overrides = $this->featuresManager
    ->detectOverrides($package, TRUE);
  $this->featuresAssigner
    ->assignConfigPackages();
  $configs = $this->featuresManager
    ->getConfigCollection();
  foreach ($missing + $overrides as $config_name) {
    if (isset($configs[$config_name])) {
      $item = $configs[$config_name];
      $message = 'Failed to revert the "@config_name" configuration.';
      if ($this->configRevert
        ->revert(ConfigurationItem::fromConfigStringToConfigType($item
        ->getType()), $item
        ->getShortName())) {
        $message = 'The "@config_name" configuration have been reverted.';
      }
    }
    else {
      $item = $this->featuresManager
        ->getConfigType($config_name);
      $message = 'Failed to import the "@config_name" configuration.';
      if ($this->configRevert
        ->import(ConfigurationItem::fromConfigStringToConfigType($item['type']), $item['name_short'])) {
        $message = 'The "@config_name" configuration have been imported.';
      }
    }
    $this->loggerChannel
      ->info($message, [
      '@name' => $config_name,
    ]);
  }
}