deploy_7.inc

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

Functions

File

platform/drupal/deploy_7.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Update paths inside database content for sites cloned/migrated/renamed.
  6. */
  7. $new_url = drush_get_option('uri');
  8. $old_url = drush_get_option('old_uri');
  9. /**
  10. * @file
  11. * Handle site migration tasks for redeployed sites.
  12. * This is primarily to handle the rename of the sites
  13. * directories.
  14. */
  15. if ($new_url != $old_url) {
  16. $url_changed = TRUE;
  17. }
  18. if ($url_changed) {
  19. _provision_platform_drupal_deploy_7_replace($old_url, $new_url);
  20. _provision_platform_drupal_deploy_7_replace('default', $new_url);
  21. // Is the URI in the site_name?
  22. $site_name = variable_get('site_name');
  23. $old_url_pattern_short = '/' . preg_quote($old_url) . '/';
  24. if (preg_match($old_url_pattern_short, $site_name)) {
  25. variable_set('site_name', preg_replace($old_url_pattern_short, $new_url, $site_name));
  26. }
  27. }
  28. function _provision_platform_drupal_deploy_7_replace($old_url, $new_url) {
  29. // Update absolute URLs to files for sites cloned/migrated/renamed in the multisite install.
  30. $replace_abs_patterns = array(
  31. ':old' => '//' . $old_url . '/sites/' . $old_url . '/files',
  32. ':new' => '//' . $new_url . '/sites/' . $new_url . '/files',
  33. );
  34. // Update paths for sites cloned/migrated/renamed in the multisite install.
  35. $replace_patterns = array(
  36. ':old' => 'sites/' . $old_url,
  37. ':new' => 'sites/' . $new_url,
  38. );
  39. if(db_table_exists('block_custom')) {
  40. db_query("UPDATE {block_custom} SET body = REPLACE(body, :old, :new)", $replace_abs_patterns);
  41. db_query("UPDATE {block_custom} SET body = REPLACE(body, :old, :new)", $replace_patterns);
  42. }
  43. db_query("UPDATE {system} SET filename = REPLACE(filename, :old, :new)", $replace_patterns);
  44. if (function_exists('field_info_field_map')) {
  45. $field_map = field_info_field_map();
  46. foreach ($field_map as $key => $info) {
  47. $tablekey = db_escape_table($key);
  48. // Replace in all known text fields.
  49. if (in_array($info['type'], array('text_long', 'text_with_summary'))) {
  50. drush_log('Replacing in ' . $key, 'debug');
  51. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_abs_patterns);
  52. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_abs_patterns);
  53. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_patterns);
  54. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_patterns);
  55. }
  56. // Replace in the optional summary.
  57. if ($info['type'] == 'text_with_summary') {
  58. drush_log('Replacing summary in ' . $key, 'debug');
  59. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_abs_patterns);
  60. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_abs_patterns);
  61. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
  62. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
  63. }
  64. }
  65. }
  66. drush_log(
  67. dt('Changed paths from sites/@old_url to sites/@new_url',
  68. array('@old_url' => $old_url, '@new_url' => $new_url)));
  69. }