fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / bin / freeside-prune-applications
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_d $opt_q $opt_v);  # $opt_n instead of $opt_d?
5 use vars qw($DEBUG $DRY_RUN);
6 use Getopt::Std;
7 use FS::UID qw(adminsuidsetup checkeuid);
8 use FS::Misc::prune qw(prune_applications);
9
10 die "Not running uid freeside!" unless checkeuid();
11
12 getopts("dq");
13
14 $DEBUG = !$opt_q;
15 #$DEBUG = $opt_v;
16
17 $DRY_RUN = $opt_d;
18
19 my $user = shift or die &usage;
20 my $dbh = adminsuidsetup($user);
21
22 my $hashref = {};
23
24 $hashref->{dry_run} = 1 if $DRY_RUN;
25 $hashref->{debug} = 1 if $DEBUG;
26
27 print join "\n", prune_applications($hashref);
28 print "\n" if $DRY_RUN;
29
30 $dbh->commit or die $dbh->errstr;
31
32 ###
33
34 sub usage {
35   die "Usage:\n  freeside-prune-applications [ -d ] [ -q | -v ] user\n"; 
36 }
37
38 =head1 NAME
39
40 freeside-prune-applications - Removes stray applications of credit, payment to
41                               bills, refunds, etc.
42
43 =head1 SYNOPSIS
44
45   freeside-prune-applications [ -d ] [ -q | -v ]
46
47 =head1 DESCRIPTION
48
49 Reads your existing database schema and updates it to match the current schema,
50 adding any columns or tables necessary.
51
52   [ -d ]: Dry run; display affected records (to STDOUT) only, but do not
53           remove them.
54
55   [ -q ]: Run quietly.  This may become the default at some point.
56
57   [ -v ]: Run verbosely, sending debugging information to STDERR.  This is the
58           current default.
59
60 =head1 SEE ALSO
61
62 =cut
63