-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
updateDataLive2Work.php
56 lines (44 loc) · 1.7 KB
/
updateDataLive2Work.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// NOTE: make sure to first run: update webonary.wp_blogs set domain = 'www.webonary.work' where domain = 'www.webonary.org;
global $wpdb;
chdir( ABSPATH );
$oldDomain = 'webonary.org';
$newDomain = 'webonary.work';
echo_msg( 'Starting...' );
$search_replace_options = "--recurse-objects --skip-columns=guid --skip-tables='wp_users' --report-changed-only";
$sql = $wpdb->prepare( "UPDATE wp_blogs SET domain = replace(domain, %s, %s)", $oldDomain, $newDomain );
$result = $wpdb->get_results( "SELECT * FROM $wpdb->blogs" );
foreach ( $result as $blog ) {
$id = $blog->blog_id;
// Replace subdomain to subdirectory in all links tables
echo_msg( "Changing " . $blog->domain );
exec_wp_cli( "search-replace --url='https://$blog->domain$blog->path' '$oldDomain' '$newDomain' $search_replace_options" );
// Fix map file
fix_map_file( $oldDomain, $newDomain );
// Fix reverse entries
$sql = $wpdb->prepare( "UPDATE wp_{$id}_sil_reversals SET reversal_content=REPLACE(reversal_content, %s, %s)", $oldDomain, $newDomain );
echo_msg( $sql );
echo_msg( "Result: " . $wpdb->query( $sql ) );
}
echo_msg( 'All done!' );
exit;
function fix_map_file( $oldDomain, $newDomain )
{
echo_msg( "Fixing strings in map file $oldDomain to $newDomain" );;
$map_file = 'wp-content/uploads/webonary-sites.gpx';
$contents = file_get_contents( $map_file );
$contents = str_replace( $oldDomain, $newDomain, $contents );
file_put_contents( $map_file, $contents );
}
function exec_wp_cli( $cmd )
{
// NB: it's no longer necessary to use sudo
// $cmd = "sudo wp $cmd --allow-root";
$cmd = "wp $cmd --allow-root";
echo_msg( $cmd );;
echo shell_exec( "$cmd 2>&1" );
}
function echo_msg( $msg )
{
echo current_time( 'mysql' ) . " $msg\n";
}