Changeset 296 for trunk/DNSDB.pm


Ignore:
Timestamp:
04/02/12 16:58:39 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Move action logging for user status change into userStatus(). See #35

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r295 r296  
    22852285  my $dbh = shift;
    22862286  my $id = shift;
    2287   my $newstatus = shift;
     2287  my $newstatus = shift || 'mu';
    22882288
    22892289  return undef if $id !~ /^\d+$/;
    22902290
    2291   my $sth;
    2292 
    2293 # ooo, fun!  let's see what we were passed for status
    2294   if ($newstatus) {
    2295     $sth = $dbh->prepare("update users set status=? where user_id=?");
    2296     # ass-u-me caller knows what's going on in full
    2297     if ($newstatus =~ /^[01]$/) {       # only two valid for now.
    2298       $sth->execute($newstatus,$id);
    2299     } elsif ($newstatus =~ /^usero(?:n|ff)$/) {
    2300       $sth->execute(($newstatus eq 'useron' ? 1 : 0),$id);
    2301     }
    2302   }
    2303 
    2304   $sth = $dbh->prepare("select status from users where user_id=?");
    2305   $sth->execute($id);
    2306   my ($status) = $sth->fetchrow_array;
     2291  my $userdata = getUserData($dbh, $id);
     2292
     2293  # Allow transactions, and raise an exception on errors so we can catch it later.
     2294  # Use local to make sure these get "reset" properly on exiting this block
     2295  local $dbh->{AutoCommit} = 0;
     2296  local $dbh->{RaiseError} = 1;
     2297
     2298  if ($newstatus ne 'mu') {
     2299    # ooo, fun!  let's see what we were passed for status
     2300    eval {
     2301      $newstatus = 0 if $newstatus eq 'useroff';
     2302      $newstatus = 1 if $newstatus eq 'useron';
     2303      $dbh->do("UPDATE users SET status=? WHERE user_id=?", undef, ($newstatus, $id));
     2304
     2305      $resultstr = ($newstatus ? 'Enabled' : 'Disabled')." user ".$userdata->{username};
     2306
     2307      my %loghash;
     2308      $loghash{group_id} = parentID($dbh, (id => $id, type => 'user'));
     2309      $loghash{entry} = $resultstr;
     2310      _log($dbh, %loghash);
     2311
     2312      $dbh->commit;
     2313    };
     2314    if ($@) {
     2315      my $msg = $@;
     2316      eval { $dbh->rollback; };
     2317      $resultstr = '';
     2318      $errstr = $msg;
     2319##fixme: failure logging?
     2320      return;
     2321    }
     2322  }
     2323
     2324  my ($status) = $dbh->selectrow_array("SELECT status FROM users WHERE user_id=?", undef, ($id));
    23072325  return $status;
    23082326} # end userStatus()
Note: See TracChangeset for help on using the changeset viewer.