Skip to content

Commit

Permalink
Update database schemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
JJJ committed Apr 12, 2017
1 parent 446e073 commit 104ead5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,6 +74,9 @@ http:https://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
Expand Down
4 changes: 2 additions & 2 deletions wp-site-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down Expand Up @@ -114,5 +114,5 @@ function wp_site_aliases_get_plugin_url() {
* @return int
*/
function wp_site_aliases_get_asset_version() {
return 201704030001;
return 201704110001;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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;" );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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;" );
}
}
}
12 changes: 6 additions & 6 deletions wp-site-aliases/includes/classes/class-wp-db-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 );
}

/**
Expand Down

0 comments on commit 104ead5

Please sign in to comment.