![]() 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/public_html/ |
<?php
// Browser-based Track Sync - No Terminal Hanging
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<h1>🚀 Browser Track Sync - Loading Missing Info on Cards</h1>";
echo "<p>This script syncs all tracks with their complete data from API.Box and displays missing info on the cards.</p>";
// Test database connection
echo "<h2>🔍 Testing Database Connection</h2>";
try {
require_once 'config/database.php';
$pdo = getDBConnection();
if ($pdo) {
echo "<p style='color: green;'>✅ Database connection successful!</p>";
} else {
echo "<p style='color: red;'>❌ Database connection failed</p>";
exit;
}
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Error loading database config: " . $e->getMessage() . "</p>";
exit;
}
// Get tracks with task IDs
echo "<h2>📋 Finding Tracks to Sync</h2>";
try {
$stmt = $pdo->prepare("
SELECT id, title, task_id, status, audio_url
FROM music_tracks
WHERE task_id IS NOT NULL AND task_id != ''
ORDER BY id
");
$stmt->execute();
$tracks = $stmt->fetchAll();
echo "<p>Found " . count($tracks) . " tracks with task IDs</p>";
if (empty($tracks)) {
echo "<p>❌ No tracks found with task IDs</p>";
exit;
}
// Show tracks
echo "<table border='1' style='border-collapse: collapse; margin: 20px 0; width: 100%;'>";
echo "<tr style='background: #f0f0f0;'>";
echo "<th>Track ID</th><th>Title</th><th>Task ID</th><th>Status</th><th>Audio URL</th><th>Sync Action</th>";
echo "</tr>";
foreach ($tracks as $track) {
echo "<tr>";
echo "<td>{$track['id']}</td>";
echo "<td>" . htmlspecialchars($track['title'] ?: 'Untitled') . "</td>";
echo "<td style='font-family: monospace;'>{$track['task_id']}</td>";
echo "<td style='color: " . ($track['status'] === 'complete' ? 'green' : 'orange') . "'>{$track['status']}</td>";
echo "<td>" . ($track['audio_url'] ?: 'None') . "</td>";
echo "<td>";
if ($track['status'] !== 'complete') {
echo "<button onclick='syncTrack({$track['id']}, \"{$track['task_id']}\")' style='background: #48bb78; color: white; border: none; padding: 8px 16px; border-radius: 5px; cursor: pointer;'>🚀 Sync Full Data</button>";
} else {
echo "<span style='color: green;'>✅ Already Complete</span>";
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Database query error: " . $e->getMessage() . "</p>";
exit;
}
// Show current data status
echo "<h2>📊 Current Data Status</h2>";
$stmt = $pdo->prepare("
SELECT
COUNT(*) as total_tracks,
SUM(CASE WHEN lyrics IS NOT NULL AND lyrics != '' THEN 1 ELSE 0 END) as tracks_with_lyrics,
SUM(CASE WHEN metadata IS NOT NULL AND metadata != '' THEN 1 ELSE 0 END) as tracks_with_metadata,
SUM(CASE WHEN duration IS NOT NULL THEN 1 ELSE 0 END) as tracks_with_duration,
SUM(CASE WHEN status = 'complete' THEN 1 ELSE 0 END) as completed_tracks
FROM music_tracks
");
$stmt->execute();
$stats = $stmt->fetch();
echo "<div style='display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;'>";
echo "<div style='background: #f7fafc; padding: 20px; border-radius: 8px; text-align: center;'>";
echo "<h3>📊 Total Tracks</h3>";
echo "<p style='font-size: 24px; font-weight: bold; color: #2d3748;'>{$stats['total_tracks']}</p>";
echo "</div>";
echo "<div style='background: #f0fff4; padding: 20px; border-radius: 8px; text-align: center;'>";
echo "<h3>🎵 With Lyrics</h3>";
echo "<p style='font-size: 24px; font-weight: bold; color: #38a169;'>{$stats['tracks_with_lyrics']}</p>";
echo "</div>";
echo "<div style='background: #fffaf0; padding: 20px; border-radius: 8px; text-align: center;'>";
echo "<h3>📋 With Metadata</h3>";
echo "<p style='font-size: 24px; font-weight: bold; color: #d69e2e;'>{$stats['tracks_with_metadata']}</p>";
echo "</div>";
echo "<div style='background: #f0f9ff; padding: 20px; border-radius: 8px; text-align: center;'>";
echo "<h3>⏱️ With Duration</h3>";
echo "<p style='font-size: 24px; font-weight: bold; color: #3182ce;'>{$stats['tracks_with_duration']}</p>";
echo "</div>";
echo "<div style='background: #f0fff4; padding: 20px; border-radius: 8px; text-align: center;'>";
echo "<h3>✅ Completed</h3>";
echo "<p style='font-size: 24px; font-weight: bold; color: #38a169;'>{$stats['completed_tracks']}</p>";
echo "</div>";
echo "</div>";
echo "<h2>🚀 Sync Actions</h2>";
echo "<p>";
echo "<button onclick='syncAllTracks()' style='background: #667eea; color: white; border: none; padding: 12px 24px; border-radius: 8px; cursor: pointer; font-size: 16px; margin-right: 10px;'>🔄 Sync ALL Tracks with Full Data</button>";
echo "<button onclick='syncErikTrack()' style='background: #ed8936; color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer;'>🎵 Sync Erik's Track</button>";
echo "</p>";
echo "<div id='sync-results' style='margin-top: 20px;'></div>";
?>
<script>
// Sync individual track with full data
async function syncTrack(trackId, taskId) {
const resultsDiv = document.getElementById('sync-results');
resultsDiv.innerHTML = `<p>🔄 Syncing track ${trackId}...</p>`;
try {
const response = await fetch('/sync_single_track.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
track_id: trackId,
task_id: taskId
})
});
const data = await response.json();
if (data.success) {
resultsDiv.innerHTML += `<p style='color: green;'>✅ Track ${trackId} synced successfully!</p>`;
setTimeout(() => location.reload(), 2000);
} else {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Sync failed: ${data.error}</p>`;
}
} catch (error) {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Error: ${error.message}</p>`;
}
}
// Sync all tracks with full data
async function syncAllTracks() {
if (confirm('Sync ALL tracks with full data from API.Box? This may take a while.')) {
const resultsDiv = document.getElementById('sync-results');
resultsDiv.innerHTML = '<p>🔄 Starting sync of all tracks...</p>';
try {
const response = await fetch('/sync_all_tracks_batch.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
const data = await response.json();
if (data.success) {
resultsDiv.innerHTML += `<p style='color: green;'>✅ Sync completed! ${data.synced_count} tracks updated.</p>`;
setTimeout(() => location.reload(), 3000);
} else {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Sync failed: ${data.error}</p>`;
}
} catch (error) {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Error: ${error.message}</p>`;
}
}
}
// Special function to sync Erik's track
async function syncErikTrack() {
if (confirm('Sync Erik\'s track with full data from API.Box?')) {
const resultsDiv = document.getElementById('sync-results');
resultsDiv.innerHTML = '<p>🎵 Syncing Erik\'s track...</p>';
try {
const response = await fetch('/sync_erik_track_full.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
const data = await response.json();
if (data.success) {
resultsDiv.innerHTML += '<p style="color: green;">✅ Erik\'s track synced successfully!</p>';
setTimeout(() => location.reload(), 2000);
} else {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Sync failed: ${data.error}</p>`;
}
} catch (error) {
resultsDiv.innerHTML += `<p style='color: red;'>❌ Error: ${error.message}</p>`;
}
}
}
</script>