summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIrina Todeva <itodeva@hostgator.com>2015-10-08 12:03:08 -0600
committerMark Wells <mark@freeside.biz>2015-11-03 12:28:13 -0800
commit1ef811033e1ea791388c7c8d15a3a5a720b1f37f (patch)
tree6f8db69ace441ed9c6a5ac81b6c6cc54a175875b /FS
parent9170a3f9609625af49cd9e20003948713389c634 (diff)
Tables added to the list with data upgrade because of reason and void_reason
legacy fields: - cust_credit_void - cust_bill_void - cust_bill_pkg_void Made some changes to reason_Mixin to be able to upgrade reason an void_reason fields
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Upgrade.pm5
-rw-r--r--FS/FS/cust_bill_pkg_void.pm16
-rw-r--r--FS/FS/cust_bill_void.pm15
-rw-r--r--FS/FS/cust_credit_void.pm15
-rw-r--r--FS/FS/reason_Mixin.pm96
5 files changed, 105 insertions, 42 deletions
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 263230b34..bffda566f 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -350,6 +350,11 @@ sub upgrade_data {
#customer credits
'cust_credit' => [],
+ # reason / void_reason migration to reasonnum / void_reasonnum
+ 'cust_credit_void' => [],
+ 'cust_bill_void' => [],
+ 'cust_bill_pkg_void' => [],
+
#duplicate history records
'h_cust_svc' => [],
diff --git a/FS/FS/cust_bill_pkg_void.pm b/FS/FS/cust_bill_pkg_void.pm
index 4b9cffd4e..991dd37dd 100644
--- a/FS/FS/cust_bill_pkg_void.pm
+++ b/FS/FS/cust_bill_pkg_void.pm
@@ -2,6 +2,7 @@ package FS::cust_bill_pkg_void;
use base qw( FS::TemplateItem_Mixin FS::reason_Mixin FS::Record );
use strict;
+use vars qw( $me $DEBUG );
use FS::Record qw( qsearch qsearchs dbh fields );
use FS::cust_bill_void;
use FS::cust_bill_pkg_detail;
@@ -13,6 +14,9 @@ use FS::cust_bill_pkg_tax_location;
use FS::cust_bill_pkg_tax_rate_location;
use FS::cust_tax_exempt_pkg;
+$me = '[ FS::cust_bill_pkg_void ]';
+$DEBUG = 0;
+
=head1 NAME
FS::cust_bill_pkg_void - Object methods for cust_bill_pkg_void records
@@ -279,6 +283,18 @@ sub cust_bill_pkg_fee {
qsearch( 'cust_bill_pkg_fee_void', { 'billpkgnum' => $self->billpkgnum } );
}
+
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data { # class method
+ my ($class, %opts) = @_;
+
+ warn "$me upgrading $class\n" if $DEBUG;
+
+ $class->_upgrade_reasonnum(%opts);
+}
+
=back
=head1 BUGS
diff --git a/FS/FS/cust_bill_void.pm b/FS/FS/cust_bill_void.pm
index 04c69d4bb..50f69c9fa 100644
--- a/FS/FS/cust_bill_void.pm
+++ b/FS/FS/cust_bill_void.pm
@@ -3,12 +3,16 @@ use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin
FS::reason_Mixin FS::Record );
use strict;
+use vars qw( $me $DEBUG );
use FS::Record qw( qsearch qsearchs dbh fields );
use FS::cust_statement;
use FS::access_user;
use FS::cust_bill_pkg_void;
use FS::cust_bill;
+$me = '[ FS::cust_bill_void ]';
+$DEBUG = 0;
+
=head1 NAME
FS::cust_bill_void - Object methods for cust_bill_void records
@@ -349,6 +353,17 @@ sub search_sql_where {
sub enable_previous { 0 }
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data { # class method
+ my ($class, %opts) = @_;
+
+ warn "$me upgrading $class\n" if $DEBUG;
+
+ $class->_upgrade_reasonnum(%opts);
+}
+
=back
=head1 BUGS
diff --git a/FS/FS/cust_credit_void.pm b/FS/FS/cust_credit_void.pm
index 9c92068eb..60beaa655 100644
--- a/FS/FS/cust_credit_void.pm
+++ b/FS/FS/cust_credit_void.pm
@@ -2,12 +2,16 @@ package FS::cust_credit_void;
use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin FS::Record );
use strict;
+use vars qw( $me $DEBUG );
use FS::Record qw(qsearchs); # qsearch qsearchs);
use FS::CurrentUser;
use FS::access_user;
use FS::cust_credit;
use FS::UID qw( dbh );
+$me = '[ FS::cust_credit_void ]';
+$DEBUG = 0;
+
=head1 NAME
FS::cust_credit_void - Object methods for cust_credit_void objects
@@ -190,6 +194,17 @@ sub void_reason {
return $reason_text;
}
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data { # class method
+ my ( $class, %opts ) = @_;
+
+ warn "$me upgrading $class\n" if $DEBUG;
+
+ $class->_upgrade_reasonnum(%opts);
+}
+
=back
=head1 BUGS
diff --git a/FS/FS/reason_Mixin.pm b/FS/FS/reason_Mixin.pm
index a4c2d3feb..af9aa50e6 100644
--- a/FS/FS/reason_Mixin.pm
+++ b/FS/FS/reason_Mixin.pm
@@ -39,52 +39,64 @@ sub reason {
# FS::reason->new_or_existing
# Used by FS::Upgrade to migrate reason text fields to reasonnum.
-sub _upgrade_reasonnum { # class method
- my $class = shift;
- my $table = $class->table;
-
- if ( defined dbdef->table($table)->column('reason')
- && defined dbdef->table($table)->column('reasonnum') )
- {
-
- warn "$me Checking for unmigrated reasons\n" if $DEBUG;
+sub _upgrade_reasonnum { # class method
+ my $class = shift;
+ my $table = $class->table;
- my @legacy_reason_records = qsearch(
+ for my $fieldname (qw(reason void_reason)) {
+ if ( defined dbdef->table($table)->column($fieldname)
+ && defined dbdef->table($table)->column( $fieldname . 'num' ) )
{
- 'table' => $table,
- 'hashref' => {},
- 'extra_sql' => 'WHERE reason IS NOT NULL',
+
+ warn "$me Checking for unmigrated reasons\n" if $DEBUG;
+
+ my @legacy_reason_records = qsearch(
+ {
+ 'table' => $table,
+ 'hashref' => {},
+ 'extra_sql' => 'WHERE ' . $fieldname . ' IS NOT NULL',
+ }
+ );
+
+ if (
+ scalar(
+ grep { $_->getfield($fieldname) =~ /\S/ }
+ @legacy_reason_records
+ )
+ )
+ {
+ warn "$me Found unmigrated reasons\n" if $DEBUG;
+
+ my $reason_type =
+ _upgrade_get_legacy_reason_type( $class, $table );
+ my $noreason = _upgrade_get_no_reason( $class, $reason_type );
+
+ foreach my $record_to_upgrade (@legacy_reason_records) {
+ my $reason = $record_to_upgrade->getfield($fieldname);
+ warn "Contemplating reason $reason\n" if $DEBUG > 1;
+ if ( $reason =~ /\S/ ) {
+ my $reason =
+ _upgrade_get_reason( $class, $reason, $reason_type );
+ $record_to_upgrade->set( $fieldname . 'num',
+ $reason->reasonnum );
+ }
+ else {
+ $record_to_upgrade->set( $fieldname . 'num',
+ $noreason->reasonnum );
+ }
+
+ $record_to_upgrade->setfield( $fieldname, '' );
+ my $error = $record_to_upgrade->replace;
+
+ my $primary_key = $record_to_upgrade->primary_key;
+ warn "*** WARNING: error replacing $fieldname in $class "
+ . $record_to_upgrade->get($primary_key)
+ . ": $error ***\n"
+ if $error;
+ }
+ }
}
- );
-
- if (scalar(grep { $_->getfield('reason') =~ /\S/ } @legacy_reason_records)) {
- warn "$me Found unmigrated reasons\n" if $DEBUG;
-
- my $reason_type = _upgrade_get_legacy_reason_type($class, $table);
- my $noreason = _upgrade_get_no_reason($class, $reason_type);
-
- foreach my $record_to_upgrade (@legacy_reason_records) {
- my $reason = $record_to_upgrade->getfield('reason');
- warn "Contemplating reason $reason\n" if $DEBUG > 1;
- if ( $reason =~ /\S/ ) {
- my $reason = _upgrade_get_reason( $class, $reason, $reason_type );
- $record_to_upgrade->reasonnum( $reason->reasonnum );
- }
- else {
- $record_to_upgrade->reasonnum( $noreason->reasonnum );
- }
-
- $record_to_upgrade->setfield( 'reason', '' );
- my $error = $record_to_upgrade->replace;
-
- my $primary_key = $record_to_upgrade->primary_key;
- warn "*** WARNING: error replacing reason in $class "
- . $record_to_upgrade->get($primary_key)
- . ": $error ***\n"
- if $error;
- }
}
- }
}
# _upgrade_get_legacy_reason_type is class method supposed to be used only