madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r21971: LJSUP-12200: Need to store delayed posts...

Committer: sbelyaev
LJSUP-12200: Need to store delayed posts after publication
U   trunk/bin/upgrading/update-db-general.pl
U   trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm
U   trunk/cgi-bin/LJ/DelayedEntry.pm
Modified: trunk/bin/upgrading/update-db-general.pl
===================================================================
--- trunk/bin/upgrading/update-db-general.pl	2012-05-16 07:18:36 UTC (rev 21970)
+++ trunk/bin/upgrading/update-db-general.pl	2012-05-16 07:55:13 UTC (rev 21971)
@@ -4480,6 +4480,20 @@
     my $dbh = shift;
     my $runsql = shift;
 
+    unless (column_type("delayedlog2", "finaltime")) {
+        do_alter( "delayedlog2",
+                  "ALTER TABLE delayedlog2 " .
+                  "ADD finaltime datetime DEFAULT NULL, " . 
+                  "ADD url VARCHAR(255) DEFAULT NULL" );
+    }
+
+});
+
+register_alter(sub {
+
+    my $dbh = shift;
+    my $runsql = shift;
+
     unless (column_type("send_email_errors", "message")) {
         do_alter("send_email_errors",
                  "ALTER TABLE send_email_errors " .

Modified: trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm	2012-05-16 07:18:36 UTC (rev 21970)
+++ trunk/cgi-bin/LJ/DelayedEntry/Scheduler.pm	2012-05-16 07:55:13 UTC (rev 21971)
@@ -59,9 +59,9 @@
     my ($dbh) = @_;
     my @entries;
 
-    my $list = $dbh->selectall_arrayref("SELECT journalid, delayedid, posterid " .
-                                        "FROM delayedlog2 ".
-                                        "WHERE posttime <= NOW() LIMIT 1000");
+    my $list = $dbh->selectall_arrayref( "SELECT journalid, delayedid, posterid " .
+                                         "FROM delayedlog2 ".
+                                         "WHERE posttime <= NOW() AND finaltime IS NULL LIMIT 1000" );
     foreach my $tuple (@$list) {
         push @entries, LJ::DelayedEntry->load_data($dbh,
                                                    { journalid  => $tuple->[0],
@@ -147,12 +147,10 @@
                         print "The entry with subject " . $entry->subject;
                         print "\ndelayed id = " . $entry->delayedid . 
                         print " and post date " . $entry->posttime;
-                        print " is deleted because USER CANNOT POST\n";
                     }
 
                     __notify_user(  $entry->poster,
                                     $entry->journal);
-                    $entry->delete();
                     next;
                 }
 
@@ -170,27 +168,6 @@
                         print "\ndelayed id = " . $entry->delayedid . 
                         print " and post date " . $entry->posttime . "\n";
                 }
-
-                if ( $post_status->{delete_entry} ) {
-                    if ($verbose) {
-                        print "The entry with ";
-                        print "\ndelayed id = " . $entry->delayedid . 
-                        print " and post date " . $entry->posttime;
-                        print " is deleted.\n";
-
-                        my $res = $post_status->{'res'};
-                        if ($res) {
-                            my $current_time = DateTime->now;
-                            my $url = $res->{'url'} || '';
-                            print "New post url " . $url;
-                            print " current time : " . $current_time->ymd . ", ";
-                            print $current_time->hms . "\n";
-                        }
-
-                    }
-                
-                    $entry->delete();
-                }
             }
         } 
     };

Modified: trunk/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry.pm	2012-05-16 07:18:36 UTC (rev 21970)
+++ trunk/cgi-bin/LJ/DelayedEntry.pm	2012-05-16 07:55:13 UTC (rev 21971)
@@ -210,6 +210,19 @@
     my $res = LJ::Protocol::do_request("postevent", $req, \$err, $flags);
     my $fail = !defined $res->{itemid} && $res->{message};
 
+
+    if ( $err || !$fail ) {
+        my $url = $res->{'url'} || '';
+        $self->journal->do( "UPDATE delayedlog2 SET ".
+                            "finaltime=NOW(), url=? " .
+                            "WHERE delayedid = ? AND " .
+                                  "journalid = ?", 
+                            undef,
+                            $url,
+                            $self->delayedid,
+                            $self->journalid ); 
+    }
+
     return { 'delete_entry'  => (!$fail || $err < 500),
              'error_message' => $res->{message},
              'res' => $res };
@@ -227,12 +240,30 @@
     if ($fail) {
         $self->update($req);
     }
+
+    
+    if ( $err || !$fail ) {
+        my $url = $res->{'url'} || '';
+        $self->journal->do( "UPDATE delayedlog2 SET ".
+                            "finaltime=NOW(), url=? " .
+                            "WHERE delayedid = ? AND " .
+                                  "journalid = ?",
+                            undef,
+                            $url,
+                            $self->delayedid,
+                            $self->journalid );
+    }
+
     return { 'delete_entry' => (!$fail || $err < 500),
              'res' => $res };
 }
 
 sub delete {
     my ($self) = @_;
+
+    # read https://jira.sup.com/browse/LJSUP-12200
+    __assert( 0, "do not use this function" );
+
     __assert( $self->{delayed_id}, "no delayed id" );
     __assert( $self->{journal}, "no journal" );
 

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