]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement proper last_marked/last_published feeds for proper sorting of
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 17 Mar 2013 11:32:44 +0000 (15:32 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 17 Mar 2013 11:38:21 +0000 (15:38 +0400)
published and marked virtual feeds, remove sorting by last_read
workaround
api: add pubsubhubbub ping when article is being set published
bump schema

classes/api.php
classes/rpc.php
include/functions.php
include/rssfuncs.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/105.sql [new file with mode: 0644]
schema/versions/pgsql/105.sql [new file with mode: 0644]

index a23f20ae208e20f1c23e1fd535d386cd4852fd4e..1ee620863a5186510f274219a0497dae990de25c 100644 (file)
@@ -219,12 +219,15 @@ class API extends Handler {
                switch ($field_raw) {
                        case 0:
                                $field = "marked";
+                               $additional_fields = ",last_marked = NOW()";
                                break;
                        case 1:
                                $field = "published";
+                               $additional_fields = ",last_published = NOW()";
                                break;
                        case 2:
                                $field = "unread";
+                               $additional_fields = ",last_read = NOW()";
                                break;
                        case 3:
                                $field = "note";
@@ -248,14 +251,7 @@ class API extends Handler {
 
                        $article_ids = join(", ", $article_ids);
 
-                       if ($field == "unread") {
-                               $result = db_query($this->link, "UPDATE ttrss_user_entries SET $field = $set_to,
-                                       last_read = NOW()
-                                       WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]);
-                       } else {
-                               $result = db_query($this->link, "UPDATE ttrss_user_entries SET $field = $set_to
-                                       WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]);
-                       }
+                       $result = db_query($this->link, "UPDATE ttrss_user_entries SET $field = $set_to $additional_fields WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]);
 
                        $num_updated = db_affected_rows($this->link, $result);
 
@@ -268,6 +264,17 @@ class API extends Handler {
                                }
                        }
 
+                       if ($num_updated > 0 && $field == "published") {
+                               if (PUBSUBHUBBUB_HUB) {
+                                       $rss_link = get_self_url_prefix() .
+                                               "/public.php?op=rss&id=-2&key=" .
+                                               get_feed_access_key($this->link, -2, false);
+
+                                       $p = new Publisher(PUBSUBHUBBUB_HUB);
+                                       $pubsub_result = $p->publish_update($rss_link);
+                               }
+                       }
+
                        print $this->wrap(self::STATUS_OK, array("status" => "OK",
                                "updated" => $num_updated));
 
index 46c8b0d85eba96f94efddf5c0a633df00dbfc489..5d77b1ae8530aa2344c101334d41de391e64ca9c 100644 (file)
@@ -140,7 +140,8 @@ class RPC extends Handler_Protected {
                        $mark = "false";
                }
 
-               $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark
+               $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark,
+                                       last_marked = NOW()
                                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
                print json_encode(array("message" => "UPDATE_COUNTERS"));
@@ -219,7 +220,7 @@ class RPC extends Handler_Protected {
                }
 
                $result = db_query($this->link, "UPDATE ttrss_user_entries SET
-                       published = $pub, last_read = NOW()
+                       published = $pub, last_published = NOW()
                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
                $pubsub_result = false;
@@ -779,15 +780,15 @@ class RPC extends Handler_Protected {
 
                if ($cmode == 0) {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = false,last_read = NOW()
+                       marked = false, last_marked = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                } else if ($cmode == 1) {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = true
+                       marked = true, last_marked = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                } else {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = NOT marked,last_read = NOW()
+                       marked = NOT marked,last_marked = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                }
        }
@@ -804,15 +805,15 @@ class RPC extends Handler_Protected {
 
                if ($cmode == 0) {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       published = false,last_read = NOW()
+                       published = false,last_published = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                } else if ($cmode == 1) {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       published = true,last_read = NOW()
+                       published = true,last_published = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                } else {
                        db_query($link, "UPDATE ttrss_user_entries SET
-                       published = NOT published,last_read = NOW()
+                       published = NOT published,last_published = NOW()
                        WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
                }
 
index f17828d1db2d441696391b5fd58e71f9ddfc280c..bc8d48217c20c10c38d868afb4d83ab0c4f4b7c4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 104);
+       define('SCHEMA_VERSION', 105);
 
        $fetch_last_error = false;
        $pluginhost = false;
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
                                $allow_archived = true;
 
+                               if (!$override_order) $override_order = "last_marked DESC, updated DESC";
+
                        } else if ($feed == -2) { // published virtual feed OR labels category
 
                                if (!$cat_view) {
                                        $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
                                        $allow_archived = true;
 
-                                       if (!$override_order) $override_order = "last_read DESC, updated DESC";
+                                       if (!$override_order) $override_order = "last_published DESC, updated DESC";
                                } else {
                                        $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
 
                                                comments,
                                                int_id,
                                                unread,feed_id,marked,published,link,last_read,orig_feed_id,
+                                               last_marked, last_published,
                                                ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms,
                                                $vfeed_query_part
                                                $content_query_part
                                                                "label_cache," .
                                                                "link," .
                                                                "last_read," .
+                                                               "last_marked, last_published, " .
                                                                SUBSTRING_FOR_DATE . "(last_read,1,19) as last_read_noms," .
                                                                $since_id_part .
                                                                $vfeed_query_part .
index 5c49008c56db1cfbfdb33d9c5dbde49541d8566d..a95280a3180bc889da92a4216c1bbbdf700b79e9 100644 (file)
                                                        }
                                                }
 
+                                               $last_marked = ($marked == 'true') ? 'NOW()' : 'NULL';
+                                               $last_published = ($published == 'true') ? 'NOW()' : 'NULL';
+
                                                $result = db_query($link,
                                                        "INSERT INTO ttrss_user_entries
                                                                (ref_id, owner_uid, feed_id, unread, last_read, marked,
-                                                                       published, score, tag_cache, label_cache, uuid)
+                                                               published, score, tag_cache, label_cache, uuid,
+                                                               last_marked, last_published)
                                                        VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
-                                                               $last_read_qpart, $marked, $published, '$score', '', '', '')");
+                                                               $last_read_qpart, $marked, $published, '$score', '', '',
+                                                               '', $last_marked, $last_published)");
 
                                                if (PUBSUBHUBBUB_HUB && $published == 'true') {
                                                        $rss_link = get_self_url_prefix() .
index bf02e7b1e7a099c36eb52c921dcfee5c60206c59..d4873ecb0efda98710e460cda39503a9eba0b619 100644 (file)
@@ -179,6 +179,8 @@ create table ttrss_user_entries (
        last_read datetime,
        score int not null default 0,
        note longtext,
+       last_marked datetime,
+       last_published datetime,
        unread bool not null default 1,
        index (ref_id),
        foreign key (ref_id) references ttrss_entries(id) ON DELETE CASCADE,
@@ -310,7 +312,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (104);
+insert into ttrss_version values (105);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
index e19b8cbc64524de1731447fb5bd94cbcfe0acd80..5063c4dd81a1c7f5ce893cf386a6abe7800e1c9b 100644 (file)
@@ -159,6 +159,8 @@ create table ttrss_user_entries (
        label_cache text not null,
        last_read timestamp,
        score int not null default 0,
+       last_marked timestamp,
+       last_published timestamp,
        note text,
        unread boolean not null default true);
 
@@ -258,7 +260,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (104);
+insert into ttrss_version values (105);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
diff --git a/schema/versions/mysql/105.sql b/schema/versions/mysql/105.sql
new file mode 100644 (file)
index 0000000..a961017
--- /dev/null
@@ -0,0 +1,11 @@
+begin;
+
+alter table ttrss_user_entries add column last_marked datetime;
+alter table ttrss_user_entries add column last_published datetime;
+
+update ttrss_user_entries set last_published = last_read where published = true;
+update ttrss_user_entries set last_marked = last_read where marked = true;
+
+update ttrss_version set schema_version = 105;
+
+commit;
diff --git a/schema/versions/pgsql/105.sql b/schema/versions/pgsql/105.sql
new file mode 100644 (file)
index 0000000..11ef679
--- /dev/null
@@ -0,0 +1,11 @@
+begin;
+
+alter table ttrss_user_entries add column last_marked timestamp;
+alter table ttrss_user_entries add column last_published timestamp;
+
+update ttrss_user_entries set last_published = last_read where published = true;
+update ttrss_user_entries set last_marked = last_read where marked = true;
+
+update ttrss_version set schema_version = 105;
+
+commit;