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/.cursor-server/data/User/History/3180573f/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/.cursor-server/data/User/History/3180573f/JpKf.php
<?php
// Fix Variation URLs by Mapping to Actual Downloaded Files
require_once 'config/database.php';

$output = [];

$output[] = "=== FIXING VARIATION URLS ===";
$output[] = "Time: " . date('Y-m-d H:i:s');

$pdo = getDBConnection();
if (!$pdo) {
    $output[] = "❌ Database connection failed";
    file_put_contents('fix_variation_urls_output.txt', implode("\n", $output));
    exit;
}

$output[] = "✅ Database connected";

// Start transaction for safety
$pdo->beginTransaction();

try {
    // Get all audio files
    $audioDir = 'audio_files/';
    if (!is_dir($audioDir)) {
        throw new Exception("Audio files directory not found");
    }
    
    $audioFiles = scandir($audioDir);
    $audioFiles = array_filter($audioFiles, function($file) {
        return $file !== '.' && $file !== '..' && pathinfo($file, PATHINFO_EXTENSION) === 'mp3';
    });
    
    $output[] = "";
    $output[] = "=== AUDIO FILES ANALYSIS ===";
    $output[] = "Total audio files: " . count($audioFiles);
    
    // Group files by task ID
    $taskFiles = [];
    foreach ($audioFiles as $file) {
        if (strpos($file, '_variation_') !== false) {
            // This is a variation file
            $parts = explode('_variation_', $file);
            $taskId = $parts[0];
            $variationIndex = intval(explode('.', $parts[1])[0]);
            
            if (!isset($taskFiles[$taskId])) {
                $taskFiles[$taskId] = [];
            }
            $taskFiles[$taskId][$variationIndex] = '/audio_files/' . $file;
        }
    }
    
    $output[] = "Task IDs with variation files: " . count($taskFiles);
    
    // Show sample mapping
    $output[] = "";
    $output[] = "=== SAMPLE TASK TO FILES MAPPING ===";
    foreach (array_slice($taskFiles, 0, 3) as $taskId => $variations) {
        $output[] = "Task ID: {$taskId}";
        foreach ($variations as $index => $path) {
            $output[] = "  Variation {$index}: {$path}";
        }
        $output[] = "";
    }
    
    // Get all variations that need fixing
    $stmt = $pdo->query("
        SELECT 
            av.id,
            av.track_id,
            av.variation_index,
            av.audio_url,
            mt.task_id,
            mt.title
        FROM audio_variations av
        JOIN music_tracks mt ON av.track_id = mt.id
        WHERE av.audio_url LIKE 'http%'
        ORDER BY av.track_id ASC, av.variation_index ASC
    ");
    
    $externalVariations = $stmt->fetchAll();
    
    $output[] = "";
    $output[] = "=== VARIATIONS WITH EXTERNAL URLS ===";
    $output[] = "Found " . count($externalVariations) . " variations with external URLs";
    
    $updatedCount = 0;
    $skippedCount = 0;
    $noFileCount = 0;
    
    foreach ($externalVariations as $variation) {
        $databaseTaskId = $variation['task_id'];
        $output[] = "";
        $output[] = "Processing variation {$variation['id']} (Track {$variation['track_id']}, Index {$variation['variation_index']})";
        $output[] = "  Database Task ID: {$databaseTaskId}";
        $output[] = "  Current Audio URL: {$variation['audio_url']}";
        
        // Check if we have local files for this task ID
        if (isset($taskFiles[$databaseTaskId]) && isset($taskFiles[$databaseTaskId][$variation['variation_index']])) {
            $localPath = $taskFiles[$databaseTaskId][$variation['variation_index']];
            
            // Update the database
            $stmt = $pdo->prepare("UPDATE audio_variations SET audio_url = ? WHERE id = ?");
            $result = $stmt->execute([$localPath, $variation['id']]);
            
            if ($result) {
                $updatedCount++;
                $output[] = "  ✅ Updated to: {$localPath}";
            } else {
                $output[] = "  ❌ Failed to update";
            }
        } else {
            // No local file found for this task ID
            $noFileCount++;
            $output[] = "  ⚠️ No local file found for task ID: {$databaseTaskId}";
            
            // Look for files that might be related (maybe different task ID)
            $foundAlternative = false;
            foreach ($taskFiles as $fileTaskId => $variations) {
                if (isset($variations[$variation['variation_index']])) {
                    $output[] = "    Found alternative: {$fileTaskId} has variation {$variation['variation_index']}";
                    $foundAlternative = true;
                    break;
                }
            }
            
            if (!$foundAlternative) {
                $output[] = "    No alternative files found for variation index {$variation['variation_index']}";
            }
        }
    }
    
    $output[] = "";
    $output[] = "=== UPDATE SUMMARY ===";
    $output[] = "Updated variations: {$updatedCount}";
    $output[] = "Skipped variations: {$skippedCount}";
    $output[] = "No file found: {$noFileCount}";
    
    // Verify the fix
    $stmt = $pdo->query("SELECT COUNT(*) as total FROM audio_variations WHERE audio_url LIKE 'http%'");
    $remainingExternalUrls = $stmt->fetch();
    
    $stmt = $pdo->query("SELECT COUNT(*) as total FROM audio_variations WHERE audio_url NOT LIKE 'http%'");
    $newLocalUrls = $stmt->fetch();
    
    $output[] = "";
    $output[] = "=== VERIFICATION ===";
    $output[] = "Variations with external URLs: {$remainingExternalUrls['total']}";
    $output[] = "Variations with local URLs: {$newLocalUrls['total']}";
    
    if ($remainingExternalUrls['total'] == 0) {
        $output[] = "🎉 All variations now point to local files!";
    } else {
        $output[] = "⚠️ Some variations still have external URLs";
    }
    
    // Commit the transaction
    $pdo->commit();
    
    $output[] = "";
    $output[] = "=== FIX COMPLETE ===";
    $output[] = "✅ Variation URLs have been updated to point to local files!";
    
} catch (Exception $e) {
    // Rollback on error
    $pdo->rollBack();
    $output[] = "❌ Error occurred: " . $e->getMessage();
    $output[] = "Changes have been rolled back for safety.";
}

$output[] = "";
$output[] = "=== FIX COMPLETED ===";

// Write to file
file_put_contents('fix_variation_urls_output.txt', implode("\n", $output));
echo "Variation URL fix completed. Check fix_variation_urls_output.txt for results.";
?>

CasperSecurity Mini