Changeset 293


Ignore:
Timestamp:
03/27/12 17:11:59 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move action logging for delGroup() into DNSDB.pm. See #35.
Extend checks for Things in the group a little
Delete default reverse records as well

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r292 r293  
    18491849# -> ...
    18501850  my $failmsg = '';
     1851  my $resultmsg = '';
     1852
     1853  # collect some pieces for logging and error messages
     1854  my $groupname = groupName($dbh,$groupid);
     1855  my $parid = parentID($dbh, (id => $groupid, type => 'group'));
    18511856
    18521857  # Wrap all the SQL in a transaction
    18531858  eval {
    1854     my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
    1855     $sth->execute($groupid);
    1856     my ($domcnt) = $sth->fetchrow_array;
    1857     $failmsg = "Can't remove group ".groupName($dbh,$groupid);
     1859    # Check for Things in the group
     1860    $failmsg = "Can't remove group $groupname";
     1861    my ($grpcnt) = $dbh->selectrow_array("SELECT count(*) FROM groups WHERE parent_group_id=?", undef, ($groupid));
     1862    die "$grpcnt groups still in group\n" if $grpcnt;
     1863    my ($domcnt) = $dbh->selectrow_array("SELECT count(*) FROM domains WHERE group_id=?", undef, ($groupid));
    18581864    die "$domcnt domains still in group\n" if $domcnt;
    1859 
    1860     $sth = $dbh->prepare("delete from default_records where group_id=?");
    1861     $failmsg = "Failed to delete default records for ".groupName($dbh,$groupid);
    1862     $sth->execute($groupid);
    1863     $sth = $dbh->prepare("delete from groups where group_id=?");
    1864     $failmsg = "Failed to remove group ".groupName($dbh,$groupid);
    1865     $sth->execute($groupid);
     1865    my ($usercnt) = $dbh->selectrow_array("SELECT count(*) FROM users WHERE group_id=?", undef, ($groupid));
     1866    die "$usercnt users still in group\n" if $usercnt;
     1867
     1868    $failmsg = "Failed to delete default records for $groupname";
     1869    $dbh->do("DELETE from default_records WHERE group_id=?", undef, ($groupid));
     1870    $failmsg = "Failed to delete default reverse records for $groupname";
     1871    $dbh->do("DELETE from default_rev_records WHERE group_id=?", undef, ($groupid));
     1872    $failmsg = "Failed to remove group $groupname";
     1873    $dbh->do("DELETE from groups WHERE group_id=?", undef, ($groupid));
     1874
     1875    _log($dbh, (group_id => $parid, entry => "Deleted group $groupname"));
     1876    $resultmsg = "Deleted group $groupname";
    18661877
    18671878    # once we get here, we should have suceeded.
     
    18721883    my $msg = $@;
    18731884    eval { $dbh->rollback; };
     1885    if ($config{log_failures}) {
     1886      _log($dbh, (group_id => $parid, entry => "$failmsg: $msg"));
     1887      $dbh->commit;     # since we enabled transactions earlier
     1888    }
    18741889    return ('FAIL',"$failmsg: $msg");
    1875   } else {
    1876     return ('OK','OK');
    1877   }
     1890  }
     1891
     1892  return ('OK',$resultmsg);
    18781893} # end delGroup()
    18791894
  • trunk/dns.cgi

    r292 r293  
    974974
    975975  } elsif ($webvar{del} eq 'ok') {
    976     my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it...
    977     my $delparent = parentID($dbh, (id => $webvar{id}, type => 'group'));
    978976    my ($code,$msg) = delGroup($dbh, $webvar{id});
    979977    if ($code eq 'OK') {
    980978##fixme: need to clean up log when deleting a major container
    981       logaction(0, $session->param("username"), $delparent, "Deleted group $deleteme");
    982       changepage(page => "grpman", resultmsg => "Deleted group $deleteme");
     979      changepage(page => "grpman", resultmsg => $msg);
    983980    } else {
    984981# need to find failure mode
    985       logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg")
    986         if $config{log_failures};
    987       changepage(page => "grpman", errmsg => "Error deleting group $deleteme: $msg");
     982      changepage(page => "grpman", errmsg => $msg);
    988983    }
    989984  } else {
Note: See TracChangeset for help on using the changeset viewer.