wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r18508: LJSUP-8120. DBD::mysql::db do failed: Du...

Committer: gprochaev
LJSUP-8120. DBD::mysql::db do failed: Duplicate entry

U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/htdocs/admin/browse/top_entries_vertical.bml
A   trunk/htdocs/admin/browse/top_entries_vertical.bml.text
Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2011-03-11 04:37:17 UTC (rev 18507)
+++ trunk/cgi-bin/LJ/Vertical.pm	2011-03-11 05:17:20 UTC (rev 18508)
@@ -1345,7 +1345,12 @@
     return undef unless $entry;
 
     my $dbh = LJ::get_db_writer();
-    my $res = $dbh->do("INSERT INTO vertical_posts (vert_id, journalid, jitemid, timecreate, timeadded) VALUES
+    my $res = $dbh->selectall_arrayref("SELECT 1 FROM vertical_posts WHERE journalid = ? AND jitemid = ?", undef, $entry->journalid, $entry->jitemid) || [];
+
+    ## Record already exist. Return error.
+    return undef if $res && @$res;
+
+    $res = $dbh->do("INSERT INTO vertical_posts (vert_id, journalid, jitemid, timecreate, timeadded) VALUES
         (?, ?, ?, ?, UNIX_TIMESTAMP(NOW()))", undef, $self->vert_id, $entry->journalid, $entry->jitemid, $entry->logtime_unix);
 
     return $res;

Modified: trunk/htdocs/admin/browse/top_entries_vertical.bml
===================================================================
--- trunk/htdocs/admin/browse/top_entries_vertical.bml	2011-03-11 04:37:17 UTC (rev 18507)
+++ trunk/htdocs/admin/browse/top_entries_vertical.bml	2011-03-11 05:17:20 UTC (rev 18508)
@@ -56,6 +56,12 @@
         $vertical->set_remove_after ($POST{'remove_after'});
     }
 
+    if (LJ::did_post() && $vertical && $POST{'add'}) {
+        my $res = $vertical->add_post ($POST{'url'});
+        $ret .= "<?errorbar $ML{'.already.added.error'} errorbar?>"
+            unless $res;
+    }
+
     if ($vert_id) {
         my ($show_entries, $not_deleted, $remove_after) = ();
         if ($vertical) {
@@ -97,10 +103,6 @@
 
     }
 
-    if (LJ::did_post() && $vertical && $POST{'add'}) {
-        $vertical->add_post ($POST{'url'});
-    }
-
     if (LJ::did_post() && $vertical && $POST{'delete_post'}) {
         $vertical->delete_post (post_id => $POST{'rec_id'});
     }

Added: trunk/htdocs/admin/browse/top_entries_vertical.bml.text
===================================================================
--- trunk/htdocs/admin/browse/top_entries_vertical.bml.text	                        (rev 0)
+++ trunk/htdocs/admin/browse/top_entries_vertical.bml.text	2011-03-11 05:17:20 UTC (rev 18508)
@@ -0,0 +1,3 @@
+
+.already.added.error=Post has been already added
+

Tags: bml, livejournal, pm, text, wisest-owl
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