![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/ |
<?php
// Script to check and update processing tracks that should be marked as failed
// This fixes tracks that were rejected but stuck in processing status
require_once 'config/database.php';
header('Content-Type: text/html; charset=utf-8');
echo "<h1>đ§ Fix Failed Tracks</h1>";
echo "<p>Checking all processing tracks and updating those that should be failed...</p>";
$pdo = getDBConnection();
if (!$pdo) {
echo "<p style='color: red;'>â Database connection failed</p>";
exit;
}
// Get all processing tracks
$stmt = $pdo->query("
SELECT id, task_id, title, status, created_at, updated_at
FROM music_tracks
WHERE status = 'processing'
ORDER BY created_at DESC
");
$processing_tracks = $stmt->fetchAll();
if (empty($processing_tracks)) {
echo "<p style='color: green;'>â
No processing tracks found</p>";
exit;
}
echo "<p>Found " . count($processing_tracks) . " processing tracks to check</p>";
echo "<hr>";
$api_key = '63edba40620216c5aa2c04240ac41dbd';
$updated_count = 0;
$failed_count = 0;
$still_processing_count = 0;
$error_count = 0;
foreach ($processing_tracks as $track) {
$track_id = $track['id'];
$task_id = $track['task_id'];
$title = $track['title'] ?: 'Untitled Track';
echo "<div style='margin: 10px 0; padding: 10px; border: 1px solid #ddd;'>";
echo "<strong>Track ID:</strong> $track_id | <strong>Task ID:</strong> " . ($task_id ?: 'N/A') . " | <strong>Title:</strong> " . htmlspecialchars($title) . "<br>";
// Skip if no task_id
if (empty($task_id) || $task_id === 'unknown') {
echo "<span style='color: orange;'>â ī¸ No valid task_id - skipping</span><br>";
$error_count++;
echo "</div>";
continue;
}
// Check API.Box status
$api_url = "https://api.api.box/api/v1/status/$task_id";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json',
'User-Agent: SoundStudioPro-FixFailed/1.0'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200 && $response) {
$api_data = json_decode($response, true);
if ($api_data && isset($api_data['status'])) {
$api_status = $api_data['status'];
if ($api_status === 'failed') {
// Track failed in API.Box - update to failed
$error_msg = $api_data['error'] ?? $api_data['msg'] ?? 'Generation failed';
$error_metadata = [
'code' => 531,
'msg' => $error_msg,
'error_type' => 'generation_failed',
'data' => $api_data,
'timestamp' => date('Y-m-d H:i:s'),
'auto_fixed' => true,
'fixed_by' => 'fix_failed_tracks.php'
];
$update_stmt = $pdo->prepare("
UPDATE music_tracks
SET status = 'failed',
metadata = ?,
updated_at = NOW()
WHERE id = ?
");
if ($update_stmt->execute([json_encode($error_metadata), $track_id])) {
$rows_affected = $update_stmt->rowCount();
if ($rows_affected > 0) {
echo "<span style='color: green;'>â
Updated to FAILED (API status: failed) - Error: " . htmlspecialchars($error_msg) . "</span><br>";
$updated_count++;
$failed_count++;
} else {
echo "<span style='color: orange;'>â ī¸ Update returned success but no rows affected</span><br>";
}
} else {
echo "<span style='color: red;'>â Failed to update database</span><br>";
$error_count++;
}
} elseif ($api_status === 'completed' && isset($api_data['result']['audio_url'])) {
// Track completed - should be handled by callback, but we can note it
echo "<span style='color: blue;'>âšī¸ Track is completed in API but still processing locally - may need callback</span><br>";
$still_processing_count++;
} elseif ($api_status === 'processing') {
// Still processing - leave it
echo "<span style='color: blue;'>âšī¸ Still processing in API.Box</span><br>";
$still_processing_count++;
} else {
// Unknown status
echo "<span style='color: orange;'>â ī¸ Unknown API status: $api_status</span><br>";
$error_count++;
}
} else {
echo "<span style='color: orange;'>â ī¸ Invalid API response format</span><br>";
$error_count++;
}
} elseif ($http_code === 404) {
// Task not found in API.Box - mark as failed
$error_metadata = [
'code' => 404,
'msg' => 'Task not found in API.Box',
'error_type' => 'task_not_found',
'timestamp' => date('Y-m-d H:i:s'),
'auto_fixed' => true,
'fixed_by' => 'fix_failed_tracks.php'
];
$update_stmt = $pdo->prepare("
UPDATE music_tracks
SET status = 'failed',
metadata = ?,
updated_at = NOW()
WHERE id = ?
");
if ($update_stmt->execute([json_encode($error_metadata), $track_id])) {
$rows_affected = $update_stmt->rowCount();
if ($rows_affected > 0) {
echo "<span style='color: green;'>â
Updated to FAILED (Task not found in API - 404)</span><br>";
$updated_count++;
$failed_count++;
} else {
echo "<span style='color: orange;'>â ī¸ Update returned success but no rows affected</span><br>";
}
} else {
echo "<span style='color: red;'>â Failed to update database</span><br>";
$error_count++;
}
} else {
echo "<span style='color: orange;'>â ī¸ API check failed (HTTP $http_code) - skipping</span><br>";
$error_count++;
}
echo "</div>";
}
echo "<hr>";
echo "<h2>đ Summary</h2>";
echo "<p><strong>Total processing tracks checked:</strong> " . count($processing_tracks) . "</p>";
echo "<p style='color: green;'><strong>Tracks updated to failed:</strong> $updated_count</p>";
echo "<p style='color: blue;'><strong>Still processing:</strong> $still_processing_count</p>";
echo "<p style='color: orange;'><strong>Errors/skipped:</strong> $error_count</p>";
if ($updated_count > 0) {
echo "<p style='color: green; font-weight: bold;'>â
Successfully fixed $updated_count stuck tracks!</p>";
}
?>