Changeset 428 for trunk/DNSDB.pm


Ignore:
Timestamp:
10/11/12 17:11:14 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Polish off the last of the location subs; locations can now be
deleted if there are no more records tagged with that location.
See #10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r425 r428  
    30743074
    30753075## DNSDB::updateLoc()
     3076# Update details of a location.
     3077# Takes a database handle, location ID, group ID, short description,
     3078# long comments/notes, and comma/space-separated IP list
     3079# Returns a result code and message
    30763080sub updateLoc {
    30773081  my $dbh = shift;
     
    31163120
    31173121## DNSDB::delLoc()
    3118 sub delLoc {}
     3122sub delLoc {
     3123  my $dbh = shift;
     3124  my $loc = shift;
     3125
     3126  # Allow transactions, and raise an exception on errors so we can catch it later.
     3127  # Use local to make sure these get "reset" properly on exiting this block
     3128  local $dbh->{AutoCommit} = 0;
     3129  local $dbh->{RaiseError} = 1;
     3130
     3131  my $oldloc = getLoc($dbh, $loc);
     3132  my $olddesc = ($oldloc->{description} ? $oldloc->{description} : $loc);
     3133  my $okmsg = "Deleted location ($olddesc, '".$oldloc->{iplist}."')";
     3134
     3135  eval {
     3136    # Check for records with this location first.  Deleting a location without deleting records
     3137    # tagged for that location will render them unpublished without other warning.
     3138    my ($r) = $dbh->selectrow_array("SELECT record_id FROM records WHERE location=? LIMIT 1", undef, ($loc) );
     3139    die "Records still exist in location $olddesc\n" if $r;
     3140    $dbh->do("DELETE FROM locations WHERE location=?", undef, ($loc) );
     3141    _log($dbh, entry => $okmsg);
     3142    $dbh->commit;
     3143  };
     3144  if ($@) {
     3145    my $msg = $@;
     3146    eval { $dbh->rollback; };
     3147    if ($config{log_failures}) {
     3148      _log($dbh, (entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg"));
     3149      $dbh->commit;
     3150    }
     3151    return ('FAIL', "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg");
     3152  }
     3153
     3154  return ('OK',$okmsg);
     3155} # end delLoc()
    31193156
    31203157
    31213158## DNSDB::getLoc()
     3159# Get details about a location/view
     3160# Takes a database handle and location ID.
     3161# Returns a reference to a hash containing the group ID, IP list, description, and comments/notes
    31223162sub getLoc {
    31233163  my $dbh = shift;
Note: See TracChangeset for help on using the changeset viewer.