| 1 |
<?php |
| 2 |
/** |
| 3 |
* Summary of External_Lists_Schema |
| 4 |
* Use this class to create database tables for External Lists feature. |
| 5 |
*/ |
| 6 |
class External_Lists_Schema |
| 7 |
{ |
| 8 |
/** |
| 9 |
* Summary of init |
| 10 |
* Initializes the database schema for external lists. |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
public static function init() |
| 14 |
{ |
| 15 |
// Initialization code if needed |
| 16 |
self::create_table_external_list(); |
| 17 |
self::create_table_external_list_meta(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Summary of get_external_list_table_name |
| 22 |
* Get the name of the external list table. |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
public static function get_external_list_table_name() |
| 26 |
{ |
| 27 |
global $wpdb; |
| 28 |
return $wpdb->prefix . 'sue_external_lists'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Summary of get_external_list_meta_table_name |
| 33 |
* Get the name of the external list meta table. |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
public static function get_external_list_meta_table_name() |
| 37 |
{ |
| 38 |
global $wpdb; |
| 39 |
return $wpdb->prefix . 'sue_external_list_meta'; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Summary of create_table_external_list |
| 44 |
* Creates the database table for storing external list entries. |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
private static function create_table_external_list() |
| 48 |
{ |
| 49 |
global $wpdb; |
| 50 |
$table_name = self::get_external_list_table_name(); |
| 51 |
|
| 52 |
$charset_collate = $wpdb->get_charset_collate(); |
| 53 |
|
| 54 |
// Table for CSV rows |
| 55 |
$sql_rows = "CREATE TABLE $table_name ( |
| 56 |
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 57 |
list_id VARCHAR(50) NOT NULL, |
| 58 |
user_id BIGINT UNSIGNED NOT NULL, |
| 59 |
email VARCHAR(255) NOT NULL, |
| 60 |
first_name VARCHAR(100) DEFAULT '', |
| 61 |
last_name VARCHAR(100) DEFAULT '', |
| 62 |
title VARCHAR(100) DEFAULT '', |
| 63 |
salutation VARCHAR(50) DEFAULT '', |
| 64 |
field_01 VARCHAR(255) DEFAULT '', |
| 65 |
field_02 VARCHAR(255) DEFAULT '', |
| 66 |
field_03 VARCHAR(255) DEFAULT '', |
| 67 |
field_04 VARCHAR(255) DEFAULT '', |
| 68 |
field_05 VARCHAR(255) DEFAULT '', |
| 69 |
subscribed TINYINT(1) DEFAULT 1, |
| 70 |
created_at DATETIME NOT NULL, |
| 71 |
PRIMARY KEY (id), |
| 72 |
KEY email (email), |
| 73 |
KEY list_id (list_id) |
| 74 |
) $charset_collate;"; |
| 75 |
|
| 76 |
dbDelta($sql_rows); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Summary of create_table_external_list_meta |
| 81 |
* Create table for the list_meta. |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
private static function create_table_external_list_meta() |
| 85 |
{ |
| 86 |
global $wpdb; |
| 87 |
$table_name = self::get_external_list_meta_table_name(); |
| 88 |
|
| 89 |
$charset_collate = $wpdb->get_charset_collate(); |
| 90 |
|
| 91 |
// Table for CSV metadata |
| 92 |
|
| 93 |
$sql_meta = "CREATE TABLE $table_name ( |
| 94 |
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 95 |
list_id VARCHAR(50) NOT NULL, |
| 96 |
list_name VARCHAR(255) NOT NULL, |
| 97 |
user_id BIGINT UNSIGNED NOT NULL, |
| 98 |
created_at DATETIME NOT NULL, |
| 99 |
count INT UNSIGNED DEFAULT 0, |
| 100 |
PRIMARY KEY (id), |
| 101 |
KEY list_id (list_id) |
| 102 |
) $charset_collate;"; |
| 103 |
|
| 104 |
|
| 105 |
dbDelta($sql_meta); |
| 106 |
} |
| 107 |
} |