<?php
/**
 * Purges log tables
 * 
 * Best called as a cron job to periodically clean the log tables.
 * If the script is called with no table names as arguments then it will
 * purge all Log_* tables. If you only wish to purge specific log tables
 * then name them as parameters:
 * 
 * php /usr/local/atmail/webmail/utilities/tools/purge-logs.php [log_table1] [log_table2] [...]
 * 
 * You should of course change the above path to the correct path for your system
 * 
 * This script TRUNCATEs the table/s so all data from them will be deleted.
 * There is a failsafe in that this script will only truncate log tables, any
 * other tables given as arguments will be ignored.
 */

require_once(dirname(dirname(__FILE__)) . "/nfc-bootloader.php");

// Log Tables
$tables = array(
	'Log_Spam',
	'Log_Login',
	'Log_Error',
	'Log_RecvMail',
	'Log_Virus',
	'Log_SendMail',
    'Log_Device');
	
if ($_SERVER['argc'] > 1) {
	$args = array_slice($_SERVER['argv'], 1);	
} else {
	$args = $tables;
}

// purge logs
foreach ($args as $table) {
	if (in_array($table, $tables)) {
		$dbAdapter->query("truncate table $table");
	}
}
