summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2017-08-31 17:14:36 -0700
committerIvan Kohler <ivan@freeside.biz>2017-08-31 17:14:36 -0700
commit35ac50b0ff66fc78aaa11baf8ae0199280645b96 (patch)
treee4aab453382e063893a68812e55ef30a275be61f /bin
parentd32566e41c62a65a07a0c1978468583c78d96516 (diff)
recover customer locations from history, RT#77268
Diffstat (limited to 'bin')
-rwxr-xr-xbin/recover-cust_location33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/recover-cust_location b/bin/recover-cust_location
new file mode 100755
index 000000000..6318eb343
--- /dev/null
+++ b/bin/recover-cust_location
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FS::UID qw( adminsuidsetup );
+use FS::Record qw( qsearchs );
+use FS::h_cust_location;
+use FS::cust_location;
+
+adminsuidsetup shift or &usage;
+my $start = shift or &usage;
+my $end = shift or &usage;
+
+for my $locationnum ( $start .. $end ) {
+
+ my $h_cust_location = qsearchs({
+ 'table' => 'h_cust_location',
+ 'hashref' => { 'locationnum' => $locationnum, },
+ 'extra_sql' => " AND ( history_action = 'insert' OR history_action = 'replace_new' )",
+ 'order_by' => 'ORDER BY historynum DESC LIMIT 1',
+ })
+ or die "h_cust_location for $locationnum not found\n";
+
+ warn "recovering cust_locaiton $locationnum\n";
+ my $cust_location = new FS::cust_location { $h_cust_location->hash };
+ my $error = $cust_location->insert;
+ die $error if $error;
+
+}
+
+sub usage {
+ die "Usage: recover-cust_location username start_locationnum end_locationnum\n";
+}