]> git.wh0rd.org Git - tt-rss.git/commitdiff
create_published_article: check for duplicate URLs
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 15 Sep 2012 15:44:33 +0000 (19:44 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 15 Sep 2012 15:44:33 +0000 (19:44 +0400)
include/functions.php

index 3af4af35084471196c97a35e26262ab53fe965bc..b49e0b729b77f2f7df2acd0b91e7bcaf2f66caf2 100644 (file)
 
                if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false;
 
-               $result = db_query($link, "INSERT INTO ttrss_entries
-                       (title, guid, link, updated, content, content_hash, date_entered, date_updated)
-                       VALUES
-                       ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");
-
-               $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'");
+               $result = db_query($link, "SELECT id FROM ttrss_entries WHERE
+                       link = '$url' LIMIT 1");
 
                if (db_num_rows($result) != 0) {
                        $ref_id = db_fetch_result($result, 0, "id");
 
-                       db_query($link, "INSERT INTO ttrss_user_entries
-                               (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
-                               VALUES
-                               ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+                       $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
+                               ref_id = '$ref_id' AND owner_uid = '$owner_uid'");
+
+                       if (db_num_rows($result) != 0) {
+                               db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE
+                                       ref_id = '$ref_id' AND owner_uid = '$owner_uid'");
+                       } else {
+
+                               db_query($link, "INSERT INTO ttrss_user_entries
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+                                       VALUES
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+                       }
 
                        return true;
 
-               }
+               } else {
+                       $result = db_query($link, "INSERT INTO ttrss_entries
+                               (title, guid, link, updated, content, content_hash, date_entered, date_updated)
+                               VALUES
+                               ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");
 
-               return false;
+                       $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'");
+
+                       if (db_num_rows($result) != 0) {
+                               $ref_id = db_fetch_result($result, 0, "id");
+
+                               db_query($link, "INSERT INTO ttrss_user_entries
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+                                       VALUES
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+
+                               return true;
+                       }
+                       return false;
+               }
        }
 
 ?>