Changeset 377 for trunk/DNSDB.pm


Ignore:
Timestamp:
08/09/12 16:36:01 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint adding locations to UI. See #10.

  • Add location list sort field and order initialization to session setup
  • Fix up a minor copy-paste oversight
  • Fill in location update stubs
  • Add missing logging and code-style bits to addLoc()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r375 r377  
    29592959    $dbh->do("INSERT INTO locations (location, group_id, iplist, description, comments) VALUES (?,?,?,?,?)",
    29602960        undef, ($loc, $grp, $iplist, $shdesc, $comments) );
     2961    _log($dbh, entry => "Added location ($shdesc, '$iplist')");
     2962    $dbh->commit;
    29612963  };
    29622964  if ($@) {
     
    29722974
    29732975  return ('OK',$loc);
    2974 }
     2976} # end addLoc()
    29752977
    29762978
    29772979## DNSDB::updateLoc()
    2978 sub updateLoc {}
     2980sub updateLoc {
     2981  my $dbh = shift;
     2982  my $loc = shift;
     2983  my $grp = shift;
     2984  my $shdesc = shift;
     2985  my $comments = shift;
     2986  my $iplist = shift;
     2987
     2988  $shdesc = '' if !$shdesc;
     2989  $comments = '' if !$comments;
     2990  $iplist = '' if !$iplist;
     2991
     2992  # Allow transactions, and raise an exception on errors so we can catch it later.
     2993  # Use local to make sure these get "reset" properly on exiting this block
     2994  local $dbh->{AutoCommit} = 0;
     2995  local $dbh->{RaiseError} = 1;
     2996
     2997  my $oldloc = getLoc($dbh, $loc);
     2998  my $okmsg = "Updated location (".$oldloc->{description}.", '".$oldloc->{iplist}."') to ($shdesc, '$iplist')";
     2999
     3000  eval {
     3001    $dbh->do("UPDATE locations SET group_id=?,iplist=?,description=?,comments=? WHERE location=?",
     3002        undef, ($grp, $iplist, $shdesc, $comments, $loc) );
     3003    _log($dbh, entry => $okmsg);
     3004    $dbh->commit;
     3005  };
     3006  if ($@) {
     3007    my $msg = $@;
     3008    eval { $dbh->rollback; };
     3009    if ($config{log_failures}) {
     3010      $shdesc = $loc if !$shdesc;
     3011      _log($dbh, (entry => "Failed updating location ($shdesc, '$iplist'): $msg"));
     3012      $dbh->commit;
     3013    }
     3014    return ('FAIL',$msg);
     3015  }
     3016
     3017  return ('OK',$okmsg);
     3018} # end updateLoc()
     3019
    29793020
    29803021## DNSDB::delLoc()
Note: See TracChangeset for help on using the changeset viewer.