You are here

public function ConfigurationImportManager::import in Configuration Management 7.3

Import configurations into the database.

File

src/Helpers/ConfigurationImportManager.php, line 48
ConfigurationExportManager.php handles the export of configurations.

Class

ConfigurationImportManager

Namespace

Configuration\Helpers

Code

public function import() {
  $this
    ->readConfigurationsFile();
  $this
    ->findMissingModules();
  $this
    ->installMissingModules();

  // Register new handlers after install the modules.
  $this->configuration_manager
    ->registerHandlers();
  $this
    ->normalizeConfigurations();
  $ordered = $this
    ->resolveDependencies();
  $import_always = !$this->configuration_manager
    ->settings()
    ->get('import.import_only_if_hash_changed');
  foreach ($ordered as $identifier) {
    $db_hash = $this->configuration_manager
      ->getHash($identifier);
    $file_hash = $this->configuration_on_filesystem[$identifier]['hash'];
    if ($db_hash != $file_hash || $import_always) {
      $configuration = $this->cache[$identifier];
      $handler = $this->configuration_manager
        ->getHandlerFromIdentifier($identifier);
      echo "importing... " . $configuration
        ->getIdentifier() . "\n";
      $handler
        ->writeToDatabase($configuration);
    }
    else {
      echo "Skiping import of {$identifier}. It hash has not changed.";
    }
  }
}