wordpress/wp-content/plugins/sqlite-integration/utilities/database_maintenance.php
/**
	 * Method to do the fixing job to the broken tables.
	 *
	 * If the job succeeded, it returns string of success message.
	 * If failed, it returns the array of the failed query for debugging.
	 *
	 * @return string|array of string
	 * @access private
	 */
Method to do the fixing job to the broken tables.
If the job succeeded, it returns string of success message.
If failed, it returns the array of the failed query for debugging.

@return string|array of string
@access private
Method to do the fixing job to the broken tables . If the job succeeded it returns string of success message . If failed it returns the array of the failed query for debugging . @return string|array of string @access private
private function do_fix_database() {
		global $wpdb, $wp_version, $utils;
		$global_schema_to_change = array(
				$wpdb->prefix.'commentmeta' => array(
					"comment_id bigint(20) unsigned NOT NULL default '0'",
					"meta_key varchar(255) default NULL",
					"meta_value longtext"
				),
				$wpdb->prefix.'comments' => array(
					"comment_post_ID bigint(20) unsigned NOT NULL default '0'",
					"comment_author_email varchar(100) NOT NULL default ''",
					"comment_author_url varchar(200) NOT NULL default ''",
					"comment_author_IP varchar(100) NOT NULL default ''",
					"comment_date datetime NOT NULL default '0000-00-00 00:00:00'",
					"comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
					"comment_karma int(11) NOT NULL default '0'",
					"comment_approved varchar(20) NOT NULL default '1'",
					"comment_agent varchar(255) NOT NULL default ''",
					"comment_type varchar(20) NOT NULL default ''",
					"comment_parent bigint(20) unsigned NOT NULL default '0'",
					"user_id bigint(20) unsigned NOT NULL default '0'"
				),
				$wpdb->prefix.'links' => array(
					"link_url varchar(255) NOT NULL default ''",
					"link_name varchar(255) NOT NULL default ''",
					"link_image varchar(255) NOT NULL default ''",
					"link_target varchar(25) NOT NULL default ''",
					"link_description varchar(255) NOT NULL default ''",
					"link_visible varchar(20) NOT NULL default 'Y'",
					"link_owner bigint(20) unsigned NOT NULL default '1'",
					"link_rating int(11) NOT NULL default '0'",
					"link_updated datetime NOT NULL default '0000-00-00 00:00:00'",
					"link_rel varchar(255) NOT NULL default ''",
					"link_notes mediumtext NOT NULL",
					"link_rss varchar(255) NOT NULL default ''"
				),
				$wpdb->prefix.'options' => array(
					"option_name varchar(64) NOT NULL default ''",
					"option_value longtext NOT NULL",
					"autoload varchar(20) NOT NULL default 'yes'"
				),
				$wpdb->prefix.'postmeta' => array(
					"post_id bigint(20) unsigned NOT NULL default '0'",
					"meta_key varchar(255) default NULL",
					"meta_value longtext"
				),
				$wpdb->prefix.'posts' => array(
					"post_author bigint(20) unsigned NOT NULL default '0'",
					"post_date datetime NOT NULL default '0000-00-00 00:00:00'",
					"post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
					"post_status varchar(20) NOT NULL default 'publish'",
					"comment_status varchar(20) NOT NULL default 'open'",
					"ping_status varchar(20) NOT NULL default 'open'",
					"post_password varchar(20) NOT NULL default ''",
					"post_name varchar(200) NOT NULL default ''",
					"post_modified datetime NOT NULL default '0000-00-00 00:00:00'",
					"post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
					"post_content_filtered longtext NOT NULL",
					"post_parent bigint(20) unsigned NOT NULL default '0'",
					"guid varchar(255) NOT NULL default ''",
					"menu_order int(11) NOT NULL default '0'",
					"post_type varchar(20) NOT NULL default 'post'",
					"post_mime_type varchar(100) NOT NULL default ''",
					"comment_count bigint(20) NOT NULL default '0'"
				),
				$wpdb->prefix.'term_relationships' => array(
					"term_order int(11) NOT NULL default 0"
				),
				$wpdb->prefix.'term_taxonomy' => array(
					"taxonomy varchar(32) NOT NULL default ''",
					"description longtext NOT NULL",
					"parent bigint(20) unsigned NOT NULL default 0",
					"count bigint(20) NOT NULL default 0"
				),
				$wpdb->prefix.'terms' => array(
					"name varchar(200) NOT NULL default ''",
					"slug varchar(200) NOT NULL default ''",
					"term_group bigint(10) NOT NULL default 0"
				),
				$wpdb->prefix.'users' => array(
					"user_login varchar(60) NOT NULL default ''",
					"user_pass varchar(64) NOT NULL default ''",
					"user_nicename varchar(50) NOT NULL default ''",
					"user_email varchar(100) NOT NULL default ''",
					"user_url varchar(100) NOT NULL default ''",
					"user_registered datetime NOT NULL default '0000-00-00 00:00:00'",
					"user_activation_key varchar(60) NOT NULL default ''",
					"user_status int(11) NOT NULL default '0'",
					"display_name varchar(250) NOT NULL default ''"
				),
				$wpdb->prefix.'usermeta' => array(
					"user_id bigint(20) unsigned NOT NULL default '0'",
					"meta_key varchar(255) default NULL",
					"meta_value longtext"
				)
		);
		$network_schema_to_change = array(
				$wpdb->prefix.'blog_versions' => array(
					"blog_id bigint(20) NOT NULL default '0'",
					"db_version varchar(20) NOT NULL default ''",
					"last_updated datetime NOT NULL default '0000-00-00 00:00:00'"
				),
				$wpdb->prefix.'blogs' => array(
					"site_id bigint(20) NOT NULL default '0'",
					"domain varchar(200) NOT NULL default ''",
					"path varchar(100) NOT NULL default ''",
					"registered datetime NOT NULL default '0000-00-00 00:00:00'",
					"last_updated datetime NOT NULL default '0000-00-00 00:00:00'",
					"public tinyint(2) NOT NULL default '1'",
					"mature tinyint(2) NOT NULL default '0'",
					"spam tinyint(2) NOT NULL default '0'",
					"deleted tinyint(2) NOT NULL default '0'",
					"lang_id int(11) NOT NULL default '0'"
				),
				$wpdb->prefix.'registration_log' => array(
					"email varchar(255) NOT NULL default ''",
					"IP varchar(30) NOT NULL default ''",
					"blog_id bigint(20) NOT NULL default '0'",
					"date_registered datetime NOT NULL default '0000-00-00 00:00:00'"
				),
				$wpdb->prefix.'signups' => array(
					"domain varchar(200) NOT NULL default ''",
					"path varchar(100) NOT NULL default ''",
					"title longtext NOT NULL",
					"user_login varchar(60) NOT NULL default ''",
					"user_email varchar(100) NOT NULL default ''",
					"registered datetime NOT NULL default '0000-00-00 00:00:00'",
					"activated datetime NOT NULL default '0000-00-00 00:00:00'",
					"active tinyint(1) NOT NULL default '0'",
					"activation_key varchar(50) NOT NULL default ''",
					"meta longtext"
				),
				$wpdb->prefix.'site' => array(
					"domain varchar(200) NOT NULL default ''",
					"path varchar(100) NOT NULL default ''"
				),
				$wpdb->prefix.'sitemeta' => array(
					"site_id bigint(20) NOT NULL default '0'",
					"meta_key varchar(255) default NULL",
					"meta_value longtext"
				),
				$wpdb->prefix.'users' => array(
					"user_login varchar(60) NOT NULL default ''",
					"spam tinyint(2) NOT NULL default '0'",
					"deleted tinyint(2) NOT NULL default '0'"
				)
		);
		if (version_compare($wp_version, '3.6', '<')) return false;
		$return_val = array();
		$queries = array();
		$results = $this->sanity_check();
		if ($results !== true) {
			if (!$this->maintenance_backup()) {
				$message = __('Can\'t create backup file.', $domain);
				return $message;
			}
			$tables = array_keys($results);
			foreach ($tables as $table) {
				if (key_exists($table, $global_schema_to_change)) {
					$queries = $global_schema_to_change[$table];
				}
				if (key_exists($table, $network_schema_to_change)) {
					if (!empty($queries)) {
						$queries = array_merge($queries, $network_schema_to_change[$table]);
					} else {
						$queries = $network_schema_to_change[$table];
					}
				}
				foreach ($queries as $query) {
					$sql = 'ALTER TABLE' . ' ' . $table . ' ' . 'CHANGE COLUMN' . ' ' . $query;
					$res = $wpdb->query($sql);
					if ($res === false) {
						$return_val[] = __('Failed: ', $domain) . $query;
					}
				}
			}
		} else {
			$message = __('Your database is OK. You don\'t have to restore it.', $domain);
			return $message;
		}
		if (empty($return_val)) {
			$message = __('Your database restoration is successfully finished!', $domain);
			return $message;
		} else {
			return $return_val;
		}
	}
private function do_fix_database ( ) { global $ wpdb , $ wp_version , $ utils ; $ global_schema_to_change = array ( $ wpdb -> prefix . 'commentmeta' => array ( " comment_id bigint(20) unsigned NOT NULL default '0' " , " meta_key varchar(255) default NULL " , " meta_value longtext " ) , $ wpdb -> prefix . 'comments' => array ( " comment_post_ID bigint(20) unsigned NOT NULL default '0' " , " comment_author_email varchar(100) NOT NULL default '' " , " comment_author_url varchar(200) NOT NULL default '' " , " comment_author_IP varchar(100) NOT NULL default '' " , " comment_date datetime NOT NULL default '0000-00-00 00:00:00' " , " comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00' " , " comment_karma int(11) NOT NULL default '0' " , " comment_approved varchar(20) NOT NULL default '1' " , " comment_agent varchar(255) NOT NULL default '' " , " comment_type varchar(20) NOT NULL default '' " , " comment_parent bigint(20) unsigned NOT NULL default '0' " , " user_id bigint(20) unsigned NOT NULL default '0' " ) , $ wpdb -> prefix . 'links' => array ( " link_url varchar(255) NOT NULL default '' " , " link_name varchar(255) NOT NULL default '' " , " link_image varchar(255) NOT NULL default '' " , " link_target varchar(25) NOT NULL default '' " , " link_description varchar(255) NOT NULL default '' " , " link_visible varchar(20) NOT NULL default 'Y' " , " link_owner bigint(20) unsigned NOT NULL default '1' " , " link_rating int(11) NOT NULL default '0' " , " link_updated datetime NOT NULL default '0000-00-00 00:00:00' " , " link_rel varchar(255) NOT NULL default '' " , " link_notes mediumtext NOT NULL " , " link_rss varchar(255) NOT NULL default '' " ) , $ wpdb -> prefix . 'options' => array ( " option_name varchar(64) NOT NULL default '' " , " option_value longtext NOT NULL " , " autoload varchar(20) NOT NULL default 'yes' " ) , $ wpdb -> prefix . 'postmeta' => array ( " post_id bigint(20) unsigned NOT NULL default '0' " , " meta_key varchar(255) default NULL " , " meta_value longtext " ) , $ wpdb -> prefix . 'posts' => array ( " post_author bigint(20) unsigned NOT NULL default '0' " , " post_date datetime NOT NULL default '0000-00-00 00:00:00' " , " post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00' " , " post_status varchar(20) NOT NULL default 'publish' " , " comment_status varchar(20) NOT NULL default 'open' " , " ping_status varchar(20) NOT NULL default 'open' " , " post_password varchar(20) NOT NULL default '' " , " post_name varchar(200) NOT NULL default '' " , " post_modified datetime NOT NULL default '0000-00-00 00:00:00' " , " post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00' " , " post_content_filtered longtext NOT NULL " , " post_parent bigint(20) unsigned NOT NULL default '0' " , " guid varchar(255) NOT NULL default '' " , " menu_order int(11) NOT NULL default '0' " , " post_type varchar(20) NOT NULL default 'post' " , " post_mime_type varchar(100) NOT NULL default '' " , " comment_count bigint(20) NOT NULL default '0' " ) , $ wpdb -> prefix . 'term_relationships' => array ( " term_order int(11) NOT NULL default 0 " ) , $ wpdb -> prefix . 'term_taxonomy' => array ( " taxonomy varchar(32) NOT NULL default '' " , " description longtext NOT NULL " , " parent bigint(20) unsigned NOT NULL default 0 " , " count bigint(20) NOT NULL default 0 " ) , $ wpdb -> prefix . 'terms' => array ( " name varchar(200) NOT NULL default '' " , " slug varchar(200) NOT NULL default '' " , " term_group bigint(10) NOT NULL default 0 " ) , $ wpdb -> prefix . 'users' => array ( " user_login varchar(60) NOT NULL default '' " , " user_pass varchar(64) NOT NULL default '' " , " user_nicename varchar(50) NOT NULL default '' " , " user_email varchar(100) NOT NULL default '' " , " user_url varchar(100) NOT NULL default '' " , " user_registered datetime NOT NULL default '0000-00-00 00:00:00' " , " user_activation_key varchar(60) NOT NULL default '' " , " user_status int(11) NOT NULL default '0' " , " display_name varchar(250) NOT NULL default '' " ) , $ wpdb -> prefix . 'usermeta' => array ( " user_id bigint(20) unsigned NOT NULL default '0' " , " meta_key varchar(255) default NULL " , " meta_value longtext " ) ) ; $ network_schema_to_change = array ( $ wpdb -> prefix . 'blog_versions' => array ( " blog_id bigint(20) NOT NULL default '0' " , " db_version varchar(20) NOT NULL default '' " , " last_updated datetime NOT NULL default '0000-00-00 00:00:00' " ) , $ wpdb -> prefix . 'blogs' => array ( " site_id bigint(20) NOT NULL default '0' " , " domain varchar(200) NOT NULL default '' " , " path varchar(100) NOT NULL default '' " , " registered datetime NOT NULL default '0000-00-00 00:00:00' " , " last_updated datetime NOT NULL default '0000-00-00 00:00:00' " , " public tinyint(2) NOT NULL default '1' " , " mature tinyint(2) NOT NULL default '0' " , " spam tinyint(2) NOT NULL default '0' " , " deleted tinyint(2) NOT NULL default '0' " , " lang_id int(11) NOT NULL default '0' " ) , $ wpdb -> prefix . 'registration_log' => array ( " email varchar(255) NOT NULL default '' " , " IP varchar(30) NOT NULL default '' " , " blog_id bigint(20) NOT NULL default '0' " , " date_registered datetime NOT NULL default '0000-00-00 00:00:00' " ) , $ wpdb -> prefix . 'signups' => array ( " domain varchar(200) NOT NULL default '' " , " path varchar(100) NOT NULL default '' " , " title longtext NOT NULL " , " user_login varchar(60) NOT NULL default '' " , " user_email varchar(100) NOT NULL default '' " , " registered datetime NOT NULL default '0000-00-00 00:00:00' " , " activated datetime NOT NULL default '0000-00-00 00:00:00' " , " active tinyint(1) NOT NULL default '0' " , " activation_key varchar(50) NOT NULL default '' " , " meta longtext " ) , $ wpdb -> prefix . 'site' => array ( " domain varchar(200) NOT NULL default '' " , " path varchar(100) NOT NULL default '' " ) , $ wpdb -> prefix . 'sitemeta' => array ( " site_id bigint(20) NOT NULL default '0' " , " meta_key varchar(255) default NULL " , " meta_value longtext " ) , $ wpdb -> prefix . 'users' => array ( " user_login varchar(60) NOT NULL default '' " , " spam tinyint(2) NOT NULL default '0' " , " deleted tinyint(2) NOT NULL default '0' " ) ) ; if ( version_compare ( $ wp_version , '3.6' , '<' ) ) return false ; $ return_val = array ( ) ; $ queries = array ( ) ; $ results = $ this -> sanity_check ( ) ; if ( $ results !== true ) { if ( ! $ this -> maintenance_backup ( ) ) { $ message = __ ( 'Can\'t create backup file.' , $ domain ) ; return $ message ; } $ tables = array_keys ( $ results ) ; foreach ( $ tables as $ table ) { if ( key_exists ( $ table , $ global_schema_to_change ) ) { $ queries = $ global_schema_to_change [ $ table ] ; } if ( key_exists ( $ table , $ network_schema_to_change ) ) { if ( ! empty ( $ queries ) ) { $ queries = array_merge ( $ queries , $ network_schema_to_change [ $ table ] ) ; } else { $ queries = $ network_schema_to_change [ $ table ] ; } } foreach ( $ queries as $ query ) { $ sql = 'ALTER TABLE' . ' ' . $ table . ' ' . 'CHANGE COLUMN' . ' ' . $ query ; $ res = $ wpdb -> query ( $ sql ) ; if ( $ res === false ) { $ return_val [ ] = __ ( 'Failed: ' , $ domain ) . $ query ; } } } } else { $ message = __ ( 'Your database is OK. You don\'t have to restore it.' , $ domain ) ; return $ message ; } if ( empty ( $ return_val ) ) { $ message = __ ( 'Your database restoration is successfully finished!' , $ domain ) ; return $ message ; } else { return $ return_val ; } }
Method to do the fixing job to the broken tables.
Method to do the fixing job to the broken tables .