Committer: vsukhanov
LJSUP-8224: Improvement of ban_unset console command.U trunk/cgi-bin/LJ/Console/Command/BanUnset.pm
Modified: trunk/cgi-bin/LJ/Console/Command/BanUnset.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/BanUnset.pm 2011-03-21 09:59:22 UTC (rev 18650) +++ trunk/cgi-bin/LJ/Console/Command/BanUnset.pm 2011-03-21 10:03:40 UTC (rev 18651) @@ -13,7 +13,7 @@ 'community' => "Optional; to unban a user from a community you maintain.", ] } -sub usage { '<user> [ "from" <community> ]' } +sub usage { '[<user>|+inactive] [ "from" <community> ]' } sub can_execute { 1 } @@ -38,16 +38,62 @@ unless $remote && $remote->can_manage($journal); } - my $banuser = LJ::load_user($user); - return $self->error("Unknown account: $user") - unless $banuser; + ## + ## It's possible to remove users from a ban list one by one + ## or perform a mass action. + ## Currently supported only one form of a mass unban command: + ## + ## ban_unset +inactive [from <community>] + ## + ## It removes suspended (eXpurged) users from ban list, + ## becouse there no any reason to keep such users in the list. + ## + if ($user eq '+inactive'){ + ## remove suspended users from ban list + + ## get User IDs + my $banids = LJ::load_rel_user($journal, 'B') || []; + + while (my @ids_batch = splice(@$banids, 0 => 500)){ + ## load users + my $us = LJ::load_userids(@ids_batch); + while (my (undef, $banuser) = each %$us){ + ## We are interested in suspended or expunged users only. + if ($banuser->is_suspended or $banuser->is_expunged){ + ## remove suspended user from ban list + ban_unset($remote, $journal, $banuser); + $self->print("User " . $banuser->user . " unbanned from " . $journal->user); + } + } + } + } else { + ## remove specified users from ban list + my $banuser = LJ::load_user($user); + return $self->error("Unknown account: $user") + unless $banuser; + + ban_unset($remote, $journal, $banuser); + + return $self->print("User " . $banuser->user . " unbanned from " . $journal->user); + } + + return 1; +} + +sub ban_unset { + my ($remote, $journal, $banuser) = @_; + LJ::clear_rel($journal, $banuser, 'B'); $journal->log_event('ban_unset', { actiontarget => $banuser->id, remote => $remote }); LJ::run_hooks('ban_unset', $journal, $banuser); - return $self->print("User " . $banuser->user . " unbanned from " . $journal->user); + } + + + + 1;