| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Install |
| 4 |
* |
| 5 |
* This file handles install MainWP DB. |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class MainWP_Install |
| 14 |
* |
| 15 |
* @package MainWP\Dashboard |
| 16 |
* |
| 17 |
* @uses \MainWP\Dashboard\MainWP_DB_Base |
| 18 |
*/ |
| 19 |
class MainWP_Install extends MainWP_DB_Base { |
| 20 |
|
| 21 |
// phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.DB.PreparedSQL.NotPrepared -- unprepared SQL ok, accessing the database directly to custom database functions. |
| 22 |
|
| 23 |
/** |
| 24 |
* Private variable to hold the database version info. |
| 25 |
* |
| 26 |
* @var string DB version info. |
| 27 |
*/ |
| 28 |
protected $mainwp_db_version = '8.982'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Private static variable to hold the single instance of the class. |
| 32 |
* |
| 33 |
* @static |
| 34 |
* |
| 35 |
* @var mixed Default null |
| 36 |
*/ |
| 37 |
private static $instance = null; |
| 38 |
|
| 39 |
/** |
| 40 |
* Method instance() |
| 41 |
* |
| 42 |
* Return public static instance. |
| 43 |
* |
| 44 |
* @static |
| 45 |
* @return MainWP_DB |
| 46 |
*/ |
| 47 |
public static function instance() { |
| 48 |
if ( null == self::$instance ) { |
| 49 |
self::$instance = new self(); |
| 50 |
} |
| 51 |
|
| 52 |
self::$instance->test_connection(); |
| 53 |
|
| 54 |
return self::$instance; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Method install() |
| 59 |
* |
| 60 |
* Installs the new DB. |
| 61 |
* |
| 62 |
* @return void |
| 63 |
* |
| 64 |
* @uses \MainWP\Dashboard\MainWP_Utility::update_option() |
| 65 |
*/ |
| 66 |
public function install() { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 67 |
// get_site_option is multisite aware! |
| 68 |
$currentVersion = get_site_option( 'mainwp_db_version' ); |
| 69 |
|
| 70 |
if ( empty( $currentVersion ) ) { |
| 71 |
update_option( 'mainwp_run_quick_setup', 'yes' ); |
| 72 |
MainWP_Utility::update_option( 'mainwp_enableLegacyBackupFeature', 0 ); |
| 73 |
} else { |
| 74 |
if ( false === get_option( 'mainwp_enableLegacyBackupFeature' ) ) { |
| 75 |
MainWP_Utility::update_option( 'mainwp_enableLegacyBackupFeature', 1 ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if ( empty( $currentVersion ) || version_compare( $currentVersion, '8.8', '<' ) ) { |
| 80 |
MainWP_Utility::update_option( 'mainwp_selected_theme', 'default' ); |
| 81 |
} |
| 82 |
|
| 83 |
$rslt = self::instance()->query( "SHOW TABLES LIKE '" . $this->table_name( 'wp' ) . "'" ); |
| 84 |
if ( 0 == self::num_rows( $rslt ) ) { |
| 85 |
$currentVersion = false; |
| 86 |
} |
| 87 |
|
| 88 |
if ( $currentVersion == $this->mainwp_db_version ) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
$this->pre_update_tables(); |
| 93 |
|
| 94 |
$charset_collate = $this->wpdb->get_charset_collate(); |
| 95 |
|
| 96 |
$sql = array(); |
| 97 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp' ) . " ( |
| 98 |
id int(11) NOT NULL auto_increment, |
| 99 |
userid int(11) NOT NULL, |
| 100 |
adminname text NOT NULL, |
| 101 |
name text NOT NULL, |
| 102 |
url text NOT NULL, |
| 103 |
pubkey text NOT NULL, |
| 104 |
privkey text NOT NULL, |
| 105 |
nossl tinyint(1) NOT NULL, |
| 106 |
nosslkey text NOT NULL, |
| 107 |
siteurl text NOT NULL, |
| 108 |
ga_id text NOT NULL, |
| 109 |
gas_id int(11) NOT NULL, |
| 110 |
offline_checks_last int(11) NOT NULL, |
| 111 |
offline_check_result int(11) NOT NULL, |
| 112 |
http_response_code int(11) NOT NULL DEFAULT 0, |
| 113 |
http_code_noticed tinyint(1) NOT NULL DEFAULT 1, |
| 114 |
disable_status_check tinyint(1) NOT NULL DEFAULT 0, |
| 115 |
disable_health_check tinyint(1) NOT NULL DEFAULT 0, |
| 116 |
status_check_interval tinyint(1) NOT NULL DEFAULT 0, |
| 117 |
health_threshold int(11) NOT NULL DEFAULT 0, |
| 118 |
note text NOT NULL, |
| 119 |
statsUpdate int(11) NOT NULL, |
| 120 |
directories longtext NOT NULL, |
| 121 |
plugin_upgrades longtext NOT NULL, |
| 122 |
theme_upgrades longtext NOT NULL, |
| 123 |
translation_upgrades longtext NOT NULL, |
| 124 |
premium_upgrades longtext NOT NULL, |
| 125 |
securityIssues longtext NOT NULL, |
| 126 |
themes longtext NOT NULL, |
| 127 |
ignored_themes longtext NOT NULL, |
| 128 |
plugins longtext NOT NULL, |
| 129 |
ignored_plugins longtext NOT NULL, |
| 130 |
users longtext NOT NULL, |
| 131 |
categories longtext NOT NULL, |
| 132 |
pluginDir text NOT NULL, |
| 133 |
automatic_update tinyint(1) NOT NULL, |
| 134 |
backup_before_upgrade tinyint(1) NOT NULL DEFAULT 2, |
| 135 |
mainwpdir tinyint(1) NOT NULL, |
| 136 |
loadFilesBeforeZip tinyint(1) NOT NULL DEFAULT 1, |
| 137 |
is_ignoreCoreUpdates tinyint(1) NOT NULL DEFAULT 0, |
| 138 |
is_ignorePluginUpdates tinyint(1) NOT NULL DEFAULT 0, |
| 139 |
is_ignoreThemeUpdates tinyint(1) NOT NULL DEFAULT 0, |
| 140 |
verify_certificate tinyint(1) NOT NULL DEFAULT 1, |
| 141 |
force_use_ipv4 tinyint(1) NOT NULL DEFAULT 0, |
| 142 |
ssl_version tinyint(1) NOT NULL DEFAULT 0, |
| 143 |
ip text NOT NULL DEFAULT '', |
| 144 |
uniqueId text NOT NULL, |
| 145 |
maximumFileDescriptorsOverride tinyint(1) NOT NULL DEFAULT 0, |
| 146 |
maximumFileDescriptorsAuto tinyint(1) NOT NULL DEFAULT 1, |
| 147 |
maximumFileDescriptors int(11) NOT NULL DEFAULT 150, |
| 148 |
http_user text NOT NULL DEFAULT '', |
| 149 |
http_pass text NOT NULL DEFAULT '', |
| 150 |
wpe tinyint(1) NOT NULL, |
| 151 |
is_staging tinyint(1) NOT NULL DEFAULT 0, |
| 152 |
client_id int(11) NOT NULL DEFAULT 0, |
| 153 |
`suspended` tinyint(1) NOT NULL DEFAULT 0, |
| 154 |
KEY idx_userid (userid)"; |
| 155 |
if ( '' == $currentVersion ) { |
| 156 |
$tbl .= ', |
| 157 |
PRIMARY KEY (id) '; |
| 158 |
} |
| 159 |
$tbl .= ') ' . $charset_collate; |
| 160 |
$sql[] = $tbl; |
| 161 |
|
| 162 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_sync' ) . " ( |
| 163 |
sync_id int(11) NOT NULL auto_increment, |
| 164 |
wpid int(11) NOT NULL, |
| 165 |
version text NOT NULL DEFAULT '', |
| 166 |
sync_errors longtext NOT NULL DEFAULT '', |
| 167 |
uptodate longtext NOT NULL DEFAULT '', |
| 168 |
dtsAutomaticSync int(11) NOT NULL DEFAULT 0, |
| 169 |
dtsAutomaticSyncStart int(11) NOT NULL DEFAULT 0, |
| 170 |
dtsSync int(11) NOT NULL DEFAULT 0, |
| 171 |
dtsSyncStart int(11) NOT NULL DEFAULT 0, |
| 172 |
totalsize int(11) NOT NULL DEFAULT 0, |
| 173 |
dbsize int(11) NOT NULL DEFAULT 0, |
| 174 |
extauth text NOT NULL DEFAULT '', |
| 175 |
last_post_gmt int(11) NOT NULL DEFAULT 0, |
| 176 |
health_value int(11) NOT NULL DEFAULT 0, |
| 177 |
health_status tinyint(1) NOT NULL DEFAULT 0, |
| 178 |
health_site_noticed tinyint(1) NOT NULL DEFAULT 1, |
| 179 |
KEY idx_wpid (wpid)"; |
| 180 |
|
| 181 |
if ( '' == $currentVersion ) { |
| 182 |
$tbl .= ', |
| 183 |
PRIMARY KEY (sync_id)'; |
| 184 |
} |
| 185 |
|
| 186 |
$tbl .= ') ' . $charset_collate; |
| 187 |
|
| 188 |
$sql[] = $tbl; |
| 189 |
|
| 190 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_options' ) . " ( |
| 191 |
opt_id int(11) NOT NULL auto_increment, |
| 192 |
wpid int(11) NOT NULL, |
| 193 |
name text NOT NULL DEFAULT '', |
| 194 |
value longtext NOT NULL DEFAULT '', |
| 195 |
KEY idx_wpid (wpid)"; |
| 196 |
|
| 197 |
if ( '' == $currentVersion ) { |
| 198 |
$tbl .= ', |
| 199 |
PRIMARY KEY (opt_id)'; |
| 200 |
} |
| 201 |
$tbl .= ') ' . $charset_collate; |
| 202 |
$sql[] = $tbl; |
| 203 |
|
| 204 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_settings_backup' ) . ' ( |
| 205 |
set_id int(11) NOT NULL auto_increment, |
| 206 |
wpid int(11) NOT NULL, |
| 207 |
archiveFormat text NOT NULL, |
| 208 |
KEY idx_wpid (wpid)'; |
| 209 |
|
| 210 |
if ( '' == $currentVersion ) { |
| 211 |
$tbl .= ', |
| 212 |
PRIMARY KEY (set_id)'; |
| 213 |
} |
| 214 |
$tbl .= ') ' . $charset_collate; |
| 215 |
$sql[] = $tbl; |
| 216 |
|
| 217 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'users' ) . " ( |
| 218 |
userid int(11) NOT NULL, |
| 219 |
user_email text NOT NULL DEFAULT '', |
| 220 |
ignored_plugins longtext NOT NULL DEFAULT '', |
| 221 |
trusted_plugins longtext NOT NULL DEFAULT '', |
| 222 |
trusted_plugins_notes longtext NOT NULL DEFAULT '', |
| 223 |
ignored_themes longtext NOT NULL DEFAULT '', |
| 224 |
trusted_themes longtext NOT NULL DEFAULT '', |
| 225 |
trusted_themes_notes longtext NOT NULL DEFAULT '', |
| 226 |
site_view tinyint(1) NOT NULL DEFAULT '0', |
| 227 |
pluginDir text NOT NULL DEFAULT '', |
| 228 |
dismissed_plugins longtext NOT NULL DEFAULT '', |
| 229 |
dismissed_themes longtext NOT NULL DEFAULT ''"; |
| 230 |
if ( '' == $currentVersion ) { |
| 231 |
$tbl .= ', |
| 232 |
PRIMARY KEY (userid) '; |
| 233 |
} |
| 234 |
$tbl .= ') ' . $charset_collate; |
| 235 |
$sql[] = $tbl; |
| 236 |
|
| 237 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_status' ) . ' ( |
| 238 |
statusid bigint(20) unsigned NOT NULL auto_increment, |
| 239 |
wpid int(11) NOT NULL, |
| 240 |
http_code smallint NOT NULL DEFAULT 0, |
| 241 |
status tinyint(1) NOT NULL DEFAULT 0, |
| 242 |
event_timestamp int(11) NOT NULL, |
| 243 |
duration int(11) NOT NULL DEFAULT 0'; |
| 244 |
if ( '' == $currentVersion || version_compare( $currentVersion, '8.31', '<=' ) ) { |
| 245 |
$tbl .= ', |
| 246 |
PRIMARY KEY (statusid) '; |
| 247 |
} |
| 248 |
$tbl .= ') ' . $charset_collate; |
| 249 |
$sql[] = $tbl; |
| 250 |
|
| 251 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'group' ) . ' ( |
| 252 |
id int(11) NOT NULL auto_increment, |
| 253 |
userid int(11) NOT NULL, |
| 254 |
name text NOT NULL'; |
| 255 |
if ( '' == $currentVersion ) { |
| 256 |
$tbl .= ', |
| 257 |
PRIMARY KEY (id) '; |
| 258 |
} |
| 259 |
$tbl .= ') ' . $charset_collate; |
| 260 |
$sql[] = $tbl; |
| 261 |
|
| 262 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_group' ) . ' ( |
| 263 |
wp_group_id int(11) NOT NULL auto_increment, |
| 264 |
wpid int(11) NOT NULL, |
| 265 |
groupid int(11) NOT NULL, |
| 266 |
KEY idx_wpid (wpid), |
| 267 |
KEY idx_groupid (groupid)'; |
| 268 |
if ( '' == $currentVersion || version_compare( $currentVersion, '8.57', '<=' ) ) { |
| 269 |
$tbl .= ', |
| 270 |
PRIMARY KEY (wp_group_id) '; |
| 271 |
} |
| 272 |
$tbl .= ') ' . $charset_collate; |
| 273 |
$sql[] = $tbl; |
| 274 |
|
| 275 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_backup_progress' ) . " ( |
| 276 |
task_id int(11) NOT NULL, |
| 277 |
wp_id int(11) NOT NULL, |
| 278 |
dtsFetched int(11) NOT NULL DEFAULT 0, |
| 279 |
fetchResult text NOT NULL DEFAULT '', |
| 280 |
downloadedDB text NOT NULL DEFAULT '', |
| 281 |
downloadedFULL text NOT NULL DEFAULT '', |
| 282 |
downloadedDBComplete tinyint(1) NOT NULL DEFAULT 0, |
| 283 |
downloadedFULLComplete tinyint(1) NOT NULL DEFAULT 0, |
| 284 |
removedFiles tinyint(1) NOT NULL DEFAULT 0, |
| 285 |
attempts int(11) NOT NULL DEFAULT 0, |
| 286 |
last_error text NOT NULL DEFAULT '', |
| 287 |
pid int(11) NOT NULL DEFAULT 0, |
| 288 |
KEY idx_task_id (task_id)"; |
| 289 |
if ( '' == $currentVersion || version_compare( $currentVersion, '8.53', '<=' ) ) { |
| 290 |
$tbl .= ', |
| 291 |
UNIQUE (task_id)'; |
| 292 |
} |
| 293 |
$tbl .= ') ' . $charset_collate; |
| 294 |
$sql[] = $tbl; |
| 295 |
|
| 296 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'wp_backup' ) . ' ( |
| 297 |
id int(11) NOT NULL auto_increment, |
| 298 |
userid int(11) NOT NULL, |
| 299 |
name text NOT NULL, |
| 300 |
schedule text NOT NULL, |
| 301 |
type text NOT NULL, |
| 302 |
exclude text NOT NULL, |
| 303 |
sites text NOT NULL, |
| 304 |
`groups` text NOT NULL, |
| 305 |
last int(11) NOT NULL, |
| 306 |
last_run int(11) NOT NULL, |
| 307 |
lastStartNotificationSent int(11) NOT NULL DEFAULT 0, |
| 308 |
last_run_manually int(11) NOT NULL, |
| 309 |
completed_sites text NOT NULL, |
| 310 |
completed int(11) NOT NULL, |
| 311 |
backup_errors text NOT NULL, |
| 312 |
subfolder text NOT NULL, |
| 313 |
filename text NOT NULL, |
| 314 |
paused tinyint(1) NOT NULL, |
| 315 |
template tinyint(1) DEFAULT 0, |
| 316 |
excludebackup tinyint(1) DEFAULT 0, |
| 317 |
excludecache tinyint(1) DEFAULT 0, |
| 318 |
excludenonwp tinyint(1) DEFAULT 0, |
| 319 |
excludezip tinyint(1) DEFAULT 0, |
| 320 |
archiveFormat text NOT NULL, |
| 321 |
loadFilesBeforeZip tinyint(1) NOT NULL DEFAULT 1, |
| 322 |
maximumFileDescriptorsOverride tinyint(1) NOT NULL DEFAULT 0, |
| 323 |
maximumFileDescriptorsAuto tinyint(1) NOT NULL DEFAULT 1, |
| 324 |
maximumFileDescriptors int(11) NOT NULL DEFAULT 150'; |
| 325 |
if ( '' == $currentVersion ) { |
| 326 |
$tbl .= ', |
| 327 |
PRIMARY KEY (id) '; |
| 328 |
} |
| 329 |
$tbl .= ') ' . $charset_collate; |
| 330 |
$sql[] = $tbl; |
| 331 |
|
| 332 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'action_log' ) . " ( |
| 333 |
id int(11) NOT NULL auto_increment, |
| 334 |
log_content mediumtext NOT NULL DEFAULT '', |
| 335 |
log_type tinyint(1) DEFAULT 0, |
| 336 |
log_color tinyint(1) DEFAULT 0, |
| 337 |
log_user varchar(128) NOT NULL DEFAULT '', |
| 338 |
log_timestamp int(11) NOT NULL DEFAULT 0"; |
| 339 |
if ( '' == $currentVersion || version_compare( $currentVersion, '8.50', '<=' ) ) { |
| 340 |
$tbl .= ', |
| 341 |
PRIMARY KEY (id) '; |
| 342 |
} |
| 343 |
$tbl .= ') ' . $charset_collate . ';'; |
| 344 |
$sql[] = $tbl; |
| 345 |
|
| 346 |
$tbl = 'CREATE TABLE ' . $this->table_name( 'request_log' ) . " ( |
| 347 |
id int(11) NOT NULL auto_increment, |
| 348 |
wpid int(11) NOT NULL, |
| 349 |
ip text NOT NULL DEFAULT '', |
| 350 |
subnet text NOT NULL DEFAULT '', |
| 351 |
micro_timestamp_stop DECIMAL( 12, 2 ) NOT NULL DEFAULT 0, |
| 352 |
micro_timestamp_start DECIMAL( 12, 2 ) NOT NULL DEFAULT 0"; |
| 353 |
if ( '' == $currentVersion || version_compare( $currentVersion, '5.7', '<=' ) ) { |
| 354 |
$tbl .= ', |
| 355 |
PRIMARY KEY (id) '; |
| 356 |
} |
| 357 |
$tbl .= ') ' . $charset_collate . ';'; |
| 358 |
$sql[] = $tbl; |
| 359 |
|
| 360 |
$sql = apply_filters( 'mainwp_db_install_tables', $sql, $currentVersion, $charset_collate ); |
| 361 |
|
| 362 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 363 |
foreach ( $sql as $query ) { |
| 364 |
dbDelta( $query ); |
| 365 |
} |
| 366 |
|
| 367 |
$this->post_update(); |
| 368 |
|
| 369 |
if ( ! is_multisite() ) { |
| 370 |
MainWP_Utility::update_option( 'mainwp_db_version', $this->mainwp_db_version ); |
| 371 |
} else { |
| 372 |
update_site_option( 'mainwp_db_version', $this->mainwp_db_version ); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* Method post_update() |
| 378 |
* |
| 379 |
* Update MainWP DB. |
| 380 |
* |
| 381 |
* @return void |
| 382 |
*/ |
| 383 |
public function post_update() { |
| 384 |
|
| 385 |
// get_site_option is multisite aware! |
| 386 |
$currentVersion = get_site_option( 'mainwp_db_version' ); |
| 387 |
|
| 388 |
if ( false == $currentVersion ) { |
| 389 |
return; |
| 390 |
} |
| 391 |
|
| 392 |
$this->post_update_81( $currentVersion ); |
| 393 |
|
| 394 |
// delete old columns. |
| 395 |
if ( version_compare( $currentVersion, '8.17', '<' ) ) { |
| 396 |
$rankColumns = array( |
| 397 |
'pagerank', |
| 398 |
'indexed', |
| 399 |
'alexia', |
| 400 |
'pagerank_old', |
| 401 |
'indexed_old', |
| 402 |
'alexia_old', |
| 403 |
'last_db_backup_size', |
| 404 |
); |
| 405 |
|
| 406 |
foreach ( $rankColumns as $rankColumn ) { |
| 407 |
$suppress = $this->wpdb->suppress_errors(); |
| 408 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $rankColumn ); |
| 409 |
$this->wpdb->suppress_errors( $suppress ); |
| 410 |
} |
| 411 |
|
| 412 |
$syncColumns = array( 'uptodate' ); |
| 413 |
foreach ( $syncColumns as $column ) { |
| 414 |
$suppress = $this->wpdb->suppress_errors(); |
| 415 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_sync' ) . ' DROP COLUMN ' . $column ); |
| 416 |
$this->wpdb->suppress_errors( $suppress ); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
// delete old columns. |
| 421 |
if ( version_compare( $currentVersion, '8.35', '<' ) ) { |
| 422 |
$delColumns = array( 'offline_checks' ); |
| 423 |
foreach ( $delColumns as $column ) { |
| 424 |
$suppress = $this->wpdb->suppress_errors(); |
| 425 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $column ); |
| 426 |
$this->wpdb->suppress_errors( $suppress ); |
| 427 |
} |
| 428 |
$delColumns = array( 'heatMap' ); |
| 429 |
foreach ( $delColumns as $column ) { |
| 430 |
$suppress = $this->wpdb->suppress_errors(); |
| 431 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'users' ) . ' DROP COLUMN ' . $column ); |
| 432 |
$this->wpdb->suppress_errors( $suppress ); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
// change columns. |
| 437 |
if ( version_compare( $currentVersion, '8.40', '<' ) && version_compare( $currentVersion, '8.30', '>' ) ) { |
| 438 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_status' ) . ' CHANGE COLUMN `timestamp_status` `event_timestamp` int(11) NOT NULL' ); |
| 439 |
} |
| 440 |
|
| 441 |
// delete columns. |
| 442 |
if ( version_compare( $currentVersion, '8.42', '<' ) ) { |
| 443 |
$delColumns = array( 'offlineChecksOnlineNotification' ); |
| 444 |
foreach ( $delColumns as $column ) { |
| 445 |
$suppress = $this->wpdb->suppress_errors(); |
| 446 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'users' ) . ' DROP COLUMN ' . $column ); |
| 447 |
$this->wpdb->suppress_errors( $suppress ); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
// fix missing PRIMARY keys. |
| 452 |
if ( version_compare( $currentVersion, '8.53', '<=' ) ) { |
| 453 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_options' ) . ' ADD opt_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' ); |
| 454 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_settings_backup' ) . ' ADD set_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' ); |
| 455 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_sync' ) . ' ADD sync_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' ); |
| 456 |
} |
| 457 |
|
| 458 |
MainWP_DB_Client::instance()->check_to_updates_reports_data_861( $currentVersion ); |
| 459 |
} |
| 460 |
|
| 461 |
/** |
| 462 |
* Method pre_update_tables() |
| 463 |
* |
| 464 |
* Handle pre update tables. |
| 465 |
* |
| 466 |
* @return void |
| 467 |
*/ |
| 468 |
public function pre_update_tables() { |
| 469 |
// get_site_option is multisite aware! |
| 470 |
$currentVersion = get_site_option( 'mainwp_db_version' ); |
| 471 |
|
| 472 |
if ( false == $currentVersion ) { |
| 473 |
return; |
| 474 |
} |
| 475 |
|
| 476 |
$suppress = $this->wpdb->suppress_errors(); |
| 477 |
|
| 478 |
if ( version_compare( $currentVersion, '8.98', '<=' ) ) { |
| 479 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN backups' ); |
| 480 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN note_lastupdate' ); |
| 481 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN pages' ); |
| 482 |
} |
| 483 |
|
| 484 |
$this->wpdb->suppress_errors( $suppress ); |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Method post_update_81() |
| 489 |
* |
| 490 |
* Update MainWP DB for version 8.1. |
| 491 |
* |
| 492 |
* @param string $current_version Current version DB. |
| 493 |
* |
| 494 |
* @return void |
| 495 |
*/ |
| 496 |
public function post_update_81( $current_version ) { |
| 497 |
|
| 498 |
if ( version_compare( $current_version, '8.1', '<' ) ) { |
| 499 |
|
| 500 |
// We can't split up here! |
| 501 |
$wpSyncColumns = array( |
| 502 |
'version', |
| 503 |
'totalsize', |
| 504 |
'dbsize', |
| 505 |
'extauth', |
| 506 |
'last_post_gmt', |
| 507 |
'sync_errors', |
| 508 |
'dtsSync', |
| 509 |
'dtsSyncStart', |
| 510 |
'dtsAutomaticSync', |
| 511 |
'dtsAutomaticSyncStart', |
| 512 |
); |
| 513 |
foreach ( $wpSyncColumns as $wpSyncColumn ) { |
| 514 |
$rslts = $this->wpdb->get_results( 'SELECT id,' . $wpSyncColumn . ' FROM ' . $this->table_name( 'wp' ), ARRAY_A ); |
| 515 |
if ( empty( $rslts ) ) { |
| 516 |
continue; |
| 517 |
} |
| 518 |
|
| 519 |
foreach ( $rslts as $rslt ) { |
| 520 |
$exists = $this->wpdb->get_results( $this->wpdb->prepare( 'SELECT wpid FROM ' . $this->table_name( 'wp_sync' ) . ' WHERE wpid = %d', $rslt['id'] ), ARRAY_A ); |
| 521 |
if ( empty( $exists ) ) { |
| 522 |
$this->wpdb->insert( |
| 523 |
$this->table_name( 'wp_sync' ), |
| 524 |
array( |
| 525 |
'wpid' => $rslt['id'], |
| 526 |
$wpSyncColumn => $rslt[ $wpSyncColumn ], |
| 527 |
) |
| 528 |
); |
| 529 |
} else { |
| 530 |
$this->wpdb->update( $this->table_name( 'wp_sync' ), array( $wpSyncColumn => $rslt[ $wpSyncColumn ] ), array( 'wpid' => $rslt['id'] ) ); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
$suppress = $this->wpdb->suppress_errors(); |
| 535 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $wpSyncColumn ); |
| 536 |
$this->wpdb->suppress_errors( $suppress ); |
| 537 |
} |
| 538 |
|
| 539 |
$optionColumns = array( |
| 540 |
'last_wp_upgrades', |
| 541 |
'last_plugin_upgrades', |
| 542 |
'last_theme_upgrades', |
| 543 |
'wp_upgrades', |
| 544 |
'recent_comments', |
| 545 |
'recent_posts', |
| 546 |
'recent_pages', |
| 547 |
); |
| 548 |
foreach ( $optionColumns as $optionColumn ) { |
| 549 |
$rslts = $this->wpdb->get_results( 'SELECT id,' . $optionColumn . ' FROM ' . $this->table_name( 'wp' ), ARRAY_A ); |
| 550 |
if ( empty( $rslts ) ) { |
| 551 |
continue; |
| 552 |
} |
| 553 |
|
| 554 |
foreach ( $rslts as $rslt ) { |
| 555 |
self::update_website_option( (object) $rslt, $optionColumn, $rslt[ $optionColumn ] ); |
| 556 |
} |
| 557 |
|
| 558 |
$suppress = $this->wpdb->suppress_errors(); |
| 559 |
$this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $optionColumn ); |
| 560 |
$this->wpdb->suppress_errors( $suppress ); |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
} |
| 565 |
|