Commit 342a2ab5 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Clear user-data we add when cron runs at monthend

Change-Id: I37b3472609c56a6e15d2998f4c9f2e2490979522
parent b19e3f05
......@@ -46,6 +46,7 @@ GetOptions(
"config:s",
"cleanup-date:s",
"cleanup",
"reset-userdata",
"debug",
);
......@@ -92,6 +93,9 @@ my $server;
# We must cleanup
if ($opts{'cleanup'}) {
# Check if we need to reset user data
my $reset_userdata = defined($opts{'reset-userdata'}) ? 1 : 0;
loadModules();
# Pull where we are now and default to that, if we truncate the day we mess up the timezone calculations
......@@ -116,7 +120,7 @@ if ($opts{'cleanup'}) {
# If we have a cleanup module, run it
if (defined($module->{'Cleanup'})) {
$server->log(LOG_INFO," -> running cleanup...");
$module->{'Cleanup'}($server,$cleanupMonth->epoch());
$module->{'Cleanup'}($server,$cleanupMonth->epoch(),$reset_userdata);
}
}
......
......@@ -511,7 +511,7 @@ sub data_get
# Clean up of old user variables
sub cleanup
{
my ($server,$runForDate) = @_;
my ($server,$runForDate,$resetUserData) = @_;
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Removing old user data");
# Begin operation
......@@ -534,9 +534,32 @@ sub cleanup
return;
}
if ($resetUserData) {
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Resetting user data counters");
# Perform query
my $sth = DBDo('
UPDATE
@TP@users_data
SET
Value = 0
WHERE
Name = '.DBQuote('CurrentMonthTotalTraffic').'
OR Name = '.DBQuote('CurrentMonthTotalUptime').'
');
# Error and rollback
if (!$sth) {
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Database has been rolled back, no data reset");
DBRollback();
return;
}
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => User data counters have been reset");
}
# Commit
DBCommit();
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Old user data have been deleted");
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Old user data cleaned up");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment