4 use vars qw( $opt_s $opt_e $opt_r $opt_u $opt_c );
6 use Date::Parse qw(str2time);
8 use FS::UID qw(adminsuidsetup dbh);
9 use FS::Record qw(qsearch qsearchs);
15 my $user = shift or &usage;
18 my $sdate = $opt_s ? str2time($opt_s) : 0;
19 my $edate = $opt_e ? str2time($opt_e) + 86399 #not strictly correct on time zone boundary days, but good enough for this purpose
22 my $oldAutoCommit = $FS::UID::AutoCommit;
23 local $FS::UID::AutoCommit = 0;
30 foreach my $cust_pkg (
31 qsearch({ table => 'cust_pkg',
38 #XXX only canceled packages?
39 #XXX only suspended packages?
42 qsearchs({ table => 'h_cust_pkg',
44 pkgnum => $cust_pkg->pkgnum,
45 history_action => 'replace_old',
46 setup => { op=>'!=', value=>'' },
47 ($opt_u ? ('susp' => { op=>'!=', value=>'' })
50 ($opt_c ? ('cancel' => { op=>'!=', value=>'' })
54 extra_sql => ' AND history_date >= ? AND history_date <= ? ',
55 extra_param => [ [$sdate,'int'], [$edate,'int'] ],
56 order_by => 'ORDER BY history_date DESC LIMIT 1',
63 print "restoring setup for pkgnum ". $cust_pkg->pkgnum.
64 " (custnum ". $cust_pkg->custnum.
65 ") to ". time2str('%D', $h_cust_pkg->setup). "\n";
68 $cust_pkg->set('setup', $h_cust_pkg->setup);
69 my $error = $cust_pkg->replace;
75 $dbh->rollback or die $dbh->errstr; #if $oldAutoCommit;
77 $dbh->commit or die $dbh->errstr; #if $oldAutoCommit;
80 print "changed $changed packages\n";
83 die "usage: cust_pkg-restore_setup [ -s history_start ] [ -e history_end ] [-r ] employee_username\n";
88 cust_pkg-restore_setup
92 cust_pkg-restore_setup -d date -u history_username [ -r ] employee_username
96 Command-line tool to restore removed setup dates.
98 -s: Start date of time period to restore changes from
100 -e: End date of time period to restore changes from
102 -u: sUspended packages only
104 -c: Cancelled packages only