<?php
/**
 * Löscht alle Livestream-Caches
 */

define('WP_USE_THEMES', false);
require('../../../wp-load.php');

echo "=== Cache löschen ===\n\n";

// Zähler
$deleted = 0;
global $wpdb;

// 1. Alle alten Channel-ID Caches löschen (mm_channel_id_* - alt)
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_channel_id_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted Channel-ID Caches (alt)\n";

// 2. Alle Live-Status Caches löschen (mm_live_status_*)
$deleted = 0;
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_live_status_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted Live-Status Caches\n";

// 3. Alte Live-ID Caches löschen (mm_live_id_* - alt)
$deleted = 0;
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_live_id_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted Live-ID Caches (alt)\n";

// 4. Alte Channel-ID Caches löschen (mm_id_for_* - neu)
$deleted = 0;
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_id_for_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted Channel-ID Caches (neu)\n";

// 3. Alte Video-Resolution Caches löschen (mm_yt_live_v2_*)
$deleted = 0;
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_yt_live_v2_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted YouTube Video Caches\n";

// 4. Alte Live-Status Caches löschen (mm_yt_status_*)
$deleted = 0;
$results = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_mm_yt_status_%'"
);

foreach ($results as $row) {
    $key = str_replace('_transient_', '', $row->option_name);
    delete_transient($key);
    $deleted++;
}
echo "✓ Gelöscht: $deleted YouTube Status Caches\n";

echo "\n✓ Alle Caches wurden gelöscht!\n";
echo "Die Seite kann jetzt neu geladen werden.\n";
