Commit 3d0d14a6 authored by Herman van Rink's avatar Herman van Rink
Browse files

Issue #2157785 by helmo: Deploy_7 code lacks functionality from D6 code.

parent 7c301fa4
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 *
 * Update paths inside database content for sites cloned/migrated/renamed.
 */

$new_url = drush_get_option('uri');
$old_url = drush_get_option('old_uri');

@@ -11,6 +17,48 @@ $old_url = drush_get_option('old_uri');
 */

if ($new_url != $old_url) {
  $url_changed  = TRUE;
}

if ($url_changed) {
  _provision_platform_drupal_deploy_7_replace($old_url, $new_url);
  _provision_platform_drupal_deploy_7_replace('default', $new_url);

  // Is the URI in the site_name?
  $site_name = variable_get('site_name');
  $old_url_pattern_short = '/' . preg_quote($old_url) . '/';
  if (preg_match($old_url_pattern_short, $site_name)) {
    variable_set('site_name', preg_replace($old_url_pattern_short, $new_url, $site_name));
  }
}

function _provision_platform_drupal_deploy_7_replace($old_url, $new_url) {
  // Update paths for sites cloned/migrated/renamed in the multisite install.
  $replace_patterns = array(
    ':old' => 'sites/' . $old_url,
    ':new' => 'sites/' . $new_url,
  );

  db_query("UPDATE {block_custom} SET body     = REPLACE(body,     :old, :new)", $replace_patterns);
  db_query("UPDATE {system}       SET filename = REPLACE(filename, :old, :new)", $replace_patterns);

  $field_map = field_info_field_map();
  foreach ($field_map as $key => $info) {
    $tablekey = db_escape_table($key);
    // Replace in all known text fields.
    if (in_array($info['type'], array('text_long', 'text_with_summary'))) {
      drush_log('Replacing in ' . $key, 'debug');
      db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_value     = REPLACE(${tablekey}_value,   :old, :new)", $replace_patterns);
      db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value,   :old, :new)", $replace_patterns);
    }

    // Replace in the optional summary.
    if ($info['type'] == 'text_with_summary') {
      drush_log('Replacing summary in ' . $key, 'debug');
      db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_summary     = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
      db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
    }
  }
  drush_log(
    dt('Changed paths from sites/@old_url to sites/@new_url',
    array('@old_url' => $old_url, '@new_url' => $new_url)));