'ids' ) ); foreach ( $sites as $blog_id ) { switch_to_blog( (int) $blog_id ); self::install_site(); restore_current_blog(); } return; } self::install_site(); } /** * Install a single site: tables, defaults, capabilities, version stamp. * * @return void */ private static function install_site() { self::create_tables(); if ( false === get_option( Settings::OPTION, false ) ) { add_option( Settings::OPTION, Settings::defaults() ); } Capabilities::add_to_roles(); update_option( 'aisiteark_db_version', AISITEARK_DB_VERSION ); update_option( 'aisiteark_version', AISITEARK_VERSION ); } /** * Create / upgrade custom tables via dbDelta. * * @return void */ private static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset_collate = $wpdb->get_charset_collate(); $prefix = $wpdb->prefix . 'aisiteark_'; $schema = array(); // Running/queued backup & restore jobs (resumable step engine state). $schema[] = "CREATE TABLE {$prefix}jobs ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, type varchar(20) NOT NULL DEFAULT 'backup', status varchar(20) NOT NULL DEFAULT 'queued', step varchar(40) NOT NULL DEFAULT '', progress tinyint(3) unsigned NOT NULL DEFAULT 0, state longtext NULL, message varchar(255) NOT NULL DEFAULT '', archive_file varchar(255) NOT NULL DEFAULT '', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY status (status), KEY type (type) ) {$charset_collate};"; // Completed backup history. $schema[] = "CREATE TABLE {$prefix}backups ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, filename varchar(255) NOT NULL DEFAULT '', size bigint(20) unsigned NOT NULL DEFAULT 0, destination varchar(20) NOT NULL DEFAULT 'local', remote_ref varchar(512) NOT NULL DEFAULT '', checksum varchar(64) NOT NULL DEFAULT '', scope longtext NULL, status varchar(20) NOT NULL DEFAULT 'complete', note varchar(255) NOT NULL DEFAULT '', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY status (status), KEY created_at (created_at) ) {$charset_collate};"; foreach ( $schema as $table_sql ) { dbDelta( $table_sql ); } } }