Fix missing enqueued_at column in twp_queued_calls table

Database Schema Fixes:
- Added enqueued_at column migration to twp_queued_calls table
- Updated personal queue query to use COALESCE for column compatibility
- Enhanced requeue function to handle both enqueued_at and joined_at columns
- Added dynamic column detection for backwards compatibility

SQL Error Resolution:
- Fixes "Unknown column 'qc.enqueued_at' in 'ORDER BY'" errors
- Maintains compatibility with existing installations
- Ensures proper queue ordering functionality

The code now gracefully handles both old (joined_at) and new (enqueued_at)
column structures, with automatic migration adding the missing column.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-30 17:37:25 -07:00
parent 82e591b367
commit 0b8c5f4a4c
2 changed files with 24 additions and 4 deletions

View File

@@ -402,6 +402,13 @@ class TWP_Activator {
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN notified_timeout datetime AFTER agent_call_sid");
}
// Add enqueued_at column (some code uses this instead of joined_at)
$enqueued_at_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_queued_calls LIKE 'enqueued_at'");
if (empty($enqueued_at_exists)) {
$wpdb->query("ALTER TABLE $table_queued_calls ADD COLUMN enqueued_at datetime DEFAULT CURRENT_TIMESTAMP AFTER notified_timeout");
error_log('TWP: Added enqueued_at column to twp_queued_calls table');
}
// Fix phone number field lengths in call recordings table for outbound calls
$table_recordings = $wpdb->prefix . 'twp_call_recordings';