stray closing /TABLE in the no-ticket case
[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 die "remove this line to run -- NEVER ON A LIVE DATABASE";
7
8 #-all exports (all records in part_export, part_export_option export_svc)
9 #-all non-POST invoice destinations (cust_main_invoice)
10 #-all payment gateways and agent payment gw overrides (payment_gateway,
11 # payment_gateway_option, agent_payment_gateway)
12 #-everything in the job queue (queue and queue_arg)
13 #-business-onlinepayment and business-onlinepayment-ach config
14
15 use strict;
16 use vars qw( $opt_h );
17 use Getopt::Std;
18 use FS::UID qw(adminsuidsetup dbh);
19 use FS::Conf;
20 use FS::Schema qw(dbdef);
21
22 getopts('h');
23
24 adminsuidsetup shift;
25
26 #  payment_gateway
27 #  payment_gateway_option
28 #  agent_payment_gateway
29 foreach my $table (qw(
30   export_svc
31   part_export_option
32   part_export
33   queue
34   queue_arg
35 )) {
36
37   my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
38   $sth->execute or die $sth->errstr;
39
40 }
41
42 my $dsth = dbh->prepare("DELETE FROM cust_main_invoice WHERE dest != 'POST'")
43   or die dbh->errstr;
44 $dsth->execute or die $dsth->errstr;
45
46 foreach my $table (qw( cust_main cust_payby
47                        cust_pay_pending cust_pay cust_pay_void cust_pay_batch
48                        cust_refund
49 )) {
50   my $ccsth = dbh->prepare("
51     UPDATE $table SET payinfo = '4111111111111111'
52       WHERE payby = 'CARD' OR payby = 'DCRD'
53   ") or die dbh->errstr;
54   $ccsth->execute or die $ccsth->errstr;
55 }
56
57 my $sth = dbh->prepare("UPDATE part_event SET disabled = 'Y'");
58 $sth->execute or die $sth->errstr;
59
60 my $conf = new FS::Conf;
61 foreach my $item (qw(
62   business-onlinepayment
63   business-onlinepayment-ach
64   dump-localdest
65   dump-scpdest
66   cust_bill-ftp_spool
67   smtpmachine
68 )) {
69   $conf->delete($item);
70 }
71
72 if ($opt_h) {  # not all history can be safely deleted
73   foreach my $table (grep { /^h_\w+$/ } dbdef->tables) {
74     my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
75     $sth->execute or die $sth->errstr;
76   }
77 }
78
79 dbh->commit or die dbh->errstr;