From 7873d588227cba4c66e2535b1be631736415ef6f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 17 Mar 2013 15:32:44 +0400 Subject: [PATCH] implement proper last_marked/last_published feeds for proper sorting of 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 | 23 +++++++++++++++-------- classes/rpc.php | 17 +++++++++-------- include/functions.php | 8 ++++++-- include/rssfuncs.php | 9 +++++++-- schema/ttrss_schema_mysql.sql | 4 +++- schema/ttrss_schema_pgsql.sql | 4 +++- schema/versions/mysql/105.sql | 11 +++++++++++ schema/versions/pgsql/105.sql | 11 +++++++++++ 8 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 schema/versions/mysql/105.sql create mode 100644 schema/versions/pgsql/105.sql diff --git a/classes/api.php b/classes/api.php index a23f20ae2..1ee620863 100644 --- a/classes/api.php +++ b/classes/api.php @@ -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)); diff --git a/classes/rpc.php b/classes/rpc.php index 46c8b0d85..5d77b1ae8 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -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"]); } diff --git a/include/functions.php b/include/functions.php index f17828d1d..bc8d48217 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@