madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r22803: LJSUP-10503: duplication of delay posts

Committer: sbelyaev
LJSUP-10503: duplication of delay posts
U   trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm
U   trunk/cgi-bin/LJ/DelayedEntry.pm
Modified: trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm	2012-09-04 08:26:58 UTC (rev 22802)
+++ trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm	2012-09-04 10:34:54 UTC (rev 22803)
@@ -56,12 +56,14 @@
 }
 
 sub __load_delayed_entries {
-    my ($dbh) = @_;
+    my ($dbh, $verbose) = @_;
     my @entries;
 
     my $list = $dbh->selectall_arrayref( "SELECT journalid, delayedid, posterid " .
                                          "FROM delayedlog2 ".
                                          "WHERE posttime <= NOW() AND finaltime IS NULL LIMIT 1000" );
+
+    print "loaded list to post: " . LJ::D($list) if $verbose; 
     foreach my $tuple (@$list) {
         push @entries, LJ::DelayedEntry->load_data($dbh,
                                                    { journalid  => $tuple->[0],
@@ -138,7 +140,7 @@
     }
 
     eval {
-        while ( my $entries = __load_delayed_entries($dbh) ) {
+        while ( my $entries = __load_delayed_entries($dbh, $verbose) ) {
             foreach my $entry (@$entries) {
                 if (!LJ::DelayedEntry::can_post_to($entry->journal,
                                                    $entry->poster)) {
@@ -156,7 +158,7 @@
                     next;
                 }
 
-                my $post_status = $entry->convert();
+                my $post_status = $entry->convert($verbose);
 
                 # do we need to send error
                 if ( $post_status->{'error_message'} ) {

Modified: trunk/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry.pm	2012-09-04 08:26:58 UTC (rev 22802)
+++ trunk/cgi-bin/LJ/DelayedEntry.pm	2012-09-04 10:34:54 UTC (rev 22803)
@@ -199,32 +199,41 @@
 }
 
 sub convert {
-    my ($self) = @_;
+    my ($self, $verbose) = @_;
     my $req = $self->{data};
 
     my $flags = { 'noauth' => 1,
                   'use_custom_time' => 0,
                   'u' => $self->poster };
 
-    my $err = 0;
+    warn "postevent user " . $self->poster->userid if $verbose;
+
+    my $err = '';
     my $res = LJ::Protocol::do_request("postevent", $req, \$err, $flags);
-    my $fail = !defined $res->{itemid} && $res->{message};
+    my ($error_code, $text) = split(/:/, $err);
+    $error_code ||= 0;
 
+    if ( !$err ) {
+        my $url = $res->{'url'} || '';
+        warn "no error : ";
+        warn "delayed id : " . $self->delayedid;
+        warn "journal id : " . $self->journalid;
+        warn "url : $url";
 
-    if ( $err || !$fail ) {
-        my $url = $res->{'url'} || '';
         $self->journal->do( "UPDATE delayedlog2 SET ".
                             "finaltime=NOW(), url=? " .
                             "WHERE delayedid = ? AND " .
-                                  "journalid = ?", 
+                            "journalid = ?", 
                             undef,
                             $url,
                             $self->delayedid,
                             $self->journalid ); 
+    } elsif ($verbose) {
+        warn "error $err";
     }
 
-    return { 'delete_entry'  => (!$fail || $err < 500),
-             'error_message' => $res->{message},
+    return { 'delete_entry'  => !($error_code < 500),
+             'error_message' => $text || '',
              'res' => $res };
 }
 
@@ -249,13 +258,15 @@
 
     my $err = 0;
     my $res = LJ::Protocol::do_request("postevent", $req, \$err, $flags);
-    my $fail = !defined $res->{itemid} && $res->{message};
-    if ($fail) {
+    if ($err) {
         $self->update($req);
     }
 
+    my ($error_code, $text) = split(/:/, $err);
+    $error_code ||= 0;
+    $text       ||= '';
     
-    if ( $err || !$fail ) {
+    if ( !$err ) {
         my $url = $res->{'url'} || '';
         $self->journal->do( "UPDATE delayedlog2 SET ".
                             "finaltime=NOW(), url=? " .
@@ -267,7 +278,8 @@
                             $self->journalid );
     }
 
-    return { 'delete_entry' => (!$fail || $err < 500),
+    return { 'delete_entry' => !($error_code < 500),
+             'error_message' => $text || '',
              'res' => $res };
 }
 

Tags: livejournal, madeon, pm, sbelyaev
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