| 1 |
<?php |
| 2 |
// phpcs:disable |
| 3 |
|
| 4 |
namespace FluentCommunity\Database\Migrations; |
| 5 |
|
| 6 |
class XProfileMigrator |
| 7 |
{ |
| 8 |
/** |
| 9 |
* Migrate the table. |
| 10 |
* |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
public static function migrate() |
| 14 |
{ |
| 15 |
global $wpdb; |
| 16 |
|
| 17 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 18 |
|
| 19 |
$table = $wpdb->prefix . 'fcom_xprofile'; |
| 20 |
$indexPrefix = $wpdb->prefix . 'fcom_xp_'; |
| 21 |
|
| 22 |
if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { |
| 23 |
$sql = "CREATE TABLE $table ( |
| 24 |
`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 25 |
`user_id` BIGINT UNSIGNED NOT NULL UNIQUE, |
| 26 |
`total_points` INT(11) UNSIGNED NOT NULL DEFAULT 0, |
| 27 |
`username` VARCHAR(100) NULL, |
| 28 |
`status` enum('active', 'blocked', 'pending') NOT NULL DEFAULT 'active', |
| 29 |
`is_verified` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 30 |
`display_name` VARCHAR(192) NULL, |
| 31 |
`avatar` TEXT NULL, |
| 32 |
`short_description` TEXT NULL, |
| 33 |
`last_activity` DATETIME NULL, |
| 34 |
`meta` LONGTEXT NULL, |
| 35 |
`created_at` TIMESTAMP NULL, |
| 36 |
`updated_at` TIMESTAMP NULL, |
| 37 |
INDEX `{$indexPrefix}_user_id` (`user_id`), |
| 38 |
INDEX `{$indexPrefix}_username` (`username`), |
| 39 |
INDEX `{$indexPrefix}_last_activity` (`last_activity`) |
| 40 |
) $charsetCollate;"; |
| 41 |
dbDelta($sql); |
| 42 |
} |
| 43 |
|
| 44 |
$indexNames = $wpdb->get_col("SHOW INDEX FROM $table", 2); |
| 45 |
if (!in_array("{$indexPrefix}_last_activity", $indexNames, true)) { |
| 46 |
$wpdb->query("ALTER TABLE $table ADD INDEX `{$indexPrefix}_last_activity` (`last_activity`)"); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|