diff options
author | ivan <ivan> | 2011-03-12 21:13:34 +0000 |
---|---|---|
committer | ivan <ivan> | 2011-03-12 21:13:34 +0000 |
commit | 4e76632c66f001a4f4d97aadc308038172eaeaa7 (patch) | |
tree | 49b8e66fa5b4ccce7c640c2f6f0d7cda7145e51c /FS | |
parent | 3430aaab43922bdc24f84070185db9ee3a472ccd (diff) |
refactor transaction from process/qual.cgi to qual.pm insert, RT#7111
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/qual.pm | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/FS/FS/qual.pm b/FS/FS/qual.pm index 8f5838973..e7483825f 100644 --- a/FS/FS/qual.pm +++ b/FS/FS/qual.pm @@ -2,7 +2,7 @@ package FS::qual; use strict; use base qw( FS::option_Common ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); =head1 NAME @@ -74,7 +74,55 @@ otherwise returns false. =cut -# the insert method can be inherited from FS::Record +sub insert { + my $self = shift; + my %options = @_; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + if ( $options{'cust_location'} ) { + my $cust_location = $options{'cust_location'}; + my $error = $cust_location->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + $self->locationnum( $cust_location->locationnum ); + } + + my @qual_option = (); + if ( $self->exportnum ) { + my $export = qsearchs( 'part_export', { 'exportnum' => $self->exportnum } ) + or die 'Invalid exportnum'; + + my $qres = $export->qual($self); + unless ( ref($qres) ) { + $dbh->rollback if $oldAutoCommit; + return "Qualification error: $qres"; + } + + $self->$_($qres->{$_}) foreach grep $qres->{$_}, qw(status vendor_qual_id); + @qual_option = ( $qres->{'options'} ) if ref($qres->{'options'}); + } + + my $error = $self->SUPER::insert(@qual_option); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; +} =item delete |