Skip to content

Commit

Permalink
Merge pull request #89 from humanmade/db-updates
Browse files Browse the repository at this point in the history
Better handling for db updates
  • Loading branch information
roborourke committed Jun 5, 2017
2 parents f46c9cf + 59f673d commit 671f147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "humanmade/mercator",
"description": "WordPress multisite domain mapping for the modern era.",
"homepage": "https://github.com/humanmade/Mercator",
"version": "1.0.0",
"keywords": [
"wordpress"
],
Expand Down
21 changes: 17 additions & 4 deletions mercator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Current version of Mercator.
*/
const VERSION = '0.1';
const VERSION = '1.0.0';

require __DIR__ . '/class-mapping.php';
require __DIR__ . '/class-network-mapping.php';
Expand Down Expand Up @@ -99,6 +99,11 @@ function startup() {
WP_CLI::add_command( 'mercator network-mapping', __NAMESPACE__ . '\\CLI\\Network_Mapping_Command' );
}

/**
* Check the table exists and that we're up to date.
*/
add_action( 'admin_init', __NAMESPACE__ . '\\check_table', -101 );

/**
* Fired after Mercator core has been loaded
*
Expand Down Expand Up @@ -131,8 +136,6 @@ function check_domain_mapping( $site, $domain ) {
return $site;
}

global $wpdb;

// Grab both WWW and no-WWW
if ( strpos( $domain, 'www.' ) === 0 ) {
$www = $domain;
Expand Down Expand Up @@ -186,10 +189,14 @@ function check_domain_mapping( $site, $domain ) {
function check_table() {
global $wpdb;

if ( get_option( 'mercator.db.version' ) === VERSION ) {
return 'exists';
}

$schema = "CREATE TABLE {$wpdb->dmtable} (
id bigint(20) NOT NULL auto_increment,
blog_id bigint(20) NOT NULL,
domain varchar(255) NOT NULL,
domain varchar(191) NOT NULL,
active tinyint(4) default 1,
PRIMARY KEY (id),
KEY blog_id (blog_id,domain,active),
Expand Down Expand Up @@ -219,6 +226,12 @@ function check_table() {
return 'exists';
}

// utf8mb4 conversion.
maybe_convert_table_to_utf8mb4( $wpdb->dmtable );

// Update db version option.
update_option( 'mercator.db.version', VERSION );

return 'created';
}

Expand Down

0 comments on commit 671f147

Please sign in to comment.