| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\Database\Migrations; |
| 4 |
|
| 5 |
class TicketsMigrator |
| 6 |
{ |
| 7 |
static $tableName = 'fs_tickets'; |
| 8 |
|
| 9 |
public static function migrate() |
| 10 |
{ |
| 11 |
global $wpdb; |
| 12 |
|
| 13 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 14 |
|
| 15 |
$table = $wpdb->prefix . static::$tableName; |
| 16 |
|
| 17 |
if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { |
| 18 |
$sql = "CREATE TABLE $table ( |
| 19 |
`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 20 |
`customer_id` BIGINT(20) UNSIGNED NULL, |
| 21 |
`agent_id` BIGINT(20) UNSIGNED NULL, |
| 22 |
`mailbox_id` BIGINT(20) UNSIGNED NULL, |
| 23 |
`product_id` BIGINT(20) UNSIGNED NULL, |
| 24 |
`ticket_type_id` BIGINT(20) UNSIGNED NULL, |
| 25 |
`product_source` VARCHAR(192) NULL, |
| 26 |
`privacy` VARCHAR(100) DEFAULT 'private', |
| 27 |
`priority` VARCHAR(100) DEFAULT 'normal', |
| 28 |
`client_priority` VARCHAR(100) DEFAULT 'normal', |
| 29 |
`status` VARCHAR(100) DEFAULT 'new', |
| 30 |
`title` VARCHAR(192) NULL, |
| 31 |
`slug` VARCHAR(192) NULL, |
| 32 |
`hash` VARCHAR(192) NULL, |
| 33 |
`content_hash` VARCHAR(192) NULL, |
| 34 |
`message_id` VARCHAR(192) NULL, |
| 35 |
`source` VARCHAR(192) NULL, |
| 36 |
`content` LONGTEXT NULL, |
| 37 |
`secret_content` LONGTEXT NULL, |
| 38 |
`last_agent_response` TIMESTAMP NULL, |
| 39 |
`last_customer_response` TIMESTAMP NULL, |
| 40 |
`waiting_since` TIMESTAMP NULL, |
| 41 |
`response_count` INT(11) DEFAULT 0, |
| 42 |
`first_response_time` INT(11) NULL, /* Seconds took for first contact */ |
| 43 |
`total_close_time` INT(11) NULL, /* Seconds took for closing this ticket */ |
| 44 |
`resolved_at` TIMESTAMP NULL, |
| 45 |
`closed_by` BIGINT(20) UNSIGNED NULL, |
| 46 |
`created_at` TIMESTAMP NULL, |
| 47 |
`updated_at` TIMESTAMP NULL |
| 48 |
) $charsetCollate;"; |
| 49 |
dbDelta($sql); |
| 50 |
} else { |
| 51 |
// @todo: We will remove this on final release |
| 52 |
// This is only for beta users |
| 53 |
$existing_columns = $wpdb->get_col("DESC {$table}", 0); |
| 54 |
if(!in_array('waiting_since', $existing_columns)) { |
| 55 |
$query = 'ALTER TABLE '.$table.' ADD `waiting_since` timestamp NULL AFTER `last_customer_response`'; |
| 56 |
$wpdb->query($query); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|