[freeside-commits] freeside/FS/FS qual.pm,1.8,1.9

Ivan,,, ivan at wavetail.420.am
Sat Mar 12 13:13:36 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv2884/FS/FS

Modified Files:
	qual.pm 
Log Message:
refactor transaction from process/qual.cgi to qual.pm insert, RT#7111

Index: qual.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/qual.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -d -r1.8 -r1.9
--- qual.pm	20 Jan 2011 20:46:29 -0000	1.8
+++ qual.pm	12 Mar 2011 21:13:34 -0000	1.9
@@ -2,7 +2,7 @@
 
 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 @@
 
 =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
 



More information about the freeside-commits mailing list