Fix recording database storage and improve error handling
## Database Issues Fixed - Ensure database table exists before recording operations - Better error handling when database insert fails - Added fallback to stop recording in Twilio even if not found in database - Enhanced error logging for database operations ## Improved Recording Error Handling - Stop recording attempts Twilio API even if database record missing - Better error messages distinguish between database vs Twilio issues - Recording start validates database insert success before proceeding - Enhanced debugging to identify where recordings are failing ## JavaScript Debugging Enhanced - Added console logging for all recording operations - Log recording SID and call SID on start/stop - Better error messages in browser console - Detailed AJAX failure logging ## Technical Improvements - Call TWP_Activator::ensure_tables_exist() before recording operations - Return call_sid in recording start response for debugging - Graceful handling of recordings that exist in Twilio but not database - Better validation of recording SID before stop operations This should resolve the "recording not found in database" error by: 1. Ensuring the database table exists 2. Providing better error feedback when database operations fail 3. Allowing recordings to be stopped even if database tracking failed 4. Enhanced logging to identify root cause of storage issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6817,42 +6817,54 @@ class TWP_Admin {
|
||||
call_sid: callSid,
|
||||
nonce: '<?php echo wp_create_nonce('twp_ajax_nonce'); ?>'
|
||||
}, function(response) {
|
||||
console.log('Recording start response:', response);
|
||||
if (response.success) {
|
||||
adminIsRecording = true;
|
||||
adminRecordingSid = response.data.recording_sid;
|
||||
console.log('Recording started - SID:', adminRecordingSid, 'Call SID:', response.data.call_sid);
|
||||
$recordBtn.html('<span class="dashicons dashicons-controls-volumeoff"></span> Stop Recording').addClass('btn-active');
|
||||
showNotice('Recording started', 'success');
|
||||
} else {
|
||||
console.error('Recording start failed:', response);
|
||||
showNotice('Failed to start recording: ' + (response.data || 'Unknown error'), 'error');
|
||||
}
|
||||
}).fail(function(xhr, status, error) {
|
||||
console.error('Recording start failed:', xhr.responseText);
|
||||
console.error('Recording start AJAX failed:', xhr.responseText);
|
||||
showNotice('Failed to start recording: ' + error, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function adminStopRecording() {
|
||||
if (!adminRecordingSid) return;
|
||||
if (!adminRecordingSid) {
|
||||
console.error('No recording SID to stop');
|
||||
showNotice('No recording to stop', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
var callSid = currentCall ? (currentCall.parameters.CallSid || currentCall.customParameters.CallSid) : '';
|
||||
var $recordBtn = $('#admin-record-btn');
|
||||
|
||||
console.log('Stopping recording - SID:', adminRecordingSid, 'Call SID:', callSid);
|
||||
|
||||
$.post(ajaxurl, {
|
||||
action: 'twp_stop_recording',
|
||||
call_sid: callSid,
|
||||
recording_sid: adminRecordingSid,
|
||||
nonce: '<?php echo wp_create_nonce('twp_ajax_nonce'); ?>'
|
||||
}, function(response) {
|
||||
console.log('Recording stop response:', response);
|
||||
if (response.success) {
|
||||
adminIsRecording = false;
|
||||
adminRecordingSid = null;
|
||||
$recordBtn.html('<span class="dashicons dashicons-controls-volumeon"></span> Record').removeClass('btn-active');
|
||||
showNotice('Recording stopped', 'info');
|
||||
} else {
|
||||
console.error('Recording stop failed:', response);
|
||||
showNotice('Failed to stop recording: ' + (response.data || 'Unknown error'), 'error');
|
||||
}
|
||||
}).fail(function() {
|
||||
showNotice('Failed to stop recording', 'error');
|
||||
}).fail(function(xhr, status, error) {
|
||||
console.error('Recording stop AJAX failed:', xhr.responseText);
|
||||
showNotice('Failed to stop recording: ' + error, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7139,6 +7151,9 @@ class TWP_Admin {
|
||||
|
||||
error_log("TWP: Starting recording for call SID: $call_sid");
|
||||
|
||||
// Ensure database table exists
|
||||
TWP_Activator::ensure_tables_exist();
|
||||
|
||||
try {
|
||||
$twilio = new TWP_Twilio_API();
|
||||
$client = $twilio->get_client();
|
||||
@@ -7183,11 +7198,16 @@ class TWP_Admin {
|
||||
|
||||
if ($insert_result === false) {
|
||||
error_log("TWP: Database insert failed: " . $wpdb->last_error);
|
||||
wp_send_json_error("Failed to save recording to database: " . $wpdb->last_error);
|
||||
return;
|
||||
} else {
|
||||
error_log("TWP: Recording saved to database - Recording SID: {$recording->sid}, Call SID: $call_sid");
|
||||
}
|
||||
|
||||
wp_send_json_success([
|
||||
'message' => 'Recording started',
|
||||
'recording_sid' => $recording->sid
|
||||
'recording_sid' => $recording->sid,
|
||||
'call_sid' => $call_sid // Include call_sid for debugging
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log("TWP: Recording start error: " . $e->getMessage());
|
||||
@@ -7222,8 +7242,23 @@ class TWP_Admin {
|
||||
));
|
||||
|
||||
if (!$recording_info) {
|
||||
wp_send_json_error('Recording not found in database');
|
||||
return;
|
||||
error_log("TWP: Recording $recording_sid not found in database, attempting Twilio-only stop");
|
||||
|
||||
// Try to stop the recording in Twilio anyway (might exist there but not in DB)
|
||||
try {
|
||||
$twilio = new TWP_Twilio_API();
|
||||
$client = $twilio->get_client();
|
||||
|
||||
$recording = $client->recordings($recording_sid)->update(['status' => 'stopped']);
|
||||
error_log("TWP: Successfully stopped recording $recording_sid in Twilio despite DB issue");
|
||||
|
||||
wp_send_json_success(['message' => 'Recording stopped (was not tracked in database)']);
|
||||
return;
|
||||
} catch (Exception $twilio_error) {
|
||||
error_log("TWP: Recording $recording_sid not found in database or Twilio: " . $twilio_error->getMessage());
|
||||
wp_send_json_error('Recording not found in database or Twilio system');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($recording_info->status === 'completed') {
|
||||
|
Reference in New Issue
Block a user