]> git.wh0rd.org Git - tt-rss.git/commitdiff
command globalUpdateFeeds to update feeds of all users at once
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 21 Nov 2005 07:11:21 +0000 (08:11 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 21 Nov 2005 07:11:21 +0000 (08:11 +0100)
backend.php
db-prefs.php
error.php
functions.php

index 1da333648cbe93fcab684688553f9a6651337925..6a0a02ecefc0623dd2a073a812d7464d31eff83b 100644 (file)
@@ -3,20 +3,23 @@
 
        $op = $_REQUEST["op"];
 
-       if (($op == "rpc" || $op == "updateAllFeeds" || 
-                       $op == "forceUpdateAllFeeds") && !$_REQUEST["noxml"]) {
+       if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
                header("Content-Type: application/xml");
        }
 
-       if (!$_SESSION["uid"]) {
+       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
 
-               if (($op == "rpc" || $op == "updateAllFeeds" || 
-                       $op == "forceUpdateAllFeeds")) {
+               if ($op == "rpc") {
                        print "<error error-code=\"6\"/>";
                }
                exit;
        }
 
+       if (!$op) {
+               print "<error error-code=\"7\"/>";
+               exit;
+       }
+
        define(SCHEMA_VERSION, 2);
 
        require_once "config.php";
 
        }
 
-       if ($op == "updateAllFeeds") {
-               update_all_feeds($link, true);                  
+       // update feeds of all users, may be used anonymously
+       if ($op == "globalUpdateFeeds") {
+
+               $result = db_query($link, "SELECT id FROM ttrss_users");
+
+               while ($line = db_fetch_assoc($result)) {
+                       $user_id = $line["id"];
+//                     print "<!-- updating feeds of uid $user_id -->";
+                       update_all_feeds($link, false, $user_id);
+               }
 
-               print "<rpc-reply>";
-               getLabelCounters($link);
-               getFeedCounters($link);
-               getTagCounters($link);
-               getGlobalCounters($link);
-               print "</rpc-reply>";
+               print "<rpc-reply>
+                       <message msg=\"All feeds updated\"/>
+               </rpc-reply>";
 
        }
 
index 16278c54045db3e5297053b1c623479663be0b67..c81149e6f08fd5acbf1aed7683d65a3921427d6d 100644 (file)
@@ -4,10 +4,16 @@
        require_once "config.php";
        require_once "db.php";
 
-       function get_pref($link, $pref_name) {
+       function get_pref($link, $pref_name, $user_id = false) {
 
                $pref_name = db_escape_string($pref_name);
 
+               if (!$user_id) {
+                       $user_id = $_SESSION["uid"];
+               } else {
+                       $user_id = sprintf("%d", $user_id);
+               }
+
                $result = db_query($link, "SELECT 
                        value,ttrss_prefs_types.type_name as type_name 
                        FROM 
@@ -15,7 +21,7 @@
                        WHERE 
                                ttrss_user_prefs.pref_name = '$pref_name' AND 
                                ttrss_prefs_types.id = type_id AND
-                               owner_uid = ".$_SESSION["uid"]." AND
+                               owner_uid = '$user_id' AND
                                ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
 
                if (db_num_rows($result) > 0) {
index 1569d309efc34364d36fe98fe6b948315c7c922e..6a7b529724ab22d708df54ea5527bd0bd49f8e5a 100644 (file)
--- a/error.php
+++ b/error.php
@@ -23,6 +23,8 @@
                header("Location: login.php");
        }
 
+       $ERRORS[7] = "No operation to perform.";
+
 ?>
 
 <html>
index b047221efba3f682b4dbbc723b4ed44ac41706b5..35460efbd95f9f7d2810d9ca56005291265a3411 100644 (file)
                        (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
        }
 
-       function update_all_feeds($link, $fetch) {
+       function update_all_feeds($link, $fetch, $user_id = false) {
 
                if (WEB_DEMO_MODE) return;
 
-               if (get_pref($link, 'DAEMON_REFRESH_ONLY')) {
+               if (!$user_id) {
+                       $user_id = $_SESSION["uid"];
+                       purge_old_posts($link);
+               }
+
+               if (get_pref($link, 'DAEMON_REFRESH_ONLY', $user_id)) {
                        if (!$_GET["daemon"]) {
                                return;
                        }
@@ -94,8 +99,6 @@
 
                db_query($link, "BEGIN");
 
-               $user_id = $_SESSION["uid"];
-
                $result = db_query($link, "SELECT feed_url,id,
                        substring(last_updated,1,19) as last_updated,
                        update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'");
                        $upd_intl = $line["update_interval"];
 
                        if (!$upd_intl || $upd_intl == 0) {
-                               $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL');
+                               $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
                        }
 
                        if ($fetch || (!$line["last_updated"] || 
                        }
                }
 
-               purge_old_posts($link);
-
                db_query($link, "COMMIT");
 
        }
 
                if ($rss) {
 
-                       if (get_pref($link, 'ENABLE_FEED_ICONS')) {     
-                               check_feed_favicon($feed_url, $feed, $link);
-                       }
-               
                        $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid 
                                FROM ttrss_feeds WHERE id = '$feed'");
 
 
                        $owner_uid = db_fetch_result($result, 0, "owner_uid");
 
+                       if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid)) { 
+                               check_feed_favicon($feed_url, $feed, $link);
+                       }
+
                        if (!$registered_title) {
                                $feed_title = db_escape_string($rss->channel["title"]);
                                db_query($link, "UPDATE ttrss_feeds SET 
                                                // check for user post link to main table
 
                                                // do we allow duplicate posts with same GUID in different feeds?
-                                               if (get_pref($link, "ALLOW_DUPLICATE_POSTS")) {
+                                               if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid)) {
                                                        $dupcheck_qpart = "AND feed_id = '$feed'";
                                                } else { 
                                                        $dupcheck_qpart = "";
 
                                        $post_needs_update = false;
 
-                                       if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE") &&
+                                       if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid) &&
                                                ($content_hash != $orig_content_hash)) {
                                                $post_needs_update = true;
                                        }