Commit 432dee17 authored by omega8cc's avatar omega8cc

Update absolute URLs to files for sites cloned/migrated/renamed

parent 3d06d41e
......@@ -10,6 +10,8 @@
$new_url = d()->uri;
$old_url = drush_get_option('old_uri', $new_url, 'cli');
$old_url_pattern = '/^' . preg_quote('sites/' . $old_url, '/') . '/';
$old_url_abs = '//' . $old_url . '/sites/' . $old_url . '/files';
$new_url_abs = '//' . $new_url . '/sites/' . $new_url . '/files';
// Update paths for sites migrated from standalone to the multisite install.
db_query("UPDATE {files} SET filepath = REPLACE(filepath, 'sites/default', 'sites/%s')", $new_url);
......@@ -18,6 +20,13 @@ db_query("UPDATE {boxes} SET body = REPLACE(body, 'sites/defau
db_query("UPDATE {node_revisions} SET body = REPLACE(body, 'sites/default', 'sites/%s')", $new_url);
db_query("UPDATE {node_revisions} SET teaser = REPLACE(teaser, 'sites/default', 'sites/%s')", $new_url);
// Update absolute URLs to files for sites cloned/migrated/renamed in the multisite install.
db_query("UPDATE {files} SET filepath = REPLACE(filepath, '%s', '%s')", $old_url_abs, $new_url_abs);
db_query("UPDATE {users} SET picture = REPLACE(picture, '%s', '%s')", $old_url_abs, $new_url_abs);
db_query("UPDATE {boxes} SET body = REPLACE(body, '%s', '%s')", $old_url_abs, $new_url_abs);
db_query("UPDATE {node_revisions} SET body = REPLACE(body, '%s', '%s')", $old_url_abs, $new_url_abs);
db_query("UPDATE {node_revisions} SET teaser = REPLACE(teaser, '%s', '%s')", $old_url_abs, $new_url_abs);
// Update paths for sites cloned/migrated/renamed in the multisite install.
db_query("UPDATE {files} SET filepath = REPLACE(filepath, 'sites/%s', 'sites/%s')", $old_url, $new_url);
db_query("UPDATE {users} SET picture = REPLACE(picture, 'sites/%s', 'sites/%s')", $old_url, $new_url);
......
......@@ -35,11 +35,14 @@ if ($url_changed) {
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(
':abo' => '//' . $old_url . '/sites/' . $old_url . '/files',
':abn' => '//' . $new_url . '/sites/' . $new_url . '/files',
':old' => 'sites/' . $old_url,
':new' => 'sites/' . $new_url,
);
if(db_table_exists('block_custom')) {
db_query("UPDATE {block_custom} SET body = REPLACE(body, :abo, :abn)", $replace_patterns);
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);
......@@ -51,6 +54,8 @@ function _provision_platform_drupal_deploy_7_replace($old_url, $new_url) {
// 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, :abo, :abn)", $replace_patterns);
db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :abo, :abn)", $replace_patterns);
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);
}
......@@ -58,6 +63,8 @@ function _provision_platform_drupal_deploy_7_replace($old_url, $new_url) {
// 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, :abo, :abn)", $replace_patterns);
db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :abo, :abn)", $replace_patterns);
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);
}
......
......@@ -42,11 +42,14 @@ if ($url_changed) {
function _provision_platform_drupal_deploy_8_replace($old_url, $new_url) {
// Update paths for sites cloned/migrated/renamed in the multisite install.
$replace_patterns = array(
':abo' => '//' . $old_url . '/sites/' . $old_url . '/files',
':abn' => '//' . $new_url . '/sites/' . $new_url . '/files',
':old' => 'sites/' . $old_url,
':new' => 'sites/' . $new_url,
);
if(db_table_exists('block_custom')) {
db_query("UPDATE {block_custom} SET body = REPLACE(body, :abo, :abn)", $replace_patterns);
db_query("UPDATE {block_custom} SET body = REPLACE(body, :old, :new)", $replace_patterns);
}
......@@ -57,6 +60,8 @@ function _provision_platform_drupal_deploy_8_replace($old_url, $new_url) {
// 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, :abo, :abn)", $replace_patterns);
db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_value = REPLACE(${tablekey}_value, :abo, :abn)", $replace_patterns);
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);
}
......@@ -64,6 +69,8 @@ function _provision_platform_drupal_deploy_8_replace($old_url, $new_url) {
// 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, :abo, :abn)", $replace_patterns);
db_query("UPDATE {field_revision_${tablekey}} SET ${tablekey}_summary = REPLACE(${tablekey}_summary, :abo, :abn)", $replace_patterns);
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment