hide tickets with selfservice priority indicating closure, RT#79444
[freeside.git] / bin / del-old-history
1 #!/usr/bin/perl -w
2
3 use strict;
4 use FS::UID qw(adminsuidsetup dbh);
5 use FS::Record; #why is this necessary
6
7 #WARNING: not all tables are safe to remove history!
8 # these are, and seem to take the most space in a typical install with queued
9 # exports
10 my @tables = qw( h_queue h_queue_arg );
11
12 my $years = 2;
13 my $seconds = $years * 31556926; #60*60*24*365.2422 is close enough
14 my $before = int( time - $seconds );
15
16 adminsuidsetup shift or die "usage: del-old-history user\n";
17
18 foreach my $table ( @tables ) {
19
20   unless ( $table =~ /^h_/ ) {
21     warn "$table is not a history table, skipping\n";
22     next;
23   }
24
25   my $sql = "DELETE FROM $table WHERE history_date < $before";
26   warn "$sql\n";
27   my $sth = dbh->prepare($sql) or die dbh->errstr;
28   $sth->execute or die $sth->errstr;
29
30 }