X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg_reason.pm;h=d11d05e95b048657a0b70c8407a7afe826ccd30b;hb=09589754a8926ef064ea1d3d474a0fc3a8590101;hp=1ec5024cd45c99a6815d55d79b369feb1d977a78;hpb=b516a7cb6c072871568bb0f217cc2bab6ebddd4a;p=freeside.git diff --git a/FS/FS/cust_pkg_reason.pm b/FS/FS/cust_pkg_reason.pm index 1ec5024cd..d11d05e95 100644 --- a/FS/FS/cust_pkg_reason.pm +++ b/FS/FS/cust_pkg_reason.pm @@ -1,8 +1,12 @@ package FS::cust_pkg_reason; +use base qw( FS::otaker_Mixin FS::Record ); use strict; -use base qw( FS::otaker_Mixin FS::Record ); -use FS::Record qw( qsearch qsearchs ); +use vars qw( $ignore_empty_action ); +use FS::Record qw( qsearch ); #qsearchs ); +use FS::upgrade_journal; + +$ignore_empty_action = 0; =head1 NAME @@ -93,11 +97,14 @@ and replace methods. sub check { my $self = shift; + my @actions = ( 'A', 'C', 'E', 'S' ); + push @actions, '' if $ignore_empty_action; + my $error = $self->ut_numbern('num') || $self->ut_number('pkgnum') || $self->ut_number('reasonnum') - || $self->ut_enum('action', [ 'A', 'C', 'E', 'S' ]) + || $self->ut_enum('action', \@actions) || $self->ut_alphan('otaker') || $self->ut_numbern('date') ; @@ -110,13 +117,6 @@ sub check { Returns the reason (see L) associated with this cust_pkg_reason. -=cut - -sub reason { - my $self = shift; - qsearchs( 'reason', { 'reasonnum' => $self->reasonnum } ); -} - =item reasontext Returns the text of the reason (see L) associated with this @@ -135,13 +135,10 @@ sub reasontext { use FS::h_cust_pkg; use FS::h_cust_pkg_reason; -use FS::Schema qw(dbdef); sub _upgrade_data { # class method my ($class, %opts) = @_; - return '' unless dbdef->table('cust_pkg_reason')->column('action'); - my $action_replace = " AND ( history_action = 'replace_old' OR history_action = 'replace_new' )"; @@ -206,9 +203,28 @@ sub _upgrade_data { # class method } #remove nullability if scalar(@migrated) - $count == 0 && ->column('action'); + + unless ( FS::upgrade_journal->is_done('cust_pkg_reason__missing_reason') ) { + $class->_upgrade_missing_reason(%opts); + FS::upgrade_journal->set_done('cust_pkg_reason__missing_reason'); + } + + #still can't fill in an action? don't abort the upgrade + local($ignore_empty_action) = 1; + + $class->_upgrade_otaker(%opts); + +} + +sub _upgrade_missing_reason { + my ($class, %opts) = @_; + + #false laziness w/above + my $action_replace = + " AND ( history_action = 'replace_old' OR history_action = 'replace_new' )"; #seek expirations/adjourns without reason - foreach my $field qw( expire adjourn cancel susp ) { + foreach my $field (qw( expire adjourn cancel susp )) { my $addl_from = "LEFT JOIN h_cust_pkg ON ". "(cust_pkg_reason.pkgnum = h_cust_pkg.pkgnum AND". @@ -268,7 +284,7 @@ sub _upgrade_data { # class method } #seek cancels/suspends without reason, but with expire/adjourn reason - foreach my $field qw( cancel susp ) { + foreach my $field (qw( cancel susp )) { my %precursor_map = ( 'cancel' => 'expire', 'susp' => 'adjourn' ); my $precursor = $precursor_map{$field}; @@ -306,15 +322,12 @@ sub _upgrade_data { # class method } } - $class->_upgrade_otaker(%opts); } =back =head1 BUGS -Here be termites. Don't use on wooden computers. - =head1 SEE ALSO L, schema.html from the base documentation.