| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\Database\Migrations; |
| 4 |
|
| 5 |
class BoardTermMigrator |
| 6 |
{ |
| 7 |
/** |
| 8 |
* @param $isForced |
| 9 |
* @return void |
| 10 |
*/ |
| 11 |
public static function migrate($isForced = true) |
| 12 |
{ |
| 13 |
global $wpdb; |
| 14 |
|
| 15 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 16 |
$table = $wpdb->prefix . 'fbs_board_terms'; |
| 17 |
/* |
| 18 |
* This Schema is for the Board Labels and Stages |
| 19 |
*/ |
| 20 |
if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) != $table || $isForced) { |
| 21 |
$sql = "CREATE TABLE $table ( |
| 22 |
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 23 |
`board_id` INT UNSIGNED NOT NULL, |
| 24 |
`title` VARCHAR(100) NULL COMMENT 'Title of the stage or label. Incase of label tile can be null with color only', |
| 25 |
`slug` VARCHAR(100) NULL COMMENT 'Slug of the stage or label', |
| 26 |
`type` VARCHAR(50) NOT NULL DEFAULT 'stage' COMMENT 'stage or label', |
| 27 |
`position` decimal(10,2) NOT NULL DEFAULT '1' COMMENT 'Position of the stage or label. 1 = first, 2 = second, etc.', |
| 28 |
`color` VARCHAR(50) NULL COMMENT 'Text Color of the stage or label', |
| 29 |
`bg_color` VARCHAR(50) NULL COMMENT 'Background Color of the stage or label', |
| 30 |
`settings` TEXT NULL COMMENT 'Serialized Settings', |
| 31 |
`archived_at` TIMESTAMP NULL, |
| 32 |
`created_at` TIMESTAMP NULL, |
| 33 |
`updated_at` TIMESTAMP NULL, |
| 34 |
KEY `title` (`title`), |
| 35 |
KEY `type` (`type`), |
| 36 |
KEY `position` (`position`), |
| 37 |
KEY `slug` (`slug`) |
| 38 |
) $charsetCollate;"; |
| 39 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 40 |
dbDelta($sql); |
| 41 |
} else { |
| 42 |
// change column type from int to decimal - for already installed sites |
| 43 |
$column_name = 'position'; |
| 44 |
$preparedQuery = $wpdb->prepare("DESCRIBE $table %s", $column_name); |
| 45 |
$dataType = $wpdb->get_row($preparedQuery); |
| 46 |
if (strpos($dataType->Type, 'int') !== false) { |
| 47 |
$sql = $wpdb->prepare( |
| 48 |
"ALTER TABLE $table MODIFY $column_name decimal(10,2) NOT NULL DEFAULT '1' COMMENT 'Position: 1 = top/first, 2 = second/second in top, etc.';" |
| 49 |
); |
| 50 |
$wpdb->query($sql); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
} |
| 56 |
|