You are here

function configuration_import_directory in Configuration Management 7.2

Import all configuration files within a directory.

The configurations files in the directory have to match the migration estructure of configurations. See http://drupal.org/node/1872288 for clarification of migration vs sync process.

Parameters

$path: The path to the directory to import.

$enable_modules: Enable all the required modules before the import process.

$include_dependencies: Process a component and all its dependencies.

$include_optionals: Process a component and all its optionals.

$start_tracking: Start tracking all imported configurations.

File

./configuration.module, line 76
API for Configuration Management module.

Code

function configuration_import_directory($path, $enable_modules = TRUE, $include_dependencies = TRUE, $include_optionals = TRUE, $start_tracking = TRUE) {
  $path = rtrim($path, '/');
  $file_content = drupal_substr(file_get_contents($path . '/configurations.inc'), 6);

  // this line creates a $configurations array with a list of components and a
  // $modules array with a list of required modules to be enabled.
  @eval($file_content);
  if ($enable_modules) {
    $settings = ConfigurationManagement::discoverRequiredModules($modules);
    $missing = $settings
      ->getInfo('modules_missing');
    if (count($missing)) {
      $missing = implode(', ', $missing);
      drupal_set_message(t('The following modules are required to import the specified configurations but are not available to install: %modules', array(
        '%modules' => $missing,
      )), 'error');
      return FALSE;
    }
    else {
      $to_install = $settings
        ->getInfo('modules_to_install');
      module_enable($to_install);
    }
  }
  $result = ConfigurationManagement::importToActiveStore($configurations, $include_dependencies, $include_optionals, FALSE, $path);
  $imported = $result
    ->getInfo('imported');
  if ($start_tracking) {
    $tracked = ConfigurationManagement::startTracking($configurations, $include_dependencies, $include_optionals);
  }
  if (is_array($imported) && count($imported) > 0) {
    return $imported;
  }
  else {
    return FALSE;
  }
}