root/trunk/cgi-bin/LJ/Console/Command/Unsuspend.pm @ 12444

Revision 12444, 2.4 KB (checked in by ahassan, 6 years ago)

Use accessors

Line 
1package LJ::Console::Command::Unsuspend;
2
3use strict;
4use base qw(LJ::Console::Command);
5use Carp qw(croak);
6
7sub cmd { "unsuspend" }
8
9sub desc { "Unsuspend an account." }
10
11sub args_desc { [
12                 'username or email address' => "The username of the account to unsuspend, or an email address to unsuspend all accounts at that address.",
13                 'reason' => "Why you're unsuspending the account.",
14                 ] }
15
16sub usage { '<username or email address> <reason>' }
17
18sub can_execute {
19    my $remote = LJ::get_remote();
20    return LJ::check_priv($remote, "suspend");
21}
22
23sub execute {
24    my ($self, $user, $reason, $confirmed, @args) = @_;
25
26    return $self->error("This command takes two arguments. Consult the reference.")
27        unless $user && $reason && scalar(@args) == 0;
28
29    my @users;
30    if ($user !~ /@/) {
31        push @users, $user;
32
33    } else {
34        $self->info("Acting on users matching email $user");
35
36        my $dbr = LJ::get_db_reader();
37        my $userids = $dbr->selectcol_arrayref('SELECT userid FROM email WHERE email = ?', undef, $user);
38        return $self->error("Database error: " . $dbr->errstr)
39            if $dbr->err;
40
41        return $self->error("No users found matching the email address $user.")
42            unless $userids && @$userids;
43
44        my $us = LJ::load_userids(@$userids);
45
46        foreach my $u (values %$us) {
47            push @users, $u->user;
48        }
49
50        unless ($confirmed eq "confirm") {
51            $self->info("   $_") foreach @users;
52            $self->info("To actually confirm this action, please do this again:");
53            $self->info("   unsuspend $user \"$reason\" confirm");
54            return 1;
55        }
56    }
57
58    foreach my $username (@users) {
59        my $u = LJ::load_user($username);
60
61        unless ($u) {
62            $self->error("Unable to load '$username'");
63            next;
64        }
65
66        unless ($u->is_suspended) {
67            $self->error("$username is not currently suspended; skipping.");
68            next;
69        }
70
71        LJ::update_user($u->{'userid'}, { statusvis => 'V', raw => 'statusvisdate=NOW()' });
72        $u->{statusvis} = 'V';
73
74        my $remote = LJ::get_remote();
75        LJ::statushistory_add($u, $remote, "unsuspend", $reason);
76        eval { $u->fb_push };
77        warn "Error running fb_push: $@\n" if $@ && $LJ::IS_DEV_SERVER;
78
79        $self->info("User '$username' unsuspended.");
80    }
81
82    return 1;
83}
84
851;
Note: See TracBrowser for help on using the browser.