<?php
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');

$datum = date("Y-m-d", strtotime("-3 month"));

$dbh = new PDO("mysql:host=localhost;dbname=tasks", "root", "gc01mysql");
$dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

echo "Daten ab {$datum} werden archiviert.\r\n";

$insertQuery = "INSERT INTO status_meldung_historie SELECT * FROM status_meldung WHERE datum <= '{$datum}' ";
$c = $dbh->query($insertQuery);

if (!$c) {
	echo $dbh->errorInfo();
	die();
}

$deleteQuery = "DELETE FROM status_meldung WHERE datum <= '{$datum}' ";
$c = $dbh->query($deleteQuery);

if (!$c) {
	echo $dbh->errorInfo();
	die();
}



$insertQuery = "INSERT INTO status_kommentar_historie SELECT * FROM status_kommentar WHERE datum <= '{$datum}' ";
$c = $dbh->query($insertQuery);

if (!$c) {
	echo $dbh->errorInfo();
	die();
}

$deleteQuery = "DELETE FROM status_kommentar WHERE datum <= '{$datum}' ";
$c = $dbh->query($deleteQuery);

if (!$c) {
	echo $dbh->errorInfo();
	die();
}


echo "Erfolgreich abgeschlossen.\r\n";