function drush_config_merge

7.x config.drush.inc drush_config_merge($alias = '', $config_label = 'staging')

File

commands/core/config.drush.inc, line 692
Provides Configuration Management commands.

Code

function drush_config_merge($alias = '', $config_label = 'staging') {
  // Allow the user to provide a specific working branch to do live work on.
  $working_branch = drush_get_option('branch', FALSE);
  $working_branch_is_tmp = FALSE;
  if (!$working_branch) {
    $working_branch = 'drush-live-config-temp';
    $working_branch_is_tmp = TRUE;
  }

  // Use in log and commit messages
  $site_label = $alias;
  // If '$alias' is a 'sites' folder, then convert it into a site
  // specification, root#uri
  if (($alias[0] != '@') && is_dir(DRUPAL_ROOT . '/sites/' . $alias)) {
    $alias = DRUPAL_ROOT . "#$alias";
  }

  // Figure out what our base commit is going to be for this operation.
  $merge_info = array(
    'base' => drush_get_option('base', FALSE),
    'message' => drush_get_option('message', ''),
    'commit' => !drush_get_option('no-commit', FALSE),
    'git-transport' => drush_get_option('git', FALSE),
    'remote' => drush_get_option('remote', 'origin'),
    'tool' => drush_get_option('tool', ''),
    'temp' => drush_get_option('temp', ''),
    'config-label' => $config_label,
    'live-site' => $alias,
    'dev-site' => '@self',
    'live-config' => $working_branch,
    'dev-config' => 'drush-dev-config-temp',
    'autodelete-live-config' => $working_branch_is_tmp,
    'autodelete-dev-config' => TRUE,
    'commit_needed' => FALSE,
  );

  $result = _drush_cm_get_initial_vcs_state($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }
  $result = _drush_cm_prepare_for_export($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }
  $result = _drush_cm_export_remote_configuration_before_merge($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }

  // Copy the exported configuration from 'live-site', either via git pull or via rsync
  if ($merge_info['git-transport']) {
    $result = _drush_cm_copy_remote_configuration_via_git($merge_info);
  }
  else {
    $result = _drush_cm_copy_remote_configuration_via_rsync($merge_info);
  }
  if ($result === FALSE) {
    return FALSE;
  }

  // Exit if there were no changes from 'live-site'.
  if (empty($merge_info['changed_configuration_files'])) {
    drush_log(dt("No configuration changes on !site; nothing to do here.", array('!site' => $merge_info['live-site'])), 'ok');
    _drush_config_merge_cleanup($merge_info);
    return TRUE;
  }

  $result = _drush_cm_commit_transmitted_configuration_changes($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }

  $result = _drush_cm_prepare_for_local_configuration_export($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }
  $result = _drush_cm_export_local_configuration($merge_info);
  if ($result === FALSE) {
    return FALSE;
  }

  // Check to see if the export changed any files.  If it did not, then
  // skip the merge, and process only the config pulled in from the other site.
  // TODO: This needs to be a diff against the base commit.  In 'git' mode,
  // we probably want to just skip this test and always merge.  Maybe always do this?
  $configuration_path = _drush_cm_get_configuration_path($merge_info);
  $result = drush_shell_cd_and_exec($configuration_path, 'git status --porcelain .');
  if (!$result) {
    return drush_set_error('DRUSH_CONFIG_MERGE_FAILURE', dt("`git status` failed."));
  }
  $changed_configuration_files = drush_shell_exec_output();
  if (empty($changed_configuration_files)) {
    drush_log(dt("No configuration changes on !site; no merge necessary.", array('!site' => $merge_info['dev-site'])), 'ok');
  }
  else {
    $result = _drush_cm_merge_local_and_remote_configurations($merge_info);
  }
  if ($result === FALSE) {
    return FALSE;
  }
  $result = _drush_cm_merge_to_original_branch($merge_info);

  return $result;
}