Go Live Update URLS - Version 5.2.4

Version Description

Download this release

Release Info

Developer Mat Lipe
Plugin Icon 128x128 Go Live Update URLS
Version 5.2.4
Comparing to
See all releases

Code changes from version 5.2.3 to 5.2.4

Files changed (3) hide show
  1. go-live-update-urls.php +2 -2
  2. readme.txt +2 -2
  3. src/Database.php +40 -34
go-live-update-urls.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: Updates all the URLs in the database to point to a new URL when making your site live or changing domains.
6
  * Author: Mat Lipe
7
  * Author URI: https://matlipe.com/
8
- * Version: 5.2.3
9
  * Text Domain: go-live-update-urls
10
  *
11
  * @package go-live-update-urls
12
  */
13
 
14
- define( 'GO_LIVE_UPDATE_URLS_VERSION', '5.2.3' );
15
 
16
  /**
17
  * Load the plugin
5
  * Description: Updates all the URLs in the database to point to a new URL when making your site live or changing domains.
6
  * Author: Mat Lipe
7
  * Author URI: https://matlipe.com/
8
+ * Version: 5.2.4
9
  * Text Domain: go-live-update-urls
10
  *
11
  * @package go-live-update-urls
12
  */
13
 
14
+ define( 'GO_LIVE_UPDATE_URLS_VERSION', '5.2.4' );
15
 
16
  /**
17
  * Load the plugin
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: Mat Lipe
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40matlipe%2ecom&lc=US&item_name=Go%20Live%20Update%20Urls&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
  Tags: Go Live, Urls, Domain Changes
5
  Requires at least: 4.6.0
6
- Tested up to: 5.0.2
7
  Requires PHP: 5.2.4
8
- Stable tag: 5.2.3
9
 
10
  == Description ==
11
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40matlipe%2ecom&lc=US&item_name=Go%20Live%20Update%20Urls&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
  Tags: Go Live, Urls, Domain Changes
5
  Requires at least: 4.6.0
6
+ Tested up to: 5.0.3
7
  Requires PHP: 5.2.4
8
+ Stable tag: 5.2.4
9
 
10
  == Description ==
11
 
src/Database.php CHANGED
@@ -5,14 +5,13 @@
5
  *
6
  * @author Mat Lipe
7
  * @since 2/1/2018
8
- *
9
  */
10
  class Go_Live_Update_Urls_Database {
11
  protected $old_url = false;
12
 
13
  protected $new_url = false;
14
 
15
- public $double_subdomain = false; //keep track if going to a subdomain
16
 
17
 
18
  /**
@@ -24,7 +23,7 @@ class Go_Live_Update_Urls_Database {
24
  */
25
  public function get_serialized_tables() {
26
  global $wpdb;
27
- //default tables with serialized data
28
  $serialized_tables = array(
29
  $wpdb->options => 'option_value',
30
  $wpdb->postmeta => 'meta_value',
@@ -33,16 +32,15 @@ class Go_Live_Update_Urls_Database {
33
  $wpdb->usermeta => 'meta_value',
34
  );
35
 
36
- //we are not going to update user meta if we are not on main blog
37
  if ( is_multisite() ) {
38
  $serialized_tables[ $wpdb->sitemeta ] = 'meta_value';
39
- //WP 5.0.0+
40
  if ( isset( $wpdb->blogmeta ) ) {
41
  $serialized_tables[ $wpdb->blogmeta ] = 'meta_value';
42
  }
43
  }
44
 
45
-
46
  $tables = apply_filters( 'go-live-update-urls-serialized-tables', $serialized_tables );
47
 
48
  return $tables;
@@ -99,7 +97,7 @@ class Go_Live_Update_Urls_Database {
99
  $tables[] = $wpdb->sitecategories;
100
  $tables[] = $wpdb->registration_log;
101
  $tables[] = $wpdb->blog_versions;
102
- //WP 5.0.0+
103
  if ( isset( $wpdb->blogmeta ) ) {
104
  $tables[ $wpdb->blogmeta ];
105
  }
@@ -121,15 +119,15 @@ class Go_Live_Update_Urls_Database {
121
  global $wpdb;
122
  $query = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME LIKE '" . $wpdb->prefix . "%'";
123
 
124
- //Site 1's 'LIKE wp_%' will return all tables in the database
125
- //so we exclude all possible sub sites e.g. wp_2, wp_3 up to 9
126
  $not_like = null;
127
  if ( 1 === (int) $wpdb->blogid && is_multisite() ) {
128
  for ( $i = 1; $i <= 9; $i ++ ) {
129
  $not_like .= "'" . $wpdb->prefix . $i . "',";
130
  }
131
  $not_like = substr( $not_like, 0, - 1 );
132
- $query .= ' AND SUBSTRING(TABLE_NAME,1,4) NOT IN (' . $not_like . ')';
133
  }
134
  return $wpdb->get_col( $query );
135
  }
@@ -158,9 +156,9 @@ class Go_Live_Update_Urls_Database {
158
  *
159
  * @since 5.0.0
160
  *
161
- * @param string $old_url
162
- * @param string $new_url
163
- * @param array $tables
164
  *
165
  * @todo split this functionality into its own OOP class
166
  *
@@ -175,15 +173,15 @@ class Go_Live_Update_Urls_Database {
175
 
176
  $updaters = (array) Go_Live_Update_Urls__Updaters__Repo::instance()->get_updaters();
177
 
178
- // If the new domain is the old one with a new sub-domain like www
179
  if ( strpos( $this->new_url, $this->old_url ) !== false ) {
180
- list( $subdomain ) = explode( '.', $this->new_url );
181
  $this->double_subdomain = $subdomain . '.' . $this->new_url;
182
  }
183
 
184
- $tables = apply_filters( 'go-live-update-urls/database/update-tables', $tables, $this );
185
 
186
- // Backward compatibility
187
  if ( array_values( $tables ) !== $tables ) {
188
  $tables = (array) array_flip( $tables );
189
  }
@@ -195,41 +193,49 @@ class Go_Live_Update_Urls_Database {
195
  $serialized->update_all_serialized_tables();
196
  }
197
 
198
- //Go through each table sent to be updated
199
  foreach ( (array) $tables as $table ) {
200
  $column_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='{$wpdb->dbname}' AND TABLE_NAME=%s";
201
  $columns = $wpdb->get_col( $wpdb->prepare( $column_query, $table ) );
202
 
203
  foreach ( $columns as $_column ) {
204
- $update_query = 'UPDATE ' . $table . ' SET ' . $_column . ' = replace(' . $_column . ', %s, %s)';
205
  $wpdb->query( $wpdb->prepare( $update_query, array( $this->old_url, $this->new_url ) ) );
206
 
207
- //Run each updater
208
  foreach ( $updaters as $_updater_class ) {
209
  if ( class_exists( $_updater_class ) ) {
210
  /** @var Go_Live_Update_Urls__Updaters__Abstract $_updater */
211
  $_updater = new $_updater_class( $table, $_column, $this->old_url, $this->new_url );
212
  $_updater->update_data();
213
- //run each updater through double sub-domain if applicable
214
- if ( $this->double_subdomain ) {
215
  $_updater = new $_updater_class( $table, $_column, $this->double_subdomain, $this->new_url );
216
  $_updater->update_data();
217
  }
218
  }
219
  }
220
 
221
-
222
- //Fix the dub dubs if this was the old domain with a new sub
223
  if ( $this->double_subdomain ) {
224
- $wpdb->query( $wpdb->prepare( $update_query, array(
225
- $this->double_subdomain,
226
- $this->new_url,
227
- ) ) );
228
- //Fix the emails breaking by being appended the new subdomain
229
- $wpdb->query( $wpdb->prepare( $update_query, array(
230
- '@' . $this->new_url,
231
- '@' . $this->old_url,
232
- ) ) );
 
 
 
 
 
 
 
 
 
 
233
  }
234
  }
235
  }
@@ -246,7 +252,7 @@ class Go_Live_Update_Urls_Database {
246
 
247
  }
248
 
249
- //********** SINGLETON **********/
250
 
251
 
252
  /**
5
  *
6
  * @author Mat Lipe
7
  * @since 2/1/2018
 
8
  */
9
  class Go_Live_Update_Urls_Database {
10
  protected $old_url = false;
11
 
12
  protected $new_url = false;
13
 
14
+ public $double_subdomain = false; // keep track if going to a subdomain
15
 
16
 
17
  /**
23
  */
24
  public function get_serialized_tables() {
25
  global $wpdb;
26
+ // default tables with serialized data
27
  $serialized_tables = array(
28
  $wpdb->options => 'option_value',
29
  $wpdb->postmeta => 'meta_value',
32
  $wpdb->usermeta => 'meta_value',
33
  );
34
 
35
+ // we are not going to update user meta if we are not on main blog
36
  if ( is_multisite() ) {
37
  $serialized_tables[ $wpdb->sitemeta ] = 'meta_value';
38
+ // WP 5.0.0+
39
  if ( isset( $wpdb->blogmeta ) ) {
40
  $serialized_tables[ $wpdb->blogmeta ] = 'meta_value';
41
  }
42
  }
43
 
 
44
  $tables = apply_filters( 'go-live-update-urls-serialized-tables', $serialized_tables );
45
 
46
  return $tables;
97
  $tables[] = $wpdb->sitecategories;
98
  $tables[] = $wpdb->registration_log;
99
  $tables[] = $wpdb->blog_versions;
100
+ // WP 5.0.0+
101
  if ( isset( $wpdb->blogmeta ) ) {
102
  $tables[ $wpdb->blogmeta ];
103
  }
119
  global $wpdb;
120
  $query = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME LIKE '" . $wpdb->prefix . "%'";
121
 
122
+ // Site 1's 'LIKE wp_%' will return all tables in the database
123
+ // so we exclude all possible sub sites e.g. wp_2, wp_3 up to 9
124
  $not_like = null;
125
  if ( 1 === (int) $wpdb->blogid && is_multisite() ) {
126
  for ( $i = 1; $i <= 9; $i ++ ) {
127
  $not_like .= "'" . $wpdb->prefix . $i . "',";
128
  }
129
  $not_like = substr( $not_like, 0, - 1 );
130
+ $query .= ' AND SUBSTRING(TABLE_NAME,1,4) NOT IN (' . $not_like . ')';
131
  }
132
  return $wpdb->get_col( $query );
133
  }
156
  *
157
  * @since 5.0.0
158
  *
159
+ * @param string $old_url - the old URL.
160
+ * @param string $new_url - the new URL.
161
+ * @param array $tables - the tables we are going to update.
162
  *
163
  * @todo split this functionality into its own OOP class
164
  *
173
 
174
  $updaters = (array) Go_Live_Update_Urls__Updaters__Repo::instance()->get_updaters();
175
 
176
+ // If the new domain is the old one with a new sub-domain like www.
177
  if ( strpos( $this->new_url, $this->old_url ) !== false ) {
178
+ list( $subdomain ) = explode( '.', $this->new_url );
179
  $this->double_subdomain = $subdomain . '.' . $this->new_url;
180
  }
181
 
182
+ $tables = apply_filters( 'go-live-update-urls/database/update-tables', $tables, $this );
183
 
184
+ // Backward compatibility.
185
  if ( array_values( $tables ) !== $tables ) {
186
  $tables = (array) array_flip( $tables );
187
  }
193
  $serialized->update_all_serialized_tables();
194
  }
195
 
196
+ // Go through each table sent to be updated.
197
  foreach ( (array) $tables as $table ) {
198
  $column_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='{$wpdb->dbname}' AND TABLE_NAME=%s";
199
  $columns = $wpdb->get_col( $wpdb->prepare( $column_query, $table ) );
200
 
201
  foreach ( $columns as $_column ) {
202
+ $update_query = 'UPDATE ' . $table . ' SET `' . $_column . '` = replace(`' . $_column . '`, %s, %s)';
203
  $wpdb->query( $wpdb->prepare( $update_query, array( $this->old_url, $this->new_url ) ) );
204
 
205
+ // Run each updater.
206
  foreach ( $updaters as $_updater_class ) {
207
  if ( class_exists( $_updater_class ) ) {
208
  /** @var Go_Live_Update_Urls__Updaters__Abstract $_updater */
209
  $_updater = new $_updater_class( $table, $_column, $this->old_url, $this->new_url );
210
  $_updater->update_data();
211
+ if ( ! empty( $this->double_subdomain ) ) {
 
212
  $_updater = new $_updater_class( $table, $_column, $this->double_subdomain, $this->new_url );
213
  $_updater->update_data();
214
  }
215
  }
216
  }
217
 
218
+ // Fix the dub dubs if this was the old domain with a new sub
 
219
  if ( $this->double_subdomain ) {
220
+ $wpdb->query(
221
+ $wpdb->prepare(
222
+ $update_query,
223
+ array(
224
+ $this->double_subdomain,
225
+ $this->new_url,
226
+ )
227
+ )
228
+ );
229
+ // Fix the emails breaking by being appended the new subdomain
230
+ $wpdb->query(
231
+ $wpdb->prepare(
232
+ $update_query,
233
+ array(
234
+ '@' . $this->new_url,
235
+ '@' . $this->old_url,
236
+ )
237
+ )
238
+ );
239
  }
240
  }
241
  }
252
 
253
  }
254
 
255
+ // ********** SINGLETON **********/
256
 
257
 
258
  /**