T.ME/BIBIL_0DAY
CasperSecurity


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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/debug_variation_button.php
<?php
/**
 * Debug Variation Button Issue
 * Checks why a track doesn't show the variation button
 * 
 * Usage: debug_variation_button.php?track_id=XXX
 */

require_once 'config/database.php';

$track_id = intval($_GET['track_id'] ?? 0);

if (!$track_id) {
    die("Please provide track_id: debug_variation_button.php?track_id=XXX");
}

$pdo = getDBConnection();

echo "<h2>Debug Variation Button for Track ID: {$track_id}</h2>";
echo "<hr>";

// Get track info
$stmt = $pdo->prepare("
    SELECT 
        mt.id,
        mt.task_id,
        mt.title,
        mt.variations_count as stored_variations_count,
        (SELECT COUNT(*) FROM audio_variations WHERE track_id = mt.id) as actual_variations_count
    FROM music_tracks mt
    WHERE mt.id = ?
");
$stmt->execute([$track_id]);
$track = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$track) {
    die("<p style='color: red;'>Track ID {$track_id} not found.</p>");
}

echo "<h3>Track Information:</h3>";
echo "<ul>";
echo "<li><strong>Track ID:</strong> {$track['id']}</li>";
echo "<li><strong>Task ID:</strong> {$track['task_id']}</li>";
echo "<li><strong>Title:</strong> " . ($track['title'] ?: 'NULL/EMPTY') . "</li>";
echo "<li><strong>Stored variations_count (in music_tracks):</strong> {$track['stored_variations_count']}</li>";
echo "<li><strong>Actual variations_count (from audio_variations table):</strong> {$track['actual_variations_count']}</li>";
echo "</ul>";

// Check what the UI query would return
$stmt = $pdo->prepare("
    SELECT 
        mt.id,
        COALESCE(vars.variation_count, 0) as variation_count
    FROM music_tracks mt
    LEFT JOIN (
        SELECT track_id, COUNT(*) as variation_count 
        FROM audio_variations 
        GROUP BY track_id
    ) vars ON mt.id = vars.track_id
    WHERE mt.id = ?
");
$stmt->execute([$track_id]);
$ui_result = $stmt->fetch(PDO::FETCH_ASSOC);

echo "<h3>UI Query Result (what determines if button shows):</h3>";
echo "<ul>";
echo "<li><strong>variation_count (from LEFT JOIN):</strong> {$ui_result['variation_count']}</li>";
echo "<li><strong>Button will show:</strong> " . ($ui_result['variation_count'] > 0 ? "✅ YES" : "❌ NO") . "</li>";
echo "</ul>";

// Check actual variations in audio_variations table
$stmt = $pdo->prepare("
    SELECT 
        variation_index,
        audio_url,
        source_audio_url,
        stream_audio_url,
        duration,
        title
    FROM audio_variations 
    WHERE track_id = ?
    ORDER BY variation_index ASC
");
$stmt->execute([$track_id]);
$variations = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo "<h3>Variations in audio_variations table:</h3>";
if (empty($variations)) {
    echo "<p style='color: red;'>❌ NO VARIATIONS FOUND in audio_variations table</p>";
    echo "<p><strong>This is why the button doesn't show!</strong></p>";
} else {
    echo "<p style='color: green;'>✅ Found " . count($variations) . " variation(s):</p>";
    echo "<table border='1' cellpadding='5'>";
    echo "<tr><th>Index</th><th>Audio URL</th><th>Source URL</th><th>Stream URL</th><th>Duration</th><th>Title</th></tr>";
    foreach ($variations as $var) {
        echo "<tr>";
        echo "<td>{$var['variation_index']}</td>";
        echo "<td>" . ($var['audio_url'] ?: 'NULL') . "</td>";
        echo "<td>" . ($var['source_audio_url'] ?: 'NULL') . "</td>";
        echo "<td>" . ($var['stream_audio_url'] ?: 'NULL') . "</td>";
        echo "<td>" . ($var['duration'] ?: 'NULL') . "</td>";
        echo "<td>" . ($var['title'] ?: 'NULL') . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}

// Check if there's a mismatch
if ($track['stored_variations_count'] != $track['actual_variations_count']) {
    echo "<hr>";
    echo "<h3 style='color: orange;'>⚠️ MISMATCH DETECTED:</h3>";
    echo "<p><strong>stored_variations_count</strong> ({$track['stored_variations_count']}) != <strong>actual_variations_count</strong> ({$track['actual_variations_count']})</p>";
    echo "<p>This means variations_count in music_tracks doesn't match what's actually in audio_variations table.</p>";
}

// Check task_results for callback data
$taskResultsFile = __DIR__ . "/task_results/{$track['task_id']}.json";
if (file_exists($taskResultsFile)) {
    echo "<hr>";
    echo "<h3>Callback Data (task_results JSON):</h3>";
    $jsonContent = file_get_contents($taskResultsFile);
    $callbackData = json_decode($jsonContent, true);
    
    if ($callbackData && isset($callbackData['data']['data']) && is_array($callbackData['data']['data'])) {
        $audioData = $callbackData['data']['data'];
        echo "<p>✅ Found " . count($audioData) . " items in callback data.data array</p>";
        
        echo "<table border='1' cellpadding='5'>";
        echo "<tr><th>Index</th><th>Has audio_url</th><th>Has source_audio_url</th><th>Has stream_audio_url</th><th>Title</th></tr>";
        foreach ($audioData as $index => $item) {
            $hasAudioUrl = !empty($item['audio_url']);
            $hasSourceUrl = !empty($item['source_audio_url']);
            $hasStreamUrl = !empty($item['stream_audio_url']);
            $title = $item['title'] ?? 'NULL';
            
            echo "<tr>";
            echo "<td>{$index}</td>";
            echo "<td>" . ($hasAudioUrl ? "✅" : "❌") . "</td>";
            echo "<td>" . ($hasSourceUrl ? "✅" : "❌") . "</td>";
            echo "<td>" . ($hasStreamUrl ? "✅" : "❌") . "</td>";
            echo "<td>{$title}</td>";
            echo "</tr>";
        }
        echo "</table>";
        
        // Count how many should have been stored
        $shouldStore = 0;
        foreach ($audioData as $item) {
            $variationAudioUrl = $item['audio_url'] ?? $item['source_audio_url'] ?? $item['stream_audio_url'] ?? null;
            if (!empty($variationAudioUrl)) {
                $shouldStore++;
            }
        }
        
        echo "<p><strong>Variations that should have been stored:</strong> {$shouldStore} (out of " . count($audioData) . " total)</p>";
        echo "<p><strong>Variations actually stored:</strong> {$track['actual_variations_count']}</p>";
        
        if ($shouldStore != $track['actual_variations_count']) {
            echo "<p style='color: red;'>❌ <strong>BUG FOUND:</strong> Should have stored {$shouldStore} but only {$track['actual_variations_count']} were stored!</p>";
        }
    }
} else {
    echo "<hr>";
    echo "<p style='color: orange;'>⚠️ task_results JSON file not found: {$taskResultsFile}</p>";
}

echo "<hr>";
echo "<h3>Summary:</h3>";
echo "<ul>";
echo "<li><strong>Button shows when:</strong> variation_count > 0 (from LEFT JOIN on audio_variations)</li>";
echo "<li><strong>Current variation_count:</strong> {$ui_result['variation_count']}</li>";
echo "<li><strong>Button will show:</strong> " . ($ui_result['variation_count'] > 0 ? "✅ YES" : "❌ NO") . "</li>";
echo "</ul>";

if ($ui_result['variation_count'] == 0 && $track['stored_variations_count'] > 0) {
    echo "<p style='color: red;'><strong>ROOT CAUSE:</strong> variations_count in music_tracks is {$track['stored_variations_count']}, but no variations exist in audio_variations table. The variations were never stored, or were deleted.</p>";
}


CasperSecurity Mini