progress made
This commit is contained in:
@@ -14,6 +14,11 @@ class TWP_Activator {
|
||||
// Set default options
|
||||
self::set_default_options();
|
||||
|
||||
// Set the database version
|
||||
if (defined('TWP_DB_VERSION')) {
|
||||
update_option('twp_db_version', TWP_DB_VERSION);
|
||||
}
|
||||
|
||||
// Create webhook endpoints
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
@@ -55,6 +60,9 @@ class TWP_Activator {
|
||||
return false; // Tables were missing
|
||||
}
|
||||
|
||||
// Check for and perform any needed migrations
|
||||
self::migrate_tables();
|
||||
|
||||
return true; // All tables exist
|
||||
}
|
||||
|
||||
@@ -72,7 +80,7 @@ class TWP_Activator {
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
phone_number varchar(20),
|
||||
schedule_name varchar(100) NOT NULL,
|
||||
days_of_week varchar(20) NOT NULL,
|
||||
days_of_week varchar(100) NOT NULL,
|
||||
start_time time NOT NULL,
|
||||
end_time time NOT NULL,
|
||||
workflow_id varchar(100),
|
||||
@@ -80,6 +88,7 @@ class TWP_Activator {
|
||||
after_hours_action varchar(20) DEFAULT 'workflow',
|
||||
after_hours_workflow_id varchar(100),
|
||||
after_hours_forward_number varchar(20),
|
||||
holiday_dates text,
|
||||
is_active tinyint(1) DEFAULT 1,
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
@@ -92,12 +101,16 @@ class TWP_Activator {
|
||||
$sql_queues = "CREATE TABLE $table_queues (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
queue_name varchar(100) NOT NULL,
|
||||
phone_number varchar(20),
|
||||
agent_group_id int(11),
|
||||
max_size int(11) DEFAULT 10,
|
||||
wait_music_url varchar(255),
|
||||
tts_message text,
|
||||
timeout_seconds int(11) DEFAULT 300,
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
PRIMARY KEY (id),
|
||||
KEY agent_group_id (agent_group_id),
|
||||
KEY phone_number (phone_number)
|
||||
) $charset_collate;";
|
||||
|
||||
// Queued calls table
|
||||
@@ -110,12 +123,15 @@ class TWP_Activator {
|
||||
to_number varchar(20) NOT NULL,
|
||||
position int(11) NOT NULL,
|
||||
status varchar(20) DEFAULT 'waiting',
|
||||
agent_phone varchar(20),
|
||||
agent_call_sid varchar(100),
|
||||
joined_at datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
answered_at datetime,
|
||||
ended_at datetime,
|
||||
PRIMARY KEY (id),
|
||||
KEY queue_id (queue_id),
|
||||
KEY call_sid (call_sid)
|
||||
KEY call_sid (call_sid),
|
||||
KEY status (status)
|
||||
) $charset_collate;";
|
||||
|
||||
// Workflows table
|
||||
@@ -262,6 +278,75 @@ class TWP_Activator {
|
||||
dbDelta($sql_group_members);
|
||||
dbDelta($sql_agent_status);
|
||||
dbDelta($sql_callbacks);
|
||||
|
||||
// Add missing columns for existing installations
|
||||
self::add_missing_columns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing columns for existing installations
|
||||
*/
|
||||
private static function add_missing_columns() {
|
||||
global $wpdb;
|
||||
|
||||
$table_schedules = $wpdb->prefix . 'twp_phone_schedules';
|
||||
|
||||
// Check if holiday_dates column exists
|
||||
$column_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_schedules LIKE 'holiday_dates'");
|
||||
|
||||
if (empty($column_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_schedules ADD COLUMN holiday_dates text AFTER after_hours_forward_number");
|
||||
}
|
||||
|
||||
// Check if days_of_week column needs to be expanded
|
||||
$column_info = $wpdb->get_results("SHOW COLUMNS FROM $table_schedules LIKE 'days_of_week'");
|
||||
if (!empty($column_info) && $column_info[0]->Type === 'varchar(20)') {
|
||||
$wpdb->query("ALTER TABLE $table_schedules MODIFY COLUMN days_of_week varchar(100) NOT NULL");
|
||||
}
|
||||
|
||||
// Add new columns to call queues table
|
||||
$table_queues = $wpdb->prefix . 'twp_call_queues';
|
||||
|
||||
// Check if phone_number column exists in queues table
|
||||
$phone_column_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_queues LIKE 'phone_number'");
|
||||
if (empty($phone_column_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_queues ADD COLUMN phone_number varchar(20) AFTER queue_name");
|
||||
$wpdb->query("ALTER TABLE $table_queues ADD INDEX phone_number (phone_number)");
|
||||
}
|
||||
|
||||
// Check if agent_group_id column exists in queues table
|
||||
$group_column_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_queues LIKE 'agent_group_id'");
|
||||
if (empty($group_column_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_queues ADD COLUMN agent_group_id int(11) AFTER phone_number");
|
||||
$wpdb->query("ALTER TABLE $table_queues ADD INDEX agent_group_id (agent_group_id)");
|
||||
}
|
||||
|
||||
// Add agent columns to queued_calls table if they don't exist
|
||||
$table_queued_calls = $wpdb->prefix . 'twp_queued_calls';
|
||||
|
||||
$agent_phone_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_queued_calls LIKE 'agent_phone'");
|
||||
if (empty($agent_phone_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN agent_phone varchar(20) AFTER status");
|
||||
}
|
||||
|
||||
$agent_call_sid_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_queued_calls LIKE 'agent_call_sid'");
|
||||
if (empty($agent_call_sid_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN agent_call_sid varchar(100) AFTER agent_phone");
|
||||
}
|
||||
|
||||
// Add status index if it doesn't exist
|
||||
$status_index_exists = $wpdb->get_results("SHOW INDEX FROM $table_queued_calls WHERE Key_name = 'status'");
|
||||
if (empty($status_index_exists)) {
|
||||
$wpdb->query("ALTER TABLE $table_queued_calls ADD INDEX status (status)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform table migrations for existing installations
|
||||
*/
|
||||
private static function migrate_tables() {
|
||||
// Call the existing add_missing_columns function which now includes queue columns
|
||||
self::add_missing_columns();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,5 +362,6 @@ class TWP_Activator {
|
||||
add_option('twp_default_queue_size', 10);
|
||||
add_option('twp_urgent_keywords', 'urgent,emergency,important,asap,help');
|
||||
add_option('twp_sms_notification_number', '');
|
||||
add_option('twp_default_sms_number', '');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user