[freeside-commits] branch FREESIDE_3_BRANCH updated. 7f970a8c019bf51cb9a564b5a085a9d30f666393
Mark Wells
mark at 420.am
Fri Nov 8 17:24:15 PST 2013
The branch, FREESIDE_3_BRANCH has been updated
via 7f970a8c019bf51cb9a564b5a085a9d30f666393 (commit)
from 3b172c8a7b7ca97bd71671dc358f29c5116948da (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7f970a8c019bf51cb9a564b5a085a9d30f666393
Author: Mark Wells <mark at freeside.biz>
Date: Fri Nov 8 17:23:55 2013 -0800
script to repopulate ship_company field
diff --git a/bin/restore-ship_company b/bin/restore-ship_company
new file mode 100755
index 0000000..cee7009
--- /dev/null
+++ b/bin/restore-ship_company
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+use FS::UID 'adminsuidsetup';
+use FS::Record qw(qsearch qsearchs dbh);
+use FS::cust_main;
+my $user = shift or die "Usage:
+ restore-ship_company username [ max-age ]
+";
+adminsuidsetup($user);
+
+$FS::UID::AutoCommit = 1;
+local $FS::cust_main::import = 1;
+
+my $days = shift || 30;
+my $time = time - (86400*$days); # by default, only restore within the last
+ # 30 days
+foreach my $cust_main (qsearch('cust_main', { ship_company => '' })) {
+ my $custnum = $cust_main->custnum;
+ my $last_h = qsearchs({
+ table => 'h_cust_main',
+ extra_sql => " WHERE custnum = $custnum".
+ " AND ship_company IS NOT NULL".
+ " AND history_date >= $time",
+ order_by => " ORDER BY history_date DESC LIMIT 1",
+ });
+ next if !$last_h;
+ print "$custnum\t".$last_h->ship_company."\n";
+ $cust_main->set('ship_company' => $last_h->ship_company);
+ my $error = $cust_main->replace;
+ warn "Error setting service company for customer #$custnum:\n $error\n"
+ if $error;
+}
-----------------------------------------------------------------------
Summary of changes:
bin/restore-ship_company | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
create mode 100755 bin/restore-ship_company
More information about the freeside-commits
mailing list