diff --git a/composer.json b/composer.json index 049e6e9..48f0ce1 100644 --- a/composer.json +++ b/composer.json @@ -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" ], diff --git a/mercator.php b/mercator.php index 35a33aa..6346bea 100644 --- a/mercator.php +++ b/mercator.php @@ -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'; @@ -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 * @@ -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; @@ -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), @@ -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'; }