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

Revision 14070, 3.4 KB (checked in by janine, 5 years ago)

LJSUP-2512

Allow individual entries to be suspended/unsuspended without suspending/unsuspending an entire account.
* The entry poster can still view the entry, and can edit it to request an unsuspension.

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 or entry." }
10
11sub args_desc { [
12                 'username or email address or entry url' => "The username of the account to unsuspend, or an email address to unsuspend all accounts at that address, or an entry URL to unsuspend a single entry within an account",
13                 'reason' => "Why you're unsuspending the account or entry",
14                 ] }
15
16sub usage { '<username or email address or entry url> <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 $remote = LJ::get_remote();
30    my $entry = LJ::Entry->new_from_url($user);
31    if ($entry) {
32        my $poster = $entry->poster;
33        my $journal = $entry->journal;
34
35        return $self->error("Invalid entry.")
36            unless $entry->valid;
37
38        return $self->error("Journal and/or poster is purged; cannot unsuspend entry.")
39            if $poster->is_expunged || $journal->is_expunged;
40
41        return $self->error("Entry is not currently suspended.")
42            if $entry->is_visible;
43
44        $entry->set_prop( statusvis => "V" );
45        $entry->set_prop( unsuspend_supportid => 0 )
46            if $entry->prop("unsuspend_supportid");
47
48        $reason = "entry: " . $entry->url . "; reason: $reason";
49        LJ::statushistory_add($journal, $remote, "unsuspend", $reason);
50        LJ::statushistory_add($poster, $remote, "unsuspend", $reason)
51            unless $journal->equals($poster);
52
53        return $self->print("Entry " . $entry->url . " unsuspended.");
54    }
55
56    my @users;
57    if ($user !~ /@/) {
58        push @users, $user;
59
60    } else {
61        $self->info("Acting on users matching email $user");
62
63        my $dbr = LJ::get_db_reader();
64        my $userids = $dbr->selectcol_arrayref('SELECT userid FROM email WHERE email = ?', undef, $user);
65        return $self->error("Database error: " . $dbr->errstr)
66            if $dbr->err;
67
68        return $self->error("No users found matching the email address $user.")
69            unless $userids && @$userids;
70
71        my $us = LJ::load_userids(@$userids);
72
73        foreach my $u (values %$us) {
74            push @users, $u->user;
75        }
76
77        unless ($confirmed eq "confirm") {
78            $self->info("   $_") foreach @users;
79            $self->info("To actually confirm this action, please do this again:");
80            $self->info("   unsuspend $user \"$reason\" confirm");
81            return 1;
82        }
83    }
84
85    foreach my $username (@users) {
86        my $u = LJ::load_user($username);
87
88        unless ($u) {
89            $self->error("Unable to load '$username'");
90            next;
91        }
92
93        unless ($u->is_suspended) {
94            $self->error("$username is not currently suspended; skipping.");
95            next;
96        }
97
98        LJ::update_user($u->{'userid'}, { statusvis => 'V', raw => 'statusvisdate=NOW()' });
99        $u->{statusvis} = 'V';
100
101        LJ::statushistory_add($u, $remote, "unsuspend", $reason);
102        eval { $u->fb_push };
103        warn "Error running fb_push: $@\n" if $@ && $LJ::IS_DEV_SERVER;
104
105        $self->print("User '$username' unsuspended.");
106    }
107
108    return 1;
109}
110
1111;
Note: See TracBrowser for help on using the browser.