CCH taxes with new customer locations, #21485
[freeside.git] / bin / test_scrub
1 #!/usr/bin/perl -w
2
3 #This drops anything from the database that could cause live things to happen.
4 #You'd want to do this on a test copy of your live database but NEVER on the
5 #live database itself.
6
7 #-all exports (all records in part_export, part_export_option export_svc)
8 #-all non-POST invoice destinations (cust_main_invoice)
9 #-all payment gateways and agent payment gw overrides (payment_gateway,
10 # payment_gateway_option, agent_payment_gateway)
11 #-everything in the job queue (queue and queue_arg)
12 #-business-onlinepayment and business-onlinepayment-ach config
13
14 use strict;
15 use vars qw( $opt_h );
16 use Getopt::Std;
17 use FS::UID qw(adminsuidsetup dbh);
18 use FS::Conf;
19 use FS::Schema qw(dbdef);
20
21 getopts('h');
22
23 adminsuidsetup shift;
24
25 foreach my $table (qw(
26   part_export
27   part_export_option
28   export_svc
29   payment_gateway
30   payment_gateway_option
31   agent_payment_gateway
32   queue
33   queue_arg
34 )) {
35
36   my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
37   $sth->execute or die $sth->errstr;
38
39 }
40
41 my $dsth = dbh->prepare("DELETE FROM cust_main_invoice WHERE dest != 'POST'")
42   or die dbh->errstr;
43 $dsth->execute or die $dsth->errstr;
44
45 my $sth = dbh->prepare("UPDATE part_event SET disabled = 'Y'");
46 $sth->execute or die $sth->errstr;
47
48 my $conf = new FS::Conf;
49 foreach my $item (qw(
50   business-onlinepayment
51   business-onlinepayment-ach
52   dump-localdest
53   dump-scpdest
54   cust_bill-ftp_spool
55   smtpmachine
56 )) {
57   $conf->delete($item);
58 }
59
60 if ($opt_h) {  # not all history can be safely deleted
61   foreach my $table (grep { /^h_\w+$/ } dbdef->tables) {
62     my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
63     $sth->execute or die $sth->errstr;
64   }
65 }
66
67 dbh->commit or die dbh->errstr;