Changeset 23 for trunk/DNSDB.pm


Ignore:
Timestamp:
10/20/09 14:47:36 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

  • basic group management functional
  • add readable failure messages on domain/group delete
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r22 r23  
    226226  local $dbh->{RaiseError} = 1;
    227227
     228  my $failmsg = '';
     229
    228230  # Wrap all the SQL in a transaction
    229231  eval {
    230232    my $sth = $dbh->prepare("delete from records where domain_id=?");
     233    $failmsg = "Failure removing domain records";
    231234    $sth->execute($domid);
    232235    $sth = $dbh->prepare("delete from domains where domain_id=?");
     236    $failmsg = "Failure removing domain";
    233237    $sth->execute($domid);
    234238
    235 #die "full of fail\n";
    236239    # once we get here, we should have suceeded.
    237 #    $dbh->commit;
     240    $dbh->commit;
    238241  }; # end eval
    239242
     
    241244    my $msg = $@;
    242245    eval { $dbh->rollback; };
    243     return ('FAIL',$msg);
     246    return ('FAIL',"$failmsg: $msg");
    244247  } else {
    245248    return ('OK','OK');
     
    340343
    341344##fixme:  locate "knowable" error conditions and deal with them before the eval
     345# ... or inside, whatever.
    342346# -> domains still exist in group
    343347# -> ...
     348  my $failmsg = '';
    344349
    345350  # Wrap all the SQL in a transaction
    346351  eval {
    347     my $sth = $dbh->prepare("delete from default_records where group_id=?");
     352    my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
     353    $sth->execute($groupid);
     354    my ($domcnt) = $sth->fetchrow_array;
     355    $failmsg = "Can't remove group ".groupName($dbh,$groupid);
     356    die "$domcnt domains still in group\n" if $domcnt;
     357
     358    $sth = $dbh->prepare("delete from default_records where group_id=?");
     359    $failmsg = "Failed to delete default records for ".groupName($dbh,$groupid);
    348360    $sth->execute($groupid);
    349361    $sth = $dbh->prepare("delete from groups where group_id=?");
     362    $failmsg = "Failed to remove group ".groupName($dbh,$groupid);
    350363    $sth->execute($groupid);
    351364
    352 die "epic group fail FTW!\n";
    353365    # once we get here, we should have suceeded.
    354366    $dbh->commit;
     
    358370    my $msg = $@;
    359371    eval { $dbh->rollback; };
    360     return ('FAIL',$msg);
     372    return ('FAIL',"$failmsg: $msg");
    361373  } else {
    362374    return ('OK','OK');
     
    447459    $sql .= " records where domain_id=$id and type=$reverse_typemap{SOA}";
    448460  }
    449 #print "getSOA DEBUG: $sql<br>\n";
    450461  my $sth = $dbh->prepare($sql);
    451462  $sth->execute;
     
    649660  $sth->execute($id);
    650661
    651   return ('FAIL',$sth->errstr) if $sth->err;
     662  return ('FAIL',"Couldn't remove record: ".$sth->errstr) if $sth->err;
    652663
    653664  return ('OK','OK');
Note: See TracChangeset for help on using the changeset viewer.