deploy_8.inc

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

Functions

File

platform/drupal/deploy_8.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_8_replace($old_url, $new_url);
  20. _provision_platform_drupal_deploy_8_replace('default', $new_url);
  21. // Update files paths
  22. \Drupal::configFactory()->getEditable('system.file')
  23. ->set('path.private', "sites/$new_url/private/files")
  24. ->set('path.temporary', "sites/$new_url/private/temp")
  25. ->save();
  26. // Detect and update default site name, if needed
  27. $old_name = \Drupal::config('system.site')->get('name');
  28. if ($old_name == $old_url) {
  29. \Drupal::configFactory()->getEditable('system.site')
  30. ->set('name', "$new_url")
  31. ->save();
  32. }
  33. }
  34. function _provision_platform_drupal_deploy_8_replace($old_url, $new_url) {
  35. // Update absolute URLs to files for sites cloned/migrated/renamed in the multisite install.
  36. $replace_abs_patterns = array(
  37. ':old' => '//' . $old_url . '/sites/' . $old_url . '/files',
  38. ':new' => '//' . $new_url . '/sites/' . $new_url . '/files',
  39. );
  40. // Update paths for sites cloned/migrated/renamed in the multisite install.
  41. $replace_patterns = array(
  42. ':old' => 'sites/' . $old_url,
  43. ':new' => 'sites/' . $new_url,
  44. );
  45. if(db_table_exists('block_custom')) {
  46. db_query("UPDATE {block_custom} SET body = REPLACE(body, :old, :new)", $replace_abs_patterns);
  47. db_query("UPDATE {block_custom} SET body = REPLACE(body, :old, :new)", $replace_patterns);
  48. }
  49. if (function_exists('field_info_field_map')) {
  50. $field_map = field_info_field_map();
  51. foreach ($field_map as $key => $info) {
  52. $tablekey = db_escape_table($key);
  53. // Replace in all known text fields.
  54. if (in_array($info['type'], array('text_long', 'text_with_summary'))) {
  55. drush_log('Replacing in ' . $key, 'debug');
  56. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_abs_patterns);
  57. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_abs_patterns);
  58. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_patterns);
  59. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :old, :new)", $replace_patterns);
  60. }
  61. // Replace in the optional summary.
  62. if ($info['type'] == 'text_with_summary') {
  63. drush_log('Replacing summary in ' . $key, 'debug');
  64. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_abs_patterns);
  65. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_abs_patterns);
  66. db_query("UPDATE {field_data_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
  67. db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :old, :new)", $replace_patterns);
  68. }
  69. }
  70. }
  71. drush_log(
  72. dt('Changed paths from sites/@old_url to sites/@new_url',
  73. array('@old_url' => $old_url, '@new_url' => $new_url)));
  74. }