Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling for db updates #89

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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