You are here

function _configuration_sync in Configuration Management 7.2

1 string reference to '_configuration_sync'
configuration_drush_command in ./configuration.drush.inc
Implements of hook_drush_command().

File

./configuration.drush.inc, line 418
configuration.drush.inc Let you perform configuration actions from the console.

Code

function _configuration_sync() {
  $tracking_file = ConfigurationManagement::readTrackingFile();
  $to_track = array_keys($tracking_file['tracked']);
  $modules_results = ConfigurationManagement::discoverRequiredModules($tracking_file['modules']);
  $missing_modules = $modules_results
    ->getInfo('missing_modules');
  if (!empty($missing_modules)) {
    drush_log(dt('Configurations cannot be synchronized because the following modules are not available to install: %modules', array(
      '%modules' => implode(', ', $missing_modules),
    )), 'error');
    $error = TRUE;
  }
  else {
    $modules_to_install = $modules_results
      ->getInfo('modules_to_install');
    drush_log(dt('The following will be enabled: %modules', array(
      '%modules' => implode(', ', $modules_to_install),
    )));
    if (!empty($modules_to_install)) {
      module_enable($modules_to_install, TRUE);
      drush_log(dt('The following modules have been enabled: %modules', array(
        '%modules' => implode(', ', $modules_to_install),
      )));
    }
  }

  // If we have to stop tracking some configurations, figure out which
  // configurations have to be untracked.
  if (!drush_get_option('preserve-tracked')) {
    $being_tracked = array_keys(ConfigurationManagement::trackedConfigurations(FALSE));
    $to_untrack = array_diff($being_tracked, $to_track);
    $un_track_results = ConfigurationManagement::stopTracking($to_untrack, TRUE, TRUE);
    if (count($un_track_results
      ->getInfo('untracked'))) {
      foreach ($un_track_results
        ->getInfo('untracked') as $untracked_config) {
        drush_log(dt('Untracked %config', array(
          '%config' => $untracked_config,
        )));
      }
    }
  }
  $results = ConfigurationManagement::importToActiveStore($to_track, FALSE, FALSE, TRUE);
  foreach ($results
    ->getInfo('imported') as $imported) {
    drush_log(dt('Imported !config', array(
      '!config' => $imported,
    )), 'ok');
  }
  foreach ($results
    ->getInfo('no_handler') as $failed) {
    drush_log(dt('!config could be imported because there is no module that can handle that configuration.', array(
      '!config' => $failed,
    )), 'error');
  }
}