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