<?php
date_default_timezone_set('Europe/Istanbul');

try {
     $db = new PDO("mysql:host=localhost;dbname=heysen_db;charset=utf8mb4", "heysen_db", "VAXw_jJki{uc");
} catch (PDOException $e) {
     print $e->getMessage();
}

$threshold = strtotime('-1 month');
$thresholdWeek = strtotime('-1 week');


// Mesajlar tablosundan kayıtları silin
$sql = "DELETE FROM mesajlar WHERE gonderen_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold) OR alan_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':threshold', $threshold, PDO::PARAM_INT);
$stmt->execute();
echo "Mesajlar tablosundan " . $stmt->rowCount() . " satır silindi.<br>";

// Aramalar tablosundan kayıtları silin
$sql = "DELETE FROM aramalar WHERE zaman < :thresholdWeek";
$stmt = $db->prepare($sql);
$stmt->bindParam(':thresholdWeek', $thresholdWeek, PDO::PARAM_INT);
$stmt->execute();
echo "Aramalar tablosundan " . $stmt->rowCount() . " satır silindi.<br>";


// Begeniler tablosundan kayıtları silin
$sql = "DELETE FROM begeniler WHERE begenen_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold) OR begenilen_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':threshold', $threshold, PDO::PARAM_INT);
$stmt->execute();
echo "Begeniler tablosundan " . $stmt->rowCount() . " satır silindi.<br>";

// Jeton senaryo sifir log tablosundan kayıtları silin
$sql = "DELETE FROM jeton_senaryo_sifir_log WHERE user_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':threshold', $threshold, PDO::PARAM_INT);
$stmt->execute();
echo "Jeton senaryo sifir log tablosundan " . $stmt->rowCount() . " satır silindi.<br>";

// Sohbetlog tablosundan kayıtları silin
$sql = "DELETE FROM sohbetlog WHERE user_id IN (SELECT user_id FROM kullanicilar WHERE user_songiris < :threshold)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':threshold', $threshold, PDO::PARAM_INT);
$stmt->execute();
echo "Sohbetlog tablosundan " . $stmt->rowCount() . " satır silindi.<br>";

// Ziyaretler tablosundan kayıtları silin
$sql = "DELETE FROM ziyaretler WHERE time < :thresholdWeek";
$stmt = $db->prepare($sql);
$stmt->bindParam(':thresholdWeek', $thresholdWeek, PDO::PARAM_INT);
$stmt->execute();
echo "Ziyaretler tablosundan " . $stmt->rowCount() . " satır silindi.<br>";
?>
