]> git.wh0rd.org Git - tt-rss.git/commitdiff
globalPurge rpc call
authorAndrew Dolgov <fox@bah.spb.su>
Fri, 18 Nov 2005 12:21:16 +0000 (13:21 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Fri, 18 Nov 2005 12:21:16 +0000 (13:21 +0100)
backend.php
functions.php

index f7318ff4728c67e5eadaf0f3055a4a8b6195313e..a2f6a0da7360626eb3dfaad197ec8145b679e663 100644 (file)
 
                        print "<error code='$error_code'/>";
                }
+
+               if ($subop == "globalPurge") {
+
+                       print "<rpc-reply>";
+                       global_purge_old_posts($link, true);
+                       print "</rpc-reply>";
+
+               }
+
        }
        
        if ($op == "feeds") {
 
        }
 
-
        db_close($link);
 ?>
 
index 730b1fedd73b144c51901ca118cf22e10ec2f1de..355226e8d09235de283a4eb0511aa65b05d19946 100644 (file)
@@ -9,6 +9,52 @@
 
        define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
 
+       function purge_feed($link, $feed_id, $purge_interval) {
+       
+               if (DB_TYPE == "pgsql") {
+                       db_query($link, "DELETE FROM ttrss_entries WHERE
+                               marked = false AND feed_id = '$feed_id' AND
+                               date_entered < NOW() - INTERVAL '$purge_interval days'");
+               } else {
+                       db_query($link, "DELETE FROM ttrss_entries WHERE
+                               marked = false AND feed_id = '$feed_id' AND
+                               date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
+               }
+       }
+
+       function global_purge_old_posts($link, $do_output = false) {
+
+               $result = db_query($link, 
+                       "SELECT id,purge_interval,owner_uid FROM ttrss_feeds");
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $feed_id = $line["id"];
+                       $purge_interval = $line["purge_interval"];
+                       $owner_uid = $line["owner_uid"];
+
+                       if ($purge_interval == 0) {
+                       
+                               $tmp_result = db_query($link, 
+                                       "SELECT value FROM ttrss_user_prefs WHERE
+                                               pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'");
+
+                               if (db_num_rows($tmp_result) != 0) {                    
+                                       $purge_interval = db_fetch_result($tmp_result, 0, "value");
+                               }
+                       }
+
+                       if ($do_output) {
+                               print "<feed id='$feed_id' p_intl='$purge_interval'/>";
+                       }
+
+                       if ($purge_interval > 0) {
+                               purge_feed($link, $feed_id, $purge_interval);
+                       }
+               }       
+
+       }
+
        function purge_old_posts($link) {
 
                $user_id = $_SESSION["uid"];
                        if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS');
 
                        if ($purge_interval > 0) {
-
-                               if (DB_TYPE == "pgsql") {
-                                       db_query($link, "DELETE FROM ttrss_entries WHERE
-                                               marked = false AND feed_id = '$feed_id' AND
-                                               date_entered < NOW() - INTERVAL '$purge_interval days'");
-                               } else {
-                                       db_query($link, "DELETE FROM ttrss_entries WHERE
-                                               marked = false AND feed_id = '$feed_id' AND
-                                               date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
-                               }
+                               purge_feed($link, $feed_id, $purge_interval);
                        }
                }       
        }