You are here

protected function ConfigurationImportManager::resolveDependencies in Configuration Management 7.3

1 call to ConfigurationImportManager::resolveDependencies()
ConfigurationImportManager::import in src/Helpers/ConfigurationImportManager.php
Import configurations into the database.

File

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

Class

ConfigurationImportManager

Namespace

Configuration\Helpers

Code

protected function resolveDependencies() {

  // Validate that all the items defined to be imported can actually be imported
  // At the same time, start to discover dependencies and finally if everything
  // is ok, build the list of configurations to import sorted by import order.
  $resolver = new DependencyResolver();
  $exclude = $this->configuration_manager
    ->settings()
    ->get('import.exclude');
  $already_proccessed = array();
  $not_procesed_yet = $this->configurations_to_import
    ->keys();
  $import_parts = $this->configuration_manager
    ->settings()
    ->get('import.import_parts');
  while (!empty($not_procesed_yet)) {
    $identifier = array_pop($not_procesed_yet);
    if (!isset($this->configuration_on_filesystem[$identifier])) {
      throw new \Exception("{$identifier} cannot be imported. There is no data defined for it in configurations.json");
    }
    else {
      $already_proccessed[$identifier] = TRUE;
      if (!isset($exclude[$identifier]) && !isset($this->cache[$identifier])) {
        $handler = $this->configuration_manager
          ->getHandlerFromIdentifier($identifier);
        $path = $this->configuration_on_filesystem[$identifier]['path'];
        $configuration = $handler
          ->import($path);

        // Apply proccesors on reverse mode.
        $this
          ->alterConfiguration($configuration);
        $this->cache[$identifier] = $configuration;
        $resolver
          ->addComponent($configuration
          ->getIdentifier(), $configuration
          ->getDependencies());

        // Add its dependencies to the list of not proccesed
        foreach ($configuration
          ->getDependencies() as $dependency) {
          if (empty($already_proccessed[$dependency])) {
            $not_procesed_yet[] = $dependency;
          }
        }
        if ($import_parts) {

          // Add its dependencies to the list of not proccesed
          foreach ($configuration
            ->getParts() as $part) {
            if (empty($already_proccessed[$part])) {
              $not_procesed_yet[] = $part;
            }
          }
        }
      }
    }
  }
  $ordered = array();
  try {

    // The list of Configurations sorted by order of import.
    $ordered = $resolver
      ->resolveDependencies();
  } catch (\Exception $e) {
    if ($e
      ->getMessage() == "Circular dependency detected") {
      return FALSE;
    }
    if (strpos($e
      ->getMessage(), "There is a component not defined") !== FALSE) {
      return FALSE;
    }
  }
  return $ordered;
}