X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Freason_Mixin.pm;h=a3975419c77bfa57d062f4fe3670b76a7d00fbed;hb=292ef074d01bb925e9a466ed771bf2ac418bb44f;hp=fdf7962190d3922be14ad1ac77379f8835906472;hpb=aa302b14cbe21ca99b70d9d13d75dbd3fb72d038;p=freeside.git diff --git a/FS/FS/reason_Mixin.pm b/FS/FS/reason_Mixin.pm index fdf796219..a3975419c 100644 --- a/FS/FS/reason_Mixin.pm +++ b/FS/FS/reason_Mixin.pm @@ -5,6 +5,7 @@ use Carp qw( croak ); #confess ); use FS::Record qw( qsearch qsearchs dbdef ); use FS::access_user; use FS::UID qw( dbh ); +use FS::reason; our $DEBUG = 0; our $me = '[FS::reason_Mixin]'; @@ -17,49 +18,23 @@ Returns the text of the associated reason (see L) for this credit. sub reason { my ($self, $value, %options) = @_; - my $dbh = dbh; - my $reason; - my $typenum = $options{'reason_type'}; - - my $oldAutoCommit = $FS::UID::AutoCommit; # this should already be in - local $FS::UID::AutoCommit = 0; # a transaction if it matters - - if ( defined( $value ) ) { - my $hashref = { 'reason' => $value }; - $hashref->{'reason_type'} = $typenum if $typenum; - my $addl_from = "LEFT JOIN reason_type ON ( reason_type = typenum ) "; - my $extra_sql = " AND reason_type.class='F'"; - - $reason = qsearchs( { 'table' => 'reason', - 'hashref' => $hashref, - 'addl_from' => $addl_from, - 'extra_sql' => $extra_sql, - } ); - - if (!$reason && $typenum) { - $reason = new FS::reason( { 'reason_type' => $typenum, - 'reason' => $value, - 'disabled' => 'Y', - } ); - my $error = $reason->insert; - if ( $error ) { - warn "error inserting reason: $error\n"; - $reason = undef; - } - } - - $self->reasonnum($reason ? $reason->reasonnum : '') ; - warn "$me reason used in set mode with non-existant reason -- clearing" - unless $reason; + my $reason_text; + if ( $self->reasonnum ) { + my $reason = FS::reason->by_key($self->reasonnum); + $reason_text = $reason->reason; + } else { # in case one of these somehow still exists + $reason_text = $self->get('reason'); + } + if ( $self->get('addlinfo') ) { + $reason_text .= ' ' . $self->get('addlinfo'); } - $reason = qsearchs( 'reason', { 'reasonnum' => $self->reasonnum } ); - - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - ( $reason ? $reason->reason : '' ). - ( $self->addlinfo ? ' '.$self->addlinfo : '' ); + return $reason_text; } +# it was a mistake to allow setting the reason this way; use +# FS::reason->new_or_existing + # Used by FS::Upgrade to migrate reason text fields to reasonnum. sub _upgrade_reasonnum { # class method my $class = shift;