]> git.proxmox.com Git - pmg-api.git/commitdiff
move cleanup_stats() to PMG::DBTools::purge_statistic_database()
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 26 Apr 2017 04:36:19 +0000 (06:36 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 26 Apr 2017 04:36:19 +0000 (06:36 +0200)
PMG/DBTools.pm
PMG/Statistic.pm
bin/pmg-daily

index 612a0a7dccd0f9775a9ae816fc3d59d02d30443a..08f1a52d6792c9a6d09082fa9c317cd02e0487e4 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 use POSIX ":sys_wait_h";
 use POSIX ':signal_h';
 use DBI;
+use Time::Local;
 
 use PVE::SafeSyslog;
 use PVE::Tools;
@@ -821,6 +822,44 @@ sub init_masterdb {
     die $err if $err;
 }
 
+sub purge_statistic_database {
+    my ($dbh, $statlifetime) = @_;
+
+    return if $statlifetime <= 0;
+
+    my (undef, undef, undef, $mday, $mon, $year) = localtime(time());
+    my $end = timelocal(0, 0, 0, $mday, $mon, $year);
+    my $start = $end - $statlifetime*86400;
+
+    # delete statistics older than $start
+
+    my $rows = 0;
+
+    eval {
+       $dbh->begin_work;
+
+       my $sth = $dbh->prepare("DELETE FROM CStatistic WHERE time < $start");
+       $sth->execute;
+       $rows = $sth->rows;
+       $sth->finish;
+
+       if ($rows > 0) {
+           $sth = $dbh->prepare(
+               "DELETE FROM CReceivers WHERE NOT EXISTS " .
+               "(SELECT * FROM CStatistic WHERE CID = CStatistic_CID AND RID = CStatistic_RID)");
+
+           $sth->execute;
+       }
+       $dbh->commit;
+    };
+    if (my $err = $@) {
+       $dbh->rollback;
+       die $err;
+    }
+
+    return $rows;
+}
+
 sub copy_table {
     my ($ldb, $rdb, $table) = @_;
 
index 5c1b87a7fff4838732f5f7c6b978ce9ed64bf4c2..49ed1287d8ebaf43ac5b265264e17f04516d089b 100755 (executable)
@@ -374,44 +374,6 @@ sub update_stats  {
     while (update_stats_virusinfo ($dbh, $cinfo) > 0) {};
 }
 
-sub cleanup_stats {
-    my ($dbh, $statlifetime) = @_;
-
-    return if $statlifetime <= 0;
-
-    my (undef, undef, undef, $mday, $mon, $year) = localtime (time());
-    my $end = timelocal(0, 0, 0, $mday, $mon, $year);
-    my $start = $end - $statlifetime*86400;
-
-    # delete statistics older than $start
-
-    my $rows = 0;
-
-    eval {
-       $dbh->begin_work;
-
-       my $sth = $dbh->prepare("DELETE FROM CStatistic WHERE time < $start");
-       $sth->execute;
-       $rows = $sth->rows;
-       $sth->finish;
-
-       if ($rows > 0) {
-           $sth = $dbh->prepare(
-               "DELETE FROM CReceivers WHERE NOT EXISTS " .
-               "(SELECT * FROM CStatistic WHERE CID = CStatistic_CID AND RID = CStatistic_RID)");
-
-           $sth->execute;
-       }
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $err;
-    }
-
-    return $rows;
-}
-
 sub total_mail_stat {
     my ($self, $rdb) = @_;
 
index e5cec9a17da50e7f813f59175d513c3eab85dc94..985e7d00ca71ee537c916e0e19697603f32d6cde 100755 (executable)
@@ -36,7 +36,7 @@ if (my $statlifetime = $cfg->get ('admin', 'statlifetime')) {
     my $count = 0;
     eval {
        my $dbh = PMG::DBTools::open_ruledb();
-       $count = PMG::Statistic::cleanup_stats($dbh, $statlifetime);
+       $count = PMG::DBTools::purge_statistic_database($dbh, $statlifetime);
     };
     if (my $err = $@) {
        syslog('err', $err);