From 104ead5a9e2c433e450dd92c2614f55f79d8c8af Mon Sep 17 00:00:00 2001 From: John James Jacoby Date: Tue, 11 Apr 2017 21:38:52 -0500 Subject: [PATCH] Update database schemas. --- readme.txt | 5 ++++- wp-site-aliases.php | 4 ++-- .../classes/class-wp-db-table-site-aliases.php | 13 +++++++++---- .../classes/class-wp-db-table-site-aliasmeta.php | 12 +++++++++--- .../includes/classes/class-wp-db-table.php | 12 ++++++------ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/readme.txt b/readme.txt index c771a22..158563d 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: johnjamesjacoby, stuttter Tags: blog, site, meta, multisite, alias, domain, mapping Requires at least: 4.5 Tested up to: 4.8 -Stable tag: 6.0.0 +Stable tag: 7.0.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9Q4F4EL5YJ62J @@ -74,6 +74,9 @@ http://github.com/stuttter/wp-site-aliases/ == Changelog == += [7.0.0] - 2017-04-11 = +* Database schema improvements + = [6.0.0] - 2017-04-03 = * Add 'created_by' meta data * Remove alias meta on delete diff --git a/wp-site-aliases.php b/wp-site-aliases.php index 9f27622..3d34f72 100644 --- a/wp-site-aliases.php +++ b/wp-site-aliases.php @@ -8,7 +8,7 @@ * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Description: User-defined site-aliases for your multisite installation - * Version: 6.0.0 + * Version: 7.0.0 * Text Domain: wp-site-aliases * Domain Path: /wp-site-aliases/assets/languages/ */ @@ -114,5 +114,5 @@ function wp_site_aliases_get_plugin_url() { * @return int */ function wp_site_aliases_get_asset_version() { - return 201704030001; + return 201704110001; } diff --git a/wp-site-aliases/includes/classes/class-wp-db-table-site-aliases.php b/wp-site-aliases/includes/classes/class-wp-db-table-site-aliases.php index 8385d1a..f502b89 100644 --- a/wp-site-aliases/includes/classes/class-wp-db-table-site-aliases.php +++ b/wp-site-aliases/includes/classes/class-wp-db-table-site-aliases.php @@ -24,7 +24,7 @@ final class WP_DB_Table_Site_Aliases extends WP_DB_Table { /** * @var string Database version */ - protected $version = 201703150001; + protected $version = 201704110001; /** * @var boolean This is a global table @@ -38,8 +38,8 @@ final class WP_DB_Table_Site_Aliases extends WP_DB_Table { */ protected function set_schema() { $max_index_length = 191; - $this->schema = "id bigint(20) NOT NULL auto_increment, - blog_id bigint(20) NOT NULL, + $this->schema = "id bigint(20) unsigned NOT NULL auto_increment, + blog_id bigint(20) unsigned NOT NULL default '0', domain varchar(255) NOT NULL, created datetime NOT NULL default '0000-00-00 00:00:00', status varchar(20) NOT NULL default 'active', @@ -55,6 +55,11 @@ protected function set_schema() { * @since 5.0.0 */ protected function upgrade() { - + + // 6.0.0 to 7.0.0 + if ( version_compare( (int) $this->db_version, 201704110001, '<=' ) ) { + $this->db->query( "ALTER TABLE {$this->table_name} MODIFY `id` BIGINT(20) unsigned NOT NULL AUTO_INCREMENT;" ); + $this->db->query( "ALTER TABLE {$this->table_name} MODIFY `blog_id` BIGINT(20) unsigned NOT NULL default 0;" ); + } } } diff --git a/wp-site-aliases/includes/classes/class-wp-db-table-site-aliasmeta.php b/wp-site-aliases/includes/classes/class-wp-db-table-site-aliasmeta.php index fcd8a87..c58e3b8 100644 --- a/wp-site-aliases/includes/classes/class-wp-db-table-site-aliasmeta.php +++ b/wp-site-aliases/includes/classes/class-wp-db-table-site-aliasmeta.php @@ -24,7 +24,7 @@ final class WP_DB_Table_Site_Aliasmeta extends WP_DB_Table { /** * @var string Database version */ - protected $version = 201703150001; + protected $version = 201704110001; /** * @var boolean This is a global table @@ -38,8 +38,8 @@ final class WP_DB_Table_Site_Aliasmeta extends WP_DB_Table { */ protected function set_schema() { $max_index_length = 191; - $this->schema = "meta_id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, - blog_alias_id bigint(20) NOT NULL, + $this->schema = "meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, + blog_alias_id bigint(20) unsigned NOT NULL default 0, meta_key varchar(255) DEFAULT NULL, meta_value longtext DEFAULT NULL, KEY blog_alias_id (blog_alias_id), @@ -57,5 +57,11 @@ protected function upgrade() { if ( version_compare( (int) $this->db_version, 201609100003, '<=' ) ) { $this->db->query( "ALTER TABLE {$this->table_name} CHANGE `id` `meta_id` BIGINT(20) NOT NULL AUTO_INCREMENT;" ); } + + // 6.0.0 to 7.0.0 + if ( version_compare( (int) $this->db_version, 201704110001, '<=' ) ) { + $this->db->query( "ALTER TABLE {$this->table_name} MODIFY `meta_id` BIGINT(20) unsigned NOT NULL AUTO_INCREMENT;" ); + $this->db->query( "ALTER TABLE {$this->table_name} MODIFY `blog_alias_id` BIGINT(20) unsigned NOT NULL default 0;" ); + } } } diff --git a/wp-site-aliases/includes/classes/class-wp-db-table.php b/wp-site-aliases/includes/classes/class-wp-db-table.php index c98ef0c..660ef9c 100644 --- a/wp-site-aliases/includes/classes/class-wp-db-table.php +++ b/wp-site-aliases/includes/classes/class-wp-db-table.php @@ -239,7 +239,7 @@ private function set_wpdb_tables() { /** * Set the database version to the table version. * - * Saves global table version to "wp_sitemeta" with a site ID of -1 + * Saves global table version to "wp_sitemeta" with a site ID of 0 * * @since 1.0.0 */ @@ -250,21 +250,21 @@ private function set_db_version() { // Update the DB version ( true === $this->global ) - ? update_network_option( -1, $this->db_version_key, $this->version ) - : update_option( $this->db_version_key, $this->version ); + ? update_network_option( 0, $this->db_version_key, $this->version ) + : update_option( $this->db_version_key, $this->version ); } /** * Get the table version from the database. * - * Gets global table version from "wp_sitemeta" with a site ID of -1 + * Gets global table version from "wp_sitemeta" with a site ID of 0 * * @since 1.0.0 */ private function get_db_version() { $this->db_version = ( true === $this->global ) - ? get_network_option( -1, $this->db_version_key, false ) - : get_option( $this->db_version_key, false ); + ? get_network_option( 0, $this->db_version_key, false ) + : get_option( $this->db_version_key, false ); } /**