ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[livejournal] r17772: LJSUP-7429: Handle "database unavailable...

Committer: ssafronova
LJSUP-7429: Handle "database unavailable" error in "mark-suspended-entries" worker
U   trunk/cgi-bin/LJ/Console/Command/Unsuspend.pm
Modified: trunk/cgi-bin/LJ/Console/Command/Unsuspend.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/Unsuspend.pm	2010-11-24 09:21:14 UTC (rev 17771)
+++ trunk/cgi-bin/LJ/Console/Command/Unsuspend.pm	2010-11-24 09:50:57 UTC (rev 17772)
@@ -6,14 +6,15 @@
 
 sub cmd { "unsuspend" }
 
-sub desc { "Unsuspend an account or entry." }
+sub desc { "Unsuspend an account or entry. Or unmark entries made by already unsuspended account." }
 
 sub args_desc { [
+                 '--unmark' => "Optional flag to not check 'suspended' status but simply put job for worker to unmark again. Not applicable to entry level.",
                  '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",
                  'reason' => "Why you're unsuspending the account or entry",
                  ] }
 
-sub usage { '<username or email address or entry url> <reason>' }
+sub usage { '[--unmark] <username or email address or entry url> <reason>' }
 
 sub can_execute {
     my $remote = LJ::get_remote();
@@ -21,9 +22,16 @@
 }
 
 sub execute {
-    my ($self, $user, $reason, $confirmed, @args) = @_;
+    my ($self, $flag_unmark, $user, $reason, $confirmed, @args) = @_;
+    if (lc($flag_unmark) ne '--unmark') {
+        unshift @args, $confirmed if defined $confirmed;
+        $confirmed = $reason;
+        $reason = $user;
+        $user = $flag_unmark;
+        $flag_unmark = undef;
+    }
 
-    return $self->error("This command takes two arguments. Consult the reference.")
+    return $self->error("This command takes two arguments (and one optional flag). Consult the reference.")
         unless $user && $reason && scalar(@args) == 0;
 
     my $remote = LJ::get_remote();
@@ -92,48 +100,56 @@
             next;
         }
 
-        unless ($u->is_suspended) {
-            $self->error("$username is not currently suspended; skipping.");
-            next;
-        }
+        unless ($flag_unmark) {
 
-        ## Restore previous statusvis of journal. It may be different
-        ## from 'V', it may be read-only, or locked, or whatever.
-        my @previous_status;
-        if ($u->clusterid) { # purged user has no cluster, but can be suspended
-            @previous_status = grep { $_ ne 'S' } $u->get_previous_statusvis;
-        } else { # was purged - no data any more
-            @previous_status = ('X');
-        }
-        my $new_status = $previous_status[0] || 'V';
-        my $method = {
-            V => 'set_visible',
-            L => 'set_locked',
-            M => 'set_memorial',
-            O => 'set_readonly',
-            R => 'set_renamed',
-            X => 'set_expunged',
-            D => 'set_deleted',
-        }->{$new_status};
+            unless ($u->is_suspended) {
+                $self->error("$username is not currently suspended; skipping.");
+                next;
+            }
 
-        unless ($method) {
-            $self->error("Can't set status '$new_status'");
-            next;
-        }
+            ## Restore previous statusvis of journal. It may be different
+            ## from 'V', it may be read-only, or locked, or whatever.
+            my @previous_status;
+            if ($u->clusterid) { # purged user has no cluster, but can be suspended
+                @previous_status = grep { $_ ne 'S' } $u->get_previous_statusvis;
+            } else { # was purged - no data any more
+                @previous_status = ('X');
+            }
+            my $new_status = $previous_status[0] || 'V';
+            my $method = {
+                V => 'set_visible',
+                L => 'set_locked',
+                M => 'set_memorial',
+                O => 'set_readonly',
+                R => 'set_renamed',
+                X => 'set_expunged',
+                D => 'set_deleted',
+            }->{$new_status};
 
-        my $res = $u->$method;
+            unless ($method) {
+                $self->error("Can't set status '$new_status'");
+                next;
+            }
 
-        $u->{statusvis} = $new_status;
+            my $res = $u->$method;
 
+            $u->{statusvis} = $new_status;
+
+        }
+
         my $job = TheSchwartz::Job->new_from_array("LJ::Worker::MarkSuspendedEntries::unmark", { userid => $u->userid });
         my $sclient = LJ::theschwartz();
         $sclient->insert_jobs($job) if $sclient and $job and LJ::is_enabled('mark_suspended_accounts');
 
-        LJ::statushistory_add($u, $remote, "unsuspend", $reason);
-        eval { $u->fb_push };
-        warn "Error running fb_push: $@\n" if $@ && $LJ::IS_DEV_SERVER;
+        unless ($flag_unmark) {
+            LJ::statushistory_add($u, $remote, "unsuspend", $reason);
+            eval { $u->fb_push };
+            warn "Error running fb_push: $@\n" if $@ && $LJ::IS_DEV_SERVER;
 
-        $self->print("User '$username' unsuspended.");
+            $self->print("User '$username' unsuspended.");
+        } else {
+            $self->print("Unmark job put for '$username' user.");
+        }
     }
 
     return 1;

Tags: livejournal, pm, ssafronova
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments