Fix database schema for call recording phone number fields
- Increased from_number and to_number fields from varchar(20) to varchar(50) - Added automatic migration to update existing table schemas - Addresses issue with outbound calls having long phone number formats - Added force_table_updates() method for manual schema updates - Enhanced ensure_tables_exist() to always run column migrations - Fixes recording database insertion failures for international numbers The original varchar(20) was too small for modern phone number formats, especially for outbound calls which may include client: prefixes and international numbers with country codes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -7379,8 +7379,9 @@ class TWP_Admin {
|
|||||||
|
|
||||||
error_log("TWP: Starting recording for call SID: $call_sid");
|
error_log("TWP: Starting recording for call SID: $call_sid");
|
||||||
|
|
||||||
// Ensure database table exists
|
// Ensure database table exists and run any migrations
|
||||||
TWP_Activator::ensure_tables_exist();
|
TWP_Activator::ensure_tables_exist();
|
||||||
|
TWP_Activator::force_table_updates();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$twilio = new TWP_Twilio_API();
|
$twilio = new TWP_Twilio_API();
|
||||||
|
@@ -68,6 +68,9 @@ class TWP_Activator {
|
|||||||
// Check for and perform any needed migrations
|
// Check for and perform any needed migrations
|
||||||
self::migrate_tables();
|
self::migrate_tables();
|
||||||
|
|
||||||
|
// Always run column updates to catch any schema changes
|
||||||
|
self::add_missing_columns();
|
||||||
|
|
||||||
return true; // All tables exist
|
return true; // All tables exist
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,8 +296,8 @@ class TWP_Activator {
|
|||||||
recording_sid varchar(100),
|
recording_sid varchar(100),
|
||||||
recording_url varchar(500),
|
recording_url varchar(500),
|
||||||
duration int(11) DEFAULT 0,
|
duration int(11) DEFAULT 0,
|
||||||
from_number varchar(20),
|
from_number varchar(50),
|
||||||
to_number varchar(20),
|
to_number varchar(50),
|
||||||
agent_id bigint(20),
|
agent_id bigint(20),
|
||||||
status varchar(20) DEFAULT 'recording',
|
status varchar(20) DEFAULT 'recording',
|
||||||
started_at datetime DEFAULT CURRENT_TIMESTAMP,
|
started_at datetime DEFAULT CURRENT_TIMESTAMP,
|
||||||
@@ -398,6 +401,26 @@ class TWP_Activator {
|
|||||||
if (empty($notified_timeout_exists)) {
|
if (empty($notified_timeout_exists)) {
|
||||||
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN notified_timeout datetime AFTER agent_call_sid");
|
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN notified_timeout datetime AFTER agent_call_sid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix phone number field lengths in call recordings table for outbound calls
|
||||||
|
$table_recordings = $wpdb->prefix . 'twp_call_recordings';
|
||||||
|
|
||||||
|
// Check if table exists first
|
||||||
|
$table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_recordings));
|
||||||
|
if ($table_exists) {
|
||||||
|
// Check current column lengths
|
||||||
|
$from_column = $wpdb->get_results("SHOW COLUMNS FROM $table_recordings LIKE 'from_number'");
|
||||||
|
if (!empty($from_column) && strpos($from_column[0]->Type, 'varchar(20)') !== false) {
|
||||||
|
$wpdb->query("ALTER TABLE $table_recordings MODIFY COLUMN from_number varchar(50)");
|
||||||
|
error_log('TWP: Updated from_number column to varchar(50)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$to_column = $wpdb->get_results("SHOW COLUMNS FROM $table_recordings LIKE 'to_number'");
|
||||||
|
if (!empty($to_column) && strpos($to_column[0]->Type, 'varchar(20)') !== false) {
|
||||||
|
$wpdb->query("ALTER TABLE $table_recordings MODIFY COLUMN to_number varchar(50)");
|
||||||
|
error_log('TWP: Updated to_number column to varchar(50)');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -408,6 +431,14 @@ class TWP_Activator {
|
|||||||
self::add_missing_columns();
|
self::add_missing_columns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force database table updates - can be called manually if needed
|
||||||
|
*/
|
||||||
|
public static function force_table_updates() {
|
||||||
|
self::add_missing_columns();
|
||||||
|
error_log('TWP: Forced database table updates completed');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default plugin options
|
* Set default plugin options
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user