fix errors saving 477 form info if run concurrently, RT#13922
authorivan <ivan>
Thu, 18 Aug 2011 22:35:53 +0000 (22:35 +0000)
committerivan <ivan>
Thu, 18 Aug 2011 22:35:53 +0000 (22:35 +0000)
FS/FS/Report/FCC_477.pm

index 582ddbe..4c94fff 100644 (file)
@@ -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 {