Index: trunk/DNSDB.pm
===================================================================
--- trunk/DNSDB.pm	(revision 309)
+++ trunk/DNSDB.pm	(revision 311)
@@ -2494,5 +2494,4 @@
   my $rev = shift;
   my $id = shift;
-  my %ret;
 
   # (ab)use distance and weight columns to store SOA data?  can't for default_rev_records...
@@ -2501,24 +2500,14 @@
   my $sql = "SELECT record_id,host,val,ttl from "._rectable($def,$rev).
 	" WHERE "._recparent($def,$rev)." = ? AND type=$reverse_typemap{SOA}";
-
-  my $sth = $dbh->prepare($sql);
-  $sth->execute($id);
+  my $ret = $dbh->selectrow_hashref($sql, undef, ($id) );
+  return if !$ret;
 ##fixme:  stick a flag somewhere if the record doesn't exist.  by the API, this is an impossible case, but...
 
-  my ($recid,$host,$val,$ttl) = $sth->fetchrow_array() or return;
-  my ($contact,$prins) = split /:/, $host;
-  my ($refresh,$retry,$expire,$minttl) = split /:/, $val;
-
-  $ret{recid}	= $recid;
-  $ret{ttl}	= $ttl;
-#  $ret{serial}	= $serial;	# ca't use distance for serial with default_rev_records
-  $ret{prins}	= $prins;
-  $ret{contact}	= $contact;
-  $ret{refresh}	= $refresh;
-  $ret{retry}	= $retry;
-  $ret{expire}	= $expire;
-  $ret{minttl}	= $minttl;
-
-  return %ret;
+  ($ret->{contact},$ret->{prins}) = split /:/, $ret->{host};
+  delete $ret->{host};
+  ($ret->{refresh},$ret->{retry},$ret->{expire},$ret->{minttl}) = split /:/, $ret->{val};
+  delete $ret->{val};
+
+  return $ret;
 } # end getSOA()
 
@@ -2535,5 +2524,18 @@
   my %soa = @_;
 
-  my %oldsoa = getSOA($dbh, $defrec, $revrec, $soa{recid});
+  my $oldsoa = getSOA($dbh, $defrec, $revrec, $soa{id});
+
+  my $msg;
+  my %logdata;
+  if ($defrec eq 'n') {
+    $logdata{domain_id} = $soa{id} if $revrec eq 'n';
+    $logdata{rdns_id} = $soa{id} if $revrec eq 'y';
+    $logdata{group_id} = parentID($dbh, (id => $soa{id}, revrec => $revrec,
+	type => ($revrec eq 'n' ? 'domain' : 'revzone') ) );
+  } else {
+    $logdata{group_id} = $soa{id};
+  }
+  my $parname = ($defrec eq 'y' ? groupName($dbh, $soa{id}) :
+		($revrec eq 'n' ? domainName($dbh, $soa{id}) : revName($dbh, $soa{id})) );
 
   # Allow transactions, and raise an exception on errors so we can catch it later.
@@ -2542,22 +2544,17 @@
   local $dbh->{RaiseError} = 1;
 
-  my $msg;
-
   eval {
-##fixme: data validation: make sure {recid} is really the SOA for {parent}
     my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
     $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
-        $soa{ttl}, $soa{recid}) );
-
-    $msg = "Updated ".($defrec eq 'y' ? 'default ' : '')."SOA for ".
-	($defrec eq 'y' ? groupName($dbh, $soa{recid}) : 
-		($revrec eq 'n' ? domainName($dbh, $soa{recid}) : revName($dbh, $soa{recid}) ) ).
-	": (ns $oldsoa{prins}, contact $oldsoa{contact}, refresh $oldsoa{refresh},".
-	" retry $oldsoa{retry}, expire $oldsoa{expire}, minTTL $oldsoa{minttl}, TTL $oldsoa{ttl}) to ".
+        $soa{ttl}, $oldsoa->{record_id}) );
+    $msg = "Updated ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse ' : 'default ') : '').
+	"SOA for $parname: ".
+	"(ns $oldsoa->{prins}, contact $oldsoa->{contact}, refresh $oldsoa->{refresh},".
+	" retry $oldsoa->{retry}, expire $oldsoa->{expire}, minTTL $oldsoa->{minttl}, TTL $oldsoa->{ttl}) to ".
 	"(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},".
 	" retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})";
 
-#    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
-#	username => $userinfo{name}, entry => $msg) );
+    $logdata{entry} = $msg;
+    _log($dbh, %logdata);
 
     $dbh->commit;
@@ -2566,5 +2563,11 @@
     $msg = $@;
     eval { $dbh->rollback; };
-    return ('FAIL',$msg);
+    $logdata{entry} = "Error updating ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse zone ' : 'default ') : '').
+	"SOA record for $parname: $msg";
+    if ($config{log_failures}) {
+      _log($dbh, %logdata);
+      $dbh->commit;
+    }
+    return ('FAIL', $logdata{entry});
   } else {
     return ('OK', $msg);
