| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('UD_CENTRAL_DIR')) die('Security check'); |
| 4 |
|
| 5 |
class UpdraftCentral_Activation { |
| 6 |
|
| 7 |
private $table_prefix; |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
$this->table_prefix = defined('UPDRAFTCENTRAL_TABLE_PREFIX') ? UPDRAFTCENTRAL_TABLE_PREFIX : 'updraftcentral_'; |
| 11 |
$this->create_tables(); |
| 12 |
} |
| 13 |
|
| 14 |
public function create_tables() { |
| 15 |
global $wpdb; |
| 16 |
|
| 17 |
// $wpdb->hide_errors(); |
| 18 |
|
| 19 |
$our_prefix = $wpdb->prefix.$this->table_prefix; |
| 20 |
$collate = ''; |
| 21 |
|
| 22 |
if ( $wpdb->has_cap( 'collation' ) ) { |
| 23 |
if ( ! empty($wpdb->charset ) ) { |
| 24 |
$collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
| 25 |
} |
| 26 |
if ( ! empty($wpdb->collate ) ) { |
| 27 |
$collate .= " COLLATE $wpdb->collate"; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 32 |
|
| 33 |
// Important: obey the magical/arbitrary rules for formatting this stuff: https://codex.wordpress.org/Creating_Tables_with_Plugins |
| 34 |
// Otherwise, you get SQL errors and unwanted header output warnings when activating |
| 35 |
|
| 36 |
$create_tables = "CREATE TABLE ".$our_prefix."sites ( |
| 37 |
site_id bigint(20) NOT NULL auto_increment, |
| 38 |
user_id bigint(20) NOT NULL, |
| 39 |
url varchar(300) NOT NULL, |
| 40 |
key_local_private blob, |
| 41 |
key_remote_public blob, |
| 42 |
key_name_indicator varchar(200) NOT NULL, |
| 43 |
description text, |
| 44 |
sequence_id bigint(20) DEFAULT 0, |
| 45 |
remote_user_id bigint(20) NOT NULL, |
| 46 |
remote_user_login varchar(60), |
| 47 |
remote_site_id bigint(20) DEFAULT 0, |
| 48 |
connection_method varchar(30), |
| 49 |
send_cors_headers tinyint(1) DEFAULT 1, |
| 50 |
PRIMARY KEY (site_id), |
| 51 |
KEY user_id (user_id), |
| 52 |
KEY url (url) |
| 53 |
) $collate; |
| 54 |
"; |
| 55 |
// KEY attribute_name (attribute_name) |
| 56 |
dbDelta($create_tables); |
| 57 |
|
| 58 |
$create_tables = "CREATE TABLE ".$our_prefix."site_temporary_keys ( |
| 59 |
key_id bigint(20) NOT NULL auto_increment, |
| 60 |
key_local_private blob, |
| 61 |
key_remote_public blob, |
| 62 |
created bigint(20), |
| 63 |
PRIMARY KEY (key_id), |
| 64 |
KEY created (created) |
| 65 |
) $collate; |
| 66 |
"; |
| 67 |
|
| 68 |
dbDelta($create_tables); |
| 69 |
|
| 70 |
$max_index_length = 191; |
| 71 |
$create_tables = "CREATE TABLE ".$our_prefix."sitemeta ( |
| 72 |
meta_id bigint(20) NOT NULL auto_increment, |
| 73 |
site_id bigint(20) NOT NULL default '0', |
| 74 |
meta_key varchar(255) default NULL, |
| 75 |
meta_value longtext, |
| 76 |
PRIMARY KEY (meta_id), |
| 77 |
KEY meta_key (meta_key($max_index_length)), |
| 78 |
KEY site_id (site_id) |
| 79 |
) $collate; |
| 80 |
"; |
| 81 |
|
| 82 |
dbDelta($create_tables); |
| 83 |
} |
| 84 |
} |
| 85 |
|