From 18ace04e5bceab4153b5d191461ade954d91b7f7 Mon Sep 17 00:00:00 2001 From: jknapp Date: Sat, 30 Aug 2025 16:42:54 -0700 Subject: [PATCH] Fix database schema for call recording phone number fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- admin/class-twp-admin.php | 3 ++- includes/class-twp-activator.php | 35 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/admin/class-twp-admin.php b/admin/class-twp-admin.php index e12dd1e..2218722 100644 --- a/admin/class-twp-admin.php +++ b/admin/class-twp-admin.php @@ -7379,8 +7379,9 @@ class TWP_Admin { 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::force_table_updates(); try { $twilio = new TWP_Twilio_API(); diff --git a/includes/class-twp-activator.php b/includes/class-twp-activator.php index 04faf30..8178868 100644 --- a/includes/class-twp-activator.php +++ b/includes/class-twp-activator.php @@ -68,6 +68,9 @@ class TWP_Activator { // Check for and perform any needed migrations self::migrate_tables(); + // Always run column updates to catch any schema changes + self::add_missing_columns(); + return true; // All tables exist } @@ -293,8 +296,8 @@ class TWP_Activator { recording_sid varchar(100), recording_url varchar(500), duration int(11) DEFAULT 0, - from_number varchar(20), - to_number varchar(20), + from_number varchar(50), + to_number varchar(50), agent_id bigint(20), status varchar(20) DEFAULT 'recording', started_at datetime DEFAULT CURRENT_TIMESTAMP, @@ -398,6 +401,26 @@ class TWP_Activator { if (empty($notified_timeout_exists)) { $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(); } + /** + * 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 */