[freeside-commits] branch master updated. b472074e9b8d1d9ca2e2e38e231bf1f209281286
Mark Wells
mark at 420.am
Wed Mar 9 16:09:50 PST 2016
The branch, master has been updated
via b472074e9b8d1d9ca2e2e38e231bf1f209281286 (commit)
from d9f0a98539cd8dd957ea9a4b5d77fbb739d43d2e (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 b472074e9b8d1d9ca2e2e38e231bf1f209281286
Author: Mark Wells <mark at freeside.biz>
Date: Wed Mar 9 15:49:53 2016 -0800
fix contact upgrade for multiple email addresses, #40971, from #25536
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 188d287..592c719 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -945,6 +945,7 @@ sub _upgrade_data { #class method
# always migrate cust_main_invoice records over
local $FS::cust_main::import = 1; # override require_phone and such
my $search = FS::Cursor->new('cust_main_invoice', {});
+ my %custnum_dest;
while (my $cust_main_invoice = $search->fetch) {
my $custnum = $cust_main_invoice->custnum;
my $dest = $cust_main_invoice->dest;
@@ -956,17 +957,22 @@ sub _upgrade_data { #class method
if !$svc_acct;
$dest = $svc_acct->email;
}
+ push @{ $custnum_dest{$custnum} ||= [] }, $dest;
- my $error = $cust_main->replace( invoicing_list => [ $dest ] );
-
+ my $error = $cust_main_invoice->delete;
if ( $error ) {
- die "custnum $custnum, invoice destination $dest, creating contact: $error\n";
+ die "custnum $custnum, cleaning up cust_main_invoice: $error\n";
}
+ }
- $error = $cust_main_invoice->delete;
- die "custnum $custnum, cleaning up cust_main_invoice: $error\n" if $error;
-
- } # while $search->fetch
+ foreach my $custnum (keys %custnum_dest) {
+ my $dests = $custnum_dest{$custnum};
+ my $cust_main = FS::cust_main->by_key($custnum);
+ my $error = $cust_main->replace( invoicing_list => $dests );
+ if ( $error ) {
+ die "custnum $custnum, creating contact: $error\n";
+ }
+ }
unless ( FS::upgrade_journal->is_done('contact_invoice_dest') ) {
diff --git a/bin/contact-upgrade-fix-multiple b/bin/contact-upgrade-fix-multiple
new file mode 100755
index 0000000..f5d68fc
--- /dev/null
+++ b/bin/contact-upgrade-fix-multiple
@@ -0,0 +1,60 @@
+#!/usr/bin/perl
+
+use FS::UID qw(adminsuidsetup);
+use FS::cust_main_invoice;
+use FS::Record qw(qsearch qsearchs dbh);
+use FS::cust_main;
+use Date::Parse 'str2time';
+use strict;
+
+my $usage = "usage: contact-upgrade-fix-multiple <user> <upgrade date>\n";
+
+my $user = shift or die $usage;
+adminsuidsetup($user);
+local $FS::UID::AutoCommit = 0;
+
+my $date = shift;
+my $timestamp = str2time($date) or die $usage;
+# safety
+die "upgrade date is before the 4.0 release, must be incorrect.\n$usage"
+ if $timestamp < 1455609600;
+
+my $search = {
+ 'table' => 'h_cust_main_invoice',
+ 'hashref' => {
+ 'history_date' => { op => '>=', value => $timestamp },
+ 'history_action' => 'delete',
+ 'dest' => { op => '!=', value => 'POST' },
+ }
+};
+
+# find deleted cust_main_invoice records
+my %custnum_dest;
+foreach my $deleted (qsearch $search) {
+ my $custnum = $deleted->custnum;
+ push @{ $custnum_dest{$custnum} ||= [] }, $deleted->dest;
+}
+
+# find those customers
+while (my ($custnum, $dests) = each(%custnum_dest)) {
+ my $cust_main = FS::cust_main->by_key($custnum);
+ # filter out the email(s) that the customer already has
+ my @curr_dest = $cust_main->invoicing_list_email;
+ my @new_dest = @curr_dest;
+ print "cust#$custnum\n";
+ foreach my $email ( @$dests ) {
+ print " $email: ";
+ if ( grep { $_ eq $email } @curr_dest ) {
+ print "skipped.\n";
+ next;
+ }
+ print "appending.\n";
+ push @new_dest, $email;
+ }
+ my $error = $cust_main->replace( invoicing_list => \@new_dest );
+ die $error if $error;
+}
+
+dbh->commit;
+print "Done.\n";
+
-----------------------------------------------------------------------
Summary of changes:
FS/FS/contact.pm | 20 ++++++++-----
bin/contact-upgrade-fix-multiple | 60 ++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 7 deletions(-)
create mode 100755 bin/contact-upgrade-fix-multiple
More information about the freeside-commits
mailing list