PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-install.php

class-mainwp-install.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.3, at class/class-mainwp-install.php

645 lines 22.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
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.49'; // NOSONAR - no IP.
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 === static::$instance ) {
56 static::$instance = new self();
57 }
58
59 static::$instance->test_connection();
60
61 return static::$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 -- NOSONAR - 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 = static::instance()->query( "SHOW TABLES LIKE '" . $this->table_name( 'wp' ) . "'" );
89 if ( empty( static::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_health_check tinyint(1) NOT NULL DEFAULT 0,
118 health_threshold int(11) NOT NULL DEFAULT 0,
119 note text NOT NULL,
120 statsUpdate int(11) NOT NULL,
121 directories longtext NOT NULL,
122 plugin_upgrades longtext NOT NULL,
123 theme_upgrades longtext NOT NULL,
124 translation_upgrades longtext NOT NULL,
125 premium_upgrades longtext NOT NULL,
126 securityIssues longtext NOT NULL,
127 themes longtext NOT NULL,
128 ignored_themes longtext NOT NULL,
129 plugins longtext NOT NULL,
130 ignored_plugins longtext NOT NULL,
131 users longtext NOT NULL,
132 categories longtext NOT NULL,
133 pluginDir text NOT NULL,
134 automatic_update tinyint(1) NOT NULL,
135 backup_before_upgrade tinyint(1) NOT NULL DEFAULT 2,
136 mainwpdir tinyint(1) NOT NULL,
137 loadFilesBeforeZip tinyint(1) NOT NULL DEFAULT 1,
138 is_ignoreCoreUpdates tinyint(1) NOT NULL DEFAULT 0,
139 is_ignorePluginUpdates tinyint(1) NOT NULL DEFAULT 0,
140 is_ignoreThemeUpdates tinyint(1) NOT NULL DEFAULT 0,
141 verify_certificate tinyint(1) NOT NULL DEFAULT 1,
142 force_use_ipv4 tinyint(1) NOT NULL DEFAULT 0,
143 ssl_version tinyint(1) NOT NULL DEFAULT 0,
144 ip text NOT NULL DEFAULT '',
145 uniqueId text NOT NULL,
146 maximumFileDescriptorsOverride tinyint(1) NOT NULL DEFAULT 0,
147 maximumFileDescriptorsAuto tinyint(1) NOT NULL DEFAULT 1,
148 maximumFileDescriptors int(11) NOT NULL DEFAULT 150,
149 http_user text NOT NULL DEFAULT '',
150 http_pass text NOT NULL DEFAULT '',
151 wpe tinyint(1) NOT NULL,
152 is_staging tinyint(1) NOT NULL DEFAULT 0,
153 client_id int(11) NOT NULL DEFAULT 0,
154 `suspended` tinyint(1) NOT NULL DEFAULT 0,
155 KEY idx_userid (userid)";
156 if ( empty( $currentVersion ) ) {
157 $tbl .= ',
158 PRIMARY KEY (id) ';
159 }
160 $tbl .= ') ' . $charset_collate;
161 $sql[] = $tbl;
162
163 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_sync' ) . " (
164 sync_id int(11) NOT NULL auto_increment,
165 wpid int(11) NOT NULL,
166 version text NOT NULL DEFAULT '',
167 sync_errors longtext NOT NULL DEFAULT '',
168 uptodate longtext NOT NULL DEFAULT '',
169 dtsAutomaticSync int(11) NOT NULL DEFAULT 0,
170 dtsAutomaticSyncStart int(11) NOT NULL DEFAULT 0,
171 dtsSync int(11) NOT NULL DEFAULT 0,
172 dtsSyncStart int(11) NOT NULL DEFAULT 0,
173 totalsize int(11) NOT NULL DEFAULT 0,
174 dbsize int(11) NOT NULL DEFAULT 0,
175 extauth text NOT NULL DEFAULT '',
176 last_post_gmt int(11) NOT NULL DEFAULT 0,
177 health_value int(11) NOT NULL DEFAULT 0,
178 health_status tinyint(1) NOT NULL DEFAULT 0,
179 health_site_noticed tinyint(1) NOT NULL DEFAULT 1,
180 KEY idx_wpid (wpid)";
181
182 if ( empty( $currentVersion ) ) {
183 $tbl .= ',
184 PRIMARY KEY (sync_id)';
185 }
186
187 $tbl .= ') ' . $charset_collate;
188
189 $sql[] = $tbl;
190
191 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_options' ) . " (
192 opt_id int(11) NOT NULL auto_increment,
193 wpid int(11) NOT NULL,
194 name text NOT NULL DEFAULT '',
195 value longtext NOT NULL DEFAULT '',
196 KEY idx_wpid (wpid)";
197
198 if ( empty( $currentVersion ) ) {
199 $tbl .= ',
200 PRIMARY KEY (opt_id)';
201 }
202 $tbl .= ') ' . $charset_collate;
203 $sql[] = $tbl;
204
205 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_settings_backup' ) . ' (
206 set_id int(11) NOT NULL auto_increment,
207 wpid int(11) NOT NULL,
208 archiveFormat text NOT NULL,
209 KEY idx_wpid (wpid)';
210
211 if ( empty( $currentVersion ) ) {
212 $tbl .= ',
213 PRIMARY KEY (set_id)';
214 }
215 $tbl .= ') ' . $charset_collate;
216 $sql[] = $tbl;
217
218 $tbl = 'CREATE TABLE ' . $this->table_name( 'users' ) . " (
219 userid int(11) NOT NULL,
220 user_email text NOT NULL DEFAULT '',
221 ignored_plugins longtext NOT NULL DEFAULT '',
222 trusted_plugins longtext NOT NULL DEFAULT '',
223 trusted_plugins_notes longtext NOT NULL DEFAULT '',
224 ignored_themes longtext NOT NULL DEFAULT '',
225 ignored_wp_upgrades longtext NOT NULL DEFAULT '',
226 trusted_themes longtext NOT NULL DEFAULT '',
227 trusted_themes_notes longtext NOT NULL DEFAULT '',
228 site_view tinyint(1) NOT NULL DEFAULT '0',
229 pluginDir text NOT NULL DEFAULT '',
230 dismissed_plugins longtext NOT NULL DEFAULT '',
231 dismissed_themes longtext NOT NULL DEFAULT ''";
232 if ( empty( $currentVersion ) ) {
233 $tbl .= ',
234 PRIMARY KEY (userid) ';
235 }
236 $tbl .= ') ' . $charset_collate;
237 $sql[] = $tbl;
238
239 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_status' ) . ' (
240 statusid bigint(20) unsigned NOT NULL auto_increment,
241 wpid int(11) NOT NULL,
242 http_code smallint NOT NULL DEFAULT 0,
243 status tinyint(1) NOT NULL DEFAULT 0,
244 event_timestamp int(11) NOT NULL,
245 duration int(11) NOT NULL DEFAULT 0';
246 if ( empty( $currentVersion ) || version_compare( $currentVersion, '8.31', '<=' ) ) {
247 $tbl .= ',
248 PRIMARY KEY (statusid) ';
249 }
250 $tbl .= ') ' . $charset_collate;
251 $sql[] = $tbl;
252
253 $tbl = 'CREATE TABLE ' . $this->table_name( 'group' ) . ' (
254 id int(11) NOT NULL auto_increment,
255 userid int(11) NOT NULL,
256 name text NOT NULL,
257 color varchar(32) NOT NULL DEFAULT ""';
258 if ( empty( $currentVersion ) ) {
259 $tbl .= ',
260 PRIMARY KEY (id) ';
261 }
262 $tbl .= ') ' . $charset_collate;
263 $sql[] = $tbl;
264
265 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_group' ) . ' (
266 wp_group_id int(11) NOT NULL auto_increment,
267 wpid int(11) NOT NULL,
268 groupid int(11) NOT NULL,
269 KEY idx_wpid (wpid),
270 KEY idx_groupid (groupid)';
271 if ( empty( $currentVersion ) || version_compare( $currentVersion, '8.57', '<=' ) ) {
272 $tbl .= ',
273 PRIMARY KEY (wp_group_id) ';
274 }
275 $tbl .= ') ' . $charset_collate;
276 $sql[] = $tbl;
277
278 $tbl = 'CREATE TABLE ' . $this->table_name( 'lookup_item_objects' ) . ' (
279 lookup_id bigint(20) unsigned NOT NULL auto_increment,
280 item_id bigint(20) unsigned NOT NULL,
281 item_name varchar(32) NOT NULL,
282 object_id bigint(20) unsigned NOT NULL,
283 object_name varchar(32) NOT NULL,
284 KEY item_id (item_id),
285 KEY object_id (object_id)';
286
287 if ( empty( $currentVersion ) || version_compare( $currentVersion, '9.0.0.5', '<' ) ) { // NOSONAR - none IP.
288 $tbl .= ',
289 PRIMARY KEY (lookup_id) ';
290 }
291 $tbl .= ') ' . $charset_collate . ';';
292 $sql[] = $tbl;
293
294 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_backup_progress' ) . " (
295 task_id int(11) NOT NULL,
296 wp_id int(11) NOT NULL,
297 dtsFetched int(11) NOT NULL DEFAULT 0,
298 fetchResult text NOT NULL DEFAULT '',
299 downloadedDB text NOT NULL DEFAULT '',
300 downloadedFULL text NOT NULL DEFAULT '',
301 downloadedDBComplete tinyint(1) NOT NULL DEFAULT 0,
302 downloadedFULLComplete tinyint(1) NOT NULL DEFAULT 0,
303 removedFiles tinyint(1) NOT NULL DEFAULT 0,
304 attempts int(11) NOT NULL DEFAULT 0,
305 last_error text NOT NULL DEFAULT '',
306 pid int(11) NOT NULL DEFAULT 0,
307 KEY idx_task_id (task_id)";
308 if ( empty( $currentVersion ) || version_compare( $currentVersion, '8.53', '<=' ) ) {
309 $tbl .= ',
310 UNIQUE (task_id)';
311 }
312 $tbl .= ') ' . $charset_collate;
313 $sql[] = $tbl;
314
315 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_backup' ) . ' (
316 id int(11) NOT NULL auto_increment,
317 userid int(11) NOT NULL,
318 name text NOT NULL,
319 schedule text NOT NULL,
320 type text NOT NULL,
321 exclude text NOT NULL,
322 sites text NOT NULL,
323 `groups` text NOT NULL,
324 last int(11) NOT NULL,
325 last_run int(11) NOT NULL,
326 lastStartNotificationSent int(11) NOT NULL DEFAULT 0,
327 last_run_manually int(11) NOT NULL,
328 completed_sites text NOT NULL,
329 completed int(11) NOT NULL,
330 backup_errors text NOT NULL,
331 subfolder text NOT NULL,
332 filename text NOT NULL,
333 paused tinyint(1) NOT NULL,
334 template tinyint(1) DEFAULT 0,
335 excludebackup tinyint(1) DEFAULT 0,
336 excludecache tinyint(1) DEFAULT 0,
337 excludenonwp tinyint(1) DEFAULT 0,
338 excludezip tinyint(1) DEFAULT 0,
339 archiveFormat text NOT NULL,
340 loadFilesBeforeZip tinyint(1) NOT NULL DEFAULT 1,
341 maximumFileDescriptorsOverride tinyint(1) NOT NULL DEFAULT 0,
342 maximumFileDescriptorsAuto tinyint(1) NOT NULL DEFAULT 1,
343 maximumFileDescriptors int(11) NOT NULL DEFAULT 150';
344 if ( empty( $currentVersion ) ) {
345 $tbl .= ',
346 PRIMARY KEY (id) ';
347 }
348 $tbl .= ') ' . $charset_collate;
349 $sql[] = $tbl;
350
351 $tbl = 'CREATE TABLE ' . $this->table_name( 'api_keys' ) . ' (
352 key_id bigint(20) unsigned NOT NULL auto_increment,
353 user_id bigint(20) unsigned NOT NULL,
354 description varchar(200) NULL,
355 permissions varchar(10) NOT NULL,
356 consumer_key char(64) NOT NULL,
357 consumer_secret char(43) NOT NULL,
358 nonces longtext NULL,
359 truncated_key char(7) NOT NULL,
360 key_pass char(64) NOT NULL DEFAULT "",
361 key_type tinyint(1) NOT NULL DEFAULT 0,
362 `enabled` tinyint(1) DEFAULT 0,
363 last_access datetime NULL default null,
364 KEY consumer_key (consumer_key),
365 KEY consumer_secret (consumer_secret)';
366 if ( empty( $currentVersion ) || version_compare( $currentVersion, '9.0.0.9', '<=' ) ) { // NOSONAR - none IP.
367 $tbl .= ',
368 PRIMARY KEY (key_id) ';
369 }
370 $tbl .= ') ' . $charset_collate . ';';
371 $sql[] = $tbl;
372
373 $tbl = 'CREATE TABLE ' . $this->table_name( 'action_log' ) . " (
374 id int(11) NOT NULL auto_increment,
375 log_content mediumtext NOT NULL DEFAULT '',
376 log_type tinyint(1) DEFAULT 0,
377 log_color tinyint(1) DEFAULT 0,
378 log_user varchar(128) NOT NULL DEFAULT '',
379 log_timestamp int(11) NOT NULL DEFAULT 0";
380 if ( empty( $currentVersion ) || version_compare( $currentVersion, '8.50', '<=' ) ) {
381 $tbl .= ',
382 PRIMARY KEY (id) ';
383 }
384 $tbl .= ') ' . $charset_collate . ';';
385 $sql[] = $tbl;
386
387 $tbl = 'CREATE TABLE ' . $this->table_name( 'request_log' ) . " (
388 id int(11) NOT NULL auto_increment,
389 wpid int(11) NOT NULL,
390 ip text NOT NULL DEFAULT '',
391 subnet text NOT NULL DEFAULT '',
392 micro_timestamp_stop DECIMAL( 12, 2 ) NOT NULL DEFAULT 0,
393 micro_timestamp_start DECIMAL( 12, 2 ) NOT NULL DEFAULT 0";
394 if ( empty( $currentVersion ) || version_compare( $currentVersion, '5.7', '<=' ) ) {
395 $tbl .= ',
396 PRIMARY KEY (id) ';
397 }
398 $tbl .= ') ' . $charset_collate . ';';
399 $sql[] = $tbl;
400
401 $tbl = 'CREATE TABLE ' . $this->table_name( 'schedule_processes' ) . " (
402 process_id int(11) NOT NULL auto_increment,
403 item_id int(11) NOT NULL,
404 `type` varchar(32) NOT NULL,
405 `process_slug` varchar(64) NOT NULL,
406 `status` varchar(32) NOT NULL DEFAULT '',
407 dts_process_start int(11) NOT NULL DEFAULT 0,
408 dts_process_stop int(11) NOT NULL DEFAULT 0";
409
410 if ( empty( $currentVersion ) || version_compare( $currentVersion, '9.0.0.45', '<' ) ) { //phpcs:ignore -- NOSONAR - no ip.
411 $tbl .= ',
412 PRIMARY KEY (process_id) ';
413 }
414
415 $tbl .= ') ' . $charset_collate . ';';
416 $sql[] = $tbl;
417
418 // End of tables.
419
420 $sql = apply_filters( 'mainwp_db_install_tables', $sql, $currentVersion, $charset_collate );
421
422 MainWP_DB_Uptime_Monitoring::instance()->get_db_schema( $sql, $currentVersion );
423
424 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // NOSONAR - WP compatible.
425
426 global $wpdb;
427
428 if ( MainWP_Utility::instance()->is_disabled_functions( 'error_log' ) || ! function_exists( '\error_log' ) ) {
429 error_reporting(0); // phpcs:ignore -- try to disabled the error_log somewhere in WP.
430 }
431
432 $suppress = $wpdb->suppress_errors();
433 foreach ( $sql as $query ) {
434 dbDelta( $query );
435 }
436 $wpdb->suppress_errors( $suppress );
437
438 $this->post_update();
439
440 do_action( 'mainwp_db_after_update', $currentVersion, $this->mainwp_db_version ); // new version: $this->mainwp_db_version.
441
442 if ( ! is_multisite() ) {
443 MainWP_Utility::update_option( $this->option_db_key, $this->mainwp_db_version );
444 } else {
445 update_site_option( $this->option_db_key, $this->mainwp_db_version );
446 }
447 }
448
449 /**
450 * Returns the database version.
451 *
452 * @return string
453 */
454 public function get_db_version() {
455 return get_site_option( $this->option_db_key );
456 }
457
458 /**
459 * Method post_update()
460 *
461 * Update MainWP DB.
462 *
463 * @return void
464 */
465 public function post_update() { // phpcs:ignore -- NOSONAR - complex.
466
467 // get_site_option is multisite aware!
468 $currentVersion = get_site_option( $this->option_db_key );
469
470 if ( false === $currentVersion ) {
471 return;
472 }
473
474 $suppress = $this->wpdb->suppress_errors();
475
476 $this->post_update_81( $currentVersion );
477
478 if ( version_compare( $currentVersion, '8.984', '<' ) ) {
479 $sslColumns = array(
480 'nossl',
481 'nosslkey',
482 );
483 foreach ( $sslColumns as $col ) {
484 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $col );
485 }
486 }
487
488 // delete old columns.
489 if ( version_compare( $currentVersion, '8.17', '<' ) ) {
490 $rankColumns = array(
491 'pagerank',
492 'indexed',
493 'alexia',
494 'pagerank_old',
495 'indexed_old',
496 'alexia_old',
497 'last_db_backup_size',
498 );
499
500 foreach ( $rankColumns as $rankColumn ) {
501 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $rankColumn );
502 }
503
504 $syncColumns = array( 'uptodate' );
505 foreach ( $syncColumns as $column ) {
506 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_sync' ) . ' DROP COLUMN ' . $column );
507 }
508 }
509
510 // delete old columns.
511 if ( version_compare( $currentVersion, '8.35', '<' ) ) {
512 $delColumns = array( 'offline_checks' );
513 foreach ( $delColumns as $column ) {
514 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $column );
515 }
516 $delColumns = array( 'heatMap' );
517 foreach ( $delColumns as $column ) {
518 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'users' ) . ' DROP COLUMN ' . $column );
519 }
520 }
521
522 // delete columns.
523 if ( version_compare( $currentVersion, '8.42', '<' ) ) {
524 $delColumns = array( 'offlineChecksOnlineNotification' );
525 foreach ( $delColumns as $column ) {
526 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'users' ) . ' DROP COLUMN ' . $column );
527 }
528 }
529
530 // fix missing PRIMARY keys.
531 if ( version_compare( $currentVersion, '8.53', '<=' ) ) {
532 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_options' ) . ' ADD opt_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' );
533 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_settings_backup' ) . ' ADD set_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' );
534 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_sync' ) . ' ADD sync_id int NOT NULL AUTO_INCREMENT PRIMARY KEY' );
535 }
536
537 $this->wpdb->suppress_errors( $suppress );
538 MainWP_DB_Client::instance()->check_to_updates_reports_data_861( $currentVersion );
539 }
540
541 /**
542 * Method pre_update_tables()
543 *
544 * Handle pre update tables.
545 *
546 * @return void
547 */
548 public function pre_update_tables() {
549 // get_site_option is multisite aware!
550 $currentVersion = get_site_option( $this->option_db_key );
551
552 if ( false === $currentVersion ) {
553 return;
554 }
555
556 $suppress = $this->wpdb->suppress_errors();
557
558 if ( version_compare( $currentVersion, '8.98', '<=' ) ) {
559 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN backups' );
560 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN note_lastupdate' );
561 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN pages' );
562 }
563
564 $this->wpdb->suppress_errors( $suppress );
565 }
566
567 /**
568 * Method post_update_81()
569 *
570 * Update MainWP DB for version 8.1.
571 *
572 * @param string $current_version Current version DB.
573 *
574 * @return void
575 */
576 public function post_update_81( $current_version ) { //phpcs:ignore -- NOSONAR - complex.
577
578 if ( version_compare( $current_version, '8.1', '<' ) ) {
579
580 // We can't split up here!
581 $wpSyncColumns = array(
582 'version',
583 'totalsize',
584 'dbsize',
585 'extauth',
586 'last_post_gmt',
587 'sync_errors',
588 'dtsSync',
589 'dtsSyncStart',
590 'dtsAutomaticSync',
591 'dtsAutomaticSyncStart',
592 );
593 foreach ( $wpSyncColumns as $wpSyncColumn ) {
594 $rslts = $this->wpdb->get_results( 'SELECT id,' . $wpSyncColumn . ' FROM ' . $this->table_name( 'wp' ), ARRAY_A );
595 if ( empty( $rslts ) ) {
596 continue;
597 }
598
599 foreach ( $rslts as $rslt ) {
600 $exists = $this->wpdb->get_results( $this->wpdb->prepare( 'SELECT wpid FROM ' . $this->table_name( 'wp_sync' ) . ' WHERE wpid = %d', $rslt['id'] ), ARRAY_A );
601 if ( empty( $exists ) ) {
602 $this->wpdb->insert(
603 $this->table_name( 'wp_sync' ),
604 array(
605 'wpid' => $rslt['id'],
606 $wpSyncColumn => $rslt[ $wpSyncColumn ],
607 )
608 );
609 } else {
610 $this->wpdb->update( $this->table_name( 'wp_sync' ), array( $wpSyncColumn => $rslt[ $wpSyncColumn ] ), array( 'wpid' => $rslt['id'] ) );
611 }
612 }
613
614 $suppress = $this->wpdb->suppress_errors();
615 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $wpSyncColumn );
616 $this->wpdb->suppress_errors( $suppress );
617 }
618
619 $optionColumns = array(
620 'last_wp_upgrades',
621 'last_plugin_upgrades',
622 'last_theme_upgrades',
623 'wp_upgrades',
624 'recent_comments',
625 'recent_posts',
626 'recent_pages',
627 );
628 foreach ( $optionColumns as $optionColumn ) {
629 $rslts = $this->wpdb->get_results( 'SELECT id,' . $optionColumn . ' FROM ' . $this->table_name( 'wp' ), ARRAY_A );
630 if ( empty( $rslts ) ) {
631 continue;
632 }
633
634 foreach ( $rslts as $rslt ) {
635 static::update_website_option( (object) $rslt, $optionColumn, $rslt[ $optionColumn ] );
636 }
637
638 $suppress = $this->wpdb->suppress_errors();
639 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp' ) . ' DROP COLUMN ' . $optionColumn );
640 $this->wpdb->suppress_errors( $suppress );
641 }
642 }
643 }
644 }
645