deploy.inc

Handle site migration tasks for redeployed sites. This is primarily to handle the rename of the sites directories.

File

platform/drupal/deploy.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Handle site migration tasks for redeployed sites.
  5. * This is primarily to handle the rename of the sites
  6. * directories.
  7. */
  8. $new_url = d()->uri;
  9. $old_url = drush_get_option('old_uri', $new_url, 'cli');
  10. $old_url_pattern = '/^' . preg_quote('sites/' . $old_url, '/') . '/';
  11. $old_url_abs = '//' . $old_url . '/sites/' . $old_url . '/files';
  12. $new_url_abs = '//' . $new_url . '/sites/' . $new_url . '/files';
  13. // Update paths for sites migrated from standalone to the multisite install.
  14. db_query("UPDATE {files} SET filepath = REPLACE(filepath, 'sites/default', 'sites/%s')", $new_url);
  15. db_query("UPDATE {users} SET picture = REPLACE(picture, 'sites/default', 'sites/%s')", $new_url);
  16. db_query("UPDATE {boxes} SET body = REPLACE(body, 'sites/default', 'sites/%s')", $new_url);
  17. db_query("UPDATE {node_revisions} SET body = REPLACE(body, 'sites/default', 'sites/%s')", $new_url);
  18. db_query("UPDATE {node_revisions} SET teaser = REPLACE(teaser, 'sites/default', 'sites/%s')", $new_url);
  19. // Update absolute URLs to files for sites cloned/migrated/renamed in the multisite install.
  20. db_query("UPDATE {files} SET filepath = REPLACE(filepath, '%s', '%s')", $old_url_abs, $new_url_abs);
  21. db_query("UPDATE {users} SET picture = REPLACE(picture, '%s', '%s')", $old_url_abs, $new_url_abs);
  22. db_query("UPDATE {boxes} SET body = REPLACE(body, '%s', '%s')", $old_url_abs, $new_url_abs);
  23. db_query("UPDATE {node_revisions} SET body = REPLACE(body, '%s', '%s')", $old_url_abs, $new_url_abs);
  24. db_query("UPDATE {node_revisions} SET teaser = REPLACE(teaser, '%s', '%s')", $old_url_abs, $new_url_abs);
  25. // Update paths for sites cloned/migrated/renamed in the multisite install.
  26. db_query("UPDATE {files} SET filepath = REPLACE(filepath, 'sites/%s', 'sites/%s')", $old_url, $new_url);
  27. db_query("UPDATE {users} SET picture = REPLACE(picture, 'sites/%s', 'sites/%s')", $old_url, $new_url);
  28. db_query("UPDATE {boxes} SET body = REPLACE(body, 'sites/%s', 'sites/%s')", $old_url, $new_url);
  29. db_query("UPDATE {node_revisions} SET body = REPLACE(body, 'sites/%s', 'sites/%s')", $old_url, $new_url);
  30. db_query("UPDATE {node_revisions} SET teaser = REPLACE(teaser, 'sites/%s', 'sites/%s')", $old_url, $new_url);
  31. // File paths.
  32. variable_set('file_directory_path', "sites/$new_url/files");
  33. variable_set('file_directory_temp', "sites/$new_url/files/tmp");
  34. // Default user picture.
  35. if ($picture = variable_get('user_picture_default', FALSE)) {
  36. $picture = preg_replace($old_url_pattern, 'sites/' . $new_url, $picture);
  37. variable_set('user_picture_default', $picture);
  38. }
  39. // Global theme settings paths.
  40. if ($var = variable_get('theme_settings', FALSE)) {
  41. $var['logo_path'] = preg_replace($old_url_pattern, 'sites/' . $new_url, $var['logo_path']);
  42. $var['favicon_path'] = preg_replace($old_url_pattern, 'sites/' . $new_url, $var['favicon_path']);
  43. variable_set('theme_settings', $var);
  44. }
  45. $themes = list_themes();
  46. foreach (array_keys($themes) as $theme) {
  47. // Update logo and favicon paths for each theme.
  48. if ($var = variable_get('theme_'. $theme .'_settings', FALSE)) {
  49. $var['logo_path'] = preg_replace($old_url_pattern, 'sites/' . $new_url, $var['logo_path']);
  50. $var['favicon_path'] = preg_replace($old_url_pattern, 'sites/' . $new_url, $var['favicon_path']);
  51. variable_set('theme_'. $theme .'_settings', $var);
  52. }
  53. // Update color module paths.
  54. if (module_exists('color')) {
  55. foreach (array('_files', '_logo', '_screenshot', '_stylesheets') as $suffix) {
  56. if ($var = variable_get('color_'. $theme . $suffix, FALSE)) {
  57. variable_set('color_'. $theme . $suffix, preg_replace($old_url_pattern, 'sites/' . $new_url, $var));
  58. }
  59. }
  60. }
  61. }
  62. drush_log(
  63. dt('Changed paths from sites/@old_url to sites/@new_url',
  64. array('@old_url' => $old_url, '@new_url' => $new_url)));