add option to limit automatic unsuspensions to a specific suspension reason type...
[freeside.git] / bin / recover-cust_location
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use FS::UID qw( adminsuidsetup );
6 use FS::Record qw( qsearchs );
7 use FS::h_cust_location;
8 use FS::cust_location;
9
10 adminsuidsetup shift or &usage;
11 my $start = shift or &usage;
12 my $end = shift or &usage;
13
14 for my $locationnum ( $start .. $end ) {
15
16   my $h_cust_location = qsearchs({
17     'table'     => 'h_cust_location',  
18     'hashref'   => { 'locationnum' => $locationnum, },
19     'extra_sql' => " AND ( history_action = 'insert' OR history_action = 'replace_new' )",
20     'order_by'  => 'ORDER BY historynum DESC LIMIT 1',
21   })
22     or die "h_cust_location for $locationnum not found\n";
23
24   warn "recovering cust_locaiton $locationnum\n";
25   my $cust_location = new FS::cust_location { $h_cust_location->hash };
26   my $error = $cust_location->insert;
27   die $error if $error;
28
29 }
30
31 sub usage {
32   die "Usage: recover-cust_location username start_locationnum end_locationnum\n";
33 }