From b00cb41411f82ce689308240e47fef1104a2ee0e Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 18 Aug 2011 22:35:53 +0000 Subject: [PATCH] fix errors saving 477 form info if run concurrently, RT#13922 --- FS/FS/Report/FCC_477.pm | 51 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/FS/FS/Report/FCC_477.pm b/FS/FS/Report/FCC_477.pm index 582ddbee4..4c94fff2e 100644 --- a/FS/FS/Report/FCC_477.pm +++ b/FS/FS/Report/FCC_477.pm @@ -142,25 +142,44 @@ Documentation. ); sub restore_fcc477map { - my $key = shift; - FS::Record::scalar_sql('',"select formvalue from fcc477map where formkey = ?",$key); + my $key = shift; + FS::Record::scalar_sql('',"select formvalue from fcc477map where formkey = ?",$key); } sub save_fcc477map { - my $key = shift; - my $value = shift; - - # lame, particularly lack of transactions - - my $sql = "delete from fcc477map where formkey = ?"; - my $sth = dbh->prepare($sql) or die dbh->errstr; - $sth->execute($key) or die "Error removing FCC 477 form defaults: " . $sth->errstr; - - $sql = "insert into fcc477map (formkey,formvalue) values (?,?)"; - $sth = dbh->prepare($sql) or die dbh->errstr; - $sth->execute($key,$value) or die "Error setting FCC 477 form defaults: " . $sth->errstr; - - ''; + my $key = shift; + my $value = shift; + + 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; + + # lame (should be normal FS::Record access) + + my $sql = "delete from fcc477map where formkey = ?"; + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute($key) or do { + warn "WARNING: Error removing FCC 477 form defaults: " . $sth->errstr; + $dbh->rollback if $oldAutoCommit; + }; + + $sql = "insert into fcc477map (formkey,formvalue) values (?,?)"; + $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute($key,$value) or do { + warn "WARNING: Error setting FCC 477 form defaults: " . $sth->errstr; + $dbh->rollback if $oldAutoCommit; + }; + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; } sub parse_technology_option { -- 2.11.0