Rearranged display for reports; fixed search.cgi
[clearscm.git] / maps / bin / mapsscrub.pl
1 #!/usr/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: mapsscrub,v $
6
7 This script scrubs messages from the MAPS database based on the users settings
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@DeFaria.com>
16
17 $Revision: 1.1 $
18
19 =item Created:
20
21 Fri Nov 29 14:17:21  2002
22
23 =item Modified:
24
25 $Date: 2013/06/12 14:05:47 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31  Usage: mapsscrub.pl [-usa|ge] [-h|elp] [-v|erbose] [-de|bug]
32                      [-n|optimize]
33
34   Where:
35    -usa|ge       Print this usage
36    -h|elp        Detailed help
37    -v|erbose     Verbose mode (Default: Not verbose)
38    -de|bug       Turn on debugging (Default: Off)
39
40    -user|id      User ID to scrub (Default: All users)
41    -n\oopitmize  Whether or not to optimize DB (Default: optimize)
42
43 =cut
44
45 use strict;
46 use warnings;
47
48 use FindBin;
49
50 use lib "$FindBin::Bin/../lib";
51 use lib "$FindBin::Bin/../../lib";
52
53 use Getopt::Long;
54 use Pod::Usage;
55
56 use DateUtils;
57 use Display;
58 use Logger;
59 use MAPS;
60 use Utils;
61
62 my %opts = (
63   usage    => sub { pod2usage },
64   help     => sub { pod2usage (-verbose => 2)},
65   verbose  => sub { set_verbose },
66   debug    => sub { set_debug },
67   optimize => 1,
68 );
69
70 my ($log, %total);
71
72 sub CleanUp($) {
73   my ($userid) = @_;
74
75   my %options = GetUserOptions($userid);
76
77   my $timestamp = SubtractDays(Today2SQLDatetime, $options{History});
78
79   $total{'Emails cleaned'}      = CleanEmail $timestamp, $opts{dryrun};
80   $total{'Log entries removed'} = CleanLog   $timestamp, $opts{dryrun};
81
82   for (qw(white black null)) {
83     my $listname = ucfirst($_) . 'list entries removed';
84
85     $total{$listname} = CleanList(
86       userid => $userid,
87       type   => $_,
88       log    => $log,
89       dryrun => $opts{dryrun},
90     );
91   } # for
92
93   Stats \%total, $log;
94
95   return;
96 } # CleanUp
97
98 # Main
99 GetOptions(
100   \%opts,
101   'usage',
102   'help',
103   'verbose',
104   'debug',
105   'userid=s',
106   'optimize!',
107   'dryrun',
108 ) or pod2usage;
109
110 $log = Logger->new(
111   path        => '/var/local/log',
112   timestamped => 'yes',
113 );
114
115 FindUser(%opts{userid});
116
117 while (my $rec = GetUser) {
118   SetContext($rec->{userid});
119
120   CleanUp($rec->{userid});
121 } # while
122
123 # Now optimize the database
124 if ($opts{optimize}) {
125   OptimizeDB;
126
127   $log->msg('Database optimized');
128 } # if
129
130 exit;