summaryrefslogtreecommitdiff
path: root/bin/test_scrub
blob: 850801f3b6592c07f8bdc42e11810008dab16d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w

#This drops anything from the database that could cause live things to happen.
#You'd want to do this on a test copy of your live database but NEVER on the
#live database itself.
die "remove this line to run -- NEVER ON A LIVE DATABASE";

#-all exports (all records in part_export, part_export_option export_svc)
#-all non-POST invoice destinations (cust_main_invoice)
#-all payment gateways and agent payment gw overrides (payment_gateway,
# payment_gateway_option, agent_payment_gateway)
#-everything in the job queue (queue and queue_arg)
#-business-onlinepayment and business-onlinepayment-ach config

use strict;
use vars qw( $opt_h );
use Getopt::Std;
use FS::UID qw(adminsuidsetup dbh);
use FS::Conf;
use FS::Schema qw(dbdef);

getopts('h');

adminsuidsetup shift;

#  payment_gateway
#  payment_gateway_option
#  agent_payment_gateway
foreach my $table (qw(
  export_svc
  part_export_option
  part_export
  queue
  queue_arg
)) {

  my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
  $sth->execute or die $sth->errstr;

}

my $dsth = dbh->prepare("DELETE FROM cust_main_invoice WHERE dest != 'POST'")
  or die dbh->errstr;
$dsth->execute or die $dsth->errstr;

foreach my $table (qw( cust_main cust_payby
                       cust_pay_pending cust_pay cust_pay_void cust_pay_batch
                       cust_refund
)) {
  my $ccsth = dbh->prepare("
    UPDATE $table SET payinfo = '4111111111111111'
      WHERE payby = 'CARD' OR payby = 'DCRD'
  ") or die dbh->errstr;
  $ccsth->execute or die $ccsth->errstr;
}

my $sth = dbh->prepare("UPDATE part_event SET disabled = 'Y'");
$sth->execute or die $sth->errstr;

my $conf = new FS::Conf;
foreach my $item (qw(
  business-onlinepayment
  business-onlinepayment-ach
  dump-localdest
  dump-scpdest
  cust_bill-ftp_spool
  smtpmachine
)) {
  $conf->delete($item);
}

if ($opt_h) {  # not all history can be safely deleted
  foreach my $table (grep { /^h_\w+$/ } dbdef->tables) {
    my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
    $sth->execute or die $sth->errstr;
  }
}

dbh->commit or die dbh->errstr;