Add script to delete old logs

This commit is contained in:
Kijin Sung 2018-11-20 15:31:34 +09:00
parent eeb74c3257
commit a228f0888b
2 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,66 @@
<?php
/**
* This script deletes old logs from the database.
*
* Rhymix produces various logs that can increase the size of the database
* unnecessarily if not cleaned. This script removes old logs.
*/
require_once __DIR__ . '/common.php';
// Delete logs older than this number of days.
$days = 30;
// Initialize the exit status.
$exit_status = 0;
// Delete advanced mailer mail logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('advanced_mailer.deleteMailLogs', $args);
if ($output->toBool())
{
echo "Successfully deleted all mail logs older than $days days.\n";
}
else
{
echo "Error while deleting mail logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
}
// Delete advanced mailer SMS logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('advanced_mailer.deleteSMSLogs', $args);
if ($output->toBool())
{
echo "Successfully deleted all SMS logs older than $days days.\n";
}
else
{
echo "Error while deleting SMS logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 12;
}
// Delete spamfilter logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('spamfilter.deleteLog', $args);
if ($output->toBool())
{
echo "Successfully deleted all spamfilter logs older than $days days.\n";
}
else
{
echo "Error while deleting spamfilter logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 12;
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}

View file

@ -0,0 +1,8 @@
<query id="deleteLog" action="delete">
<tables>
<table name="spamfilter_log" />
</tables>
<conditions>
<condition operation="less" column="regdate" var="regdate" notnull="notnull" />
</conditions>
</query>