2a0f54ea93379d61a2b57c1e4be77e778f2afc2b
[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     $total{"${_}list entries removed"} = CleanList(
84       userid => $userid,
85       type   => $_,
86       log    => $log,
87       dryrun => $opts{dryrun},
88     );
89   } # for
90
91   Stats \%total, $log;
92
93   return;
94 } # CleanUp
95
96 # Main
97 GetOptions(
98   \%opts,
99   'usage',
100   'help',
101   'verbose',
102   'debug',
103   'userid=s',
104   'optimize!',
105   'dryrun',
106 ) or pod2usage;
107
108 $log = Logger->new(
109   path        => '/var/local/log',
110   timestamped => 'yes',
111 );
112
113 FindUser(%opts{userid});
114
115 while (my $rec = GetUser) {
116   SetContext($rec->{userid});
117
118   CleanUp($rec->{userid});
119 } # while
120
121 # Now optimize the database
122 OptimizeDB if $opts{optimize};
123
124 exit;