]> git.wh0rd.org Git - tt-rss.git/commitdiff
new preference: PURGE_UNREAD_ARTICLES (closes #161), fix bug in user purge
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 15 Nov 2007 05:41:53 +0000 (06:41 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 15 Nov 2007 05:41:53 +0000 (06:41 +0100)
functions.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/26.sql [new file with mode: 0644]
schema/versions/pgsql/26.sql [new file with mode: 0644]

index 744a728ecf2d36c3d9ab84852f2f64b43b81170c..4a6613a60dd29559b71811d7951ddc5d80860fa3 100644 (file)
 
        function purge_feed($link, $feed_id, $purge_interval, $debug = false) {
 
+               if (!$purge_interval) $purge_interval = feed_purge_interval($link, $feed_id);
+
                $rows = -1;
 
+               $result = db_query($link, 
+                       "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'");
+
+               $owner_uid = false;
+
+               if (db_num_rows($result) == 1) {
+                       $owner_uid = db_fetch_result($result, 0, "owner_uid");
+               }
+
+               if (!$owner_uid) return;
+
+               $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES",
+                       $owner_uid, false);
+
+               if (!$purge_unread) $query_limit = " unread = false AND ";
+
                if (DB_TYPE == "pgsql") {
 /*                     $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
                                marked = false AND feed_id = '$feed_id' AND
                                        ttrss_entries.id = ref_id AND 
                                        marked = false AND 
                                        feed_id = '$feed_id' AND 
+                                       $query_limit
                                        ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
 
                        } else {
                                        WHERE ttrss_entries.id = ref_id AND 
                                        marked = false AND 
                                        feed_id = '$feed_id' AND 
+                                       $query_limit
                                        ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
                        }
 
                                WHERE ttrss_entries.id = ref_id AND 
                                marked = false AND 
                                feed_id = '$feed_id' AND 
+                               $query_limit
                                ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
                                        
                        $rows = mysql_affected_rows($link);
 
        }
 
+       function feed_purge_interval($link, $feed_id) {
+
+               $result = db_query($link, "SELECT purge_interval, owner_uid FROM ttrss_feeds 
+                       WHERE id = '$feed_id'");
+
+               if (db_num_rows($result) == 1) {
+                       $purge_interval = db_fetch_result($result, 0, "purge_interval");
+                       $owner_uid = db_fetch_result($result, 0, "owner_uid");
+
+                       if ($purge_interval == 0) $purge_interval = get_pref($link, 
+                               'PURGE_OLD_DAYS', $user_id);
+
+                       return $purge_interval;
+
+               } else {
+                       return -1;
+               }
+       }
+
        function purge_old_posts($link) {
 
                $user_id = $_SESSION["uid"];
index bff12e38ccc7cd45ab8524aab9d433fae8f5f241..4e99dc20aa87bf4d12db6f2d8250620781d984ac 100644 (file)
@@ -2,7 +2,7 @@
        require_once "functions.php";
 
        define('EXPECTED_CONFIG_VERSION', 11);
-       define('SCHEMA_VERSION', 25);
+       define('SCHEMA_VERSION', 26);
 
        if (!file_exists("config.php")) {
                print __("<b>Fatal Error</b>: You forgot to copy 
index 24041bb88e96574e934c398f618da366061f4f14..cf29e01211ea8e1219bd64a16b40c30bfccc5908 100644 (file)
@@ -200,7 +200,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) TYPE=InnoDB;
 
-insert into ttrss_version values (25);
+insert into ttrss_version values (26);
 
 create table ttrss_prefs_types (id integer not null primary key, 
        type_name varchar(100) not null) TYPE=InnoDB;
@@ -304,6 +304,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('CDM_EXPANDED', 1, 'true', 'Automatically expand articles in combined mode',3);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('PURGE_UNREAD_ARTICLES', 1, 'true', 'Purge unread articles',3);
+
 create table ttrss_user_prefs (
    owner_uid integer not null,
    pref_name varchar(250),
index c75e210f16f043dfe7d3cc33365207a3d3091bbb..af8f1c54f247a215623c2ebfbebadfc7461e4467 100644 (file)
@@ -179,7 +179,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (25);
+insert into ttrss_version values (26);
 
 create table ttrss_prefs_types (id integer not null primary key, 
        type_name varchar(100) not null);
@@ -279,6 +279,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('CDM_EXPANDED', 1, 'true', 'Automatically expand articles in combined mode',3);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('PURGE_UNREAD_ARTICLES', 1, 'true', 'Purge unread articles',3);
+
 create table ttrss_user_prefs (
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
        pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
diff --git a/schema/versions/mysql/26.sql b/schema/versions/mysql/26.sql
new file mode 100644 (file)
index 0000000..d7593c5
--- /dev/null
@@ -0,0 +1,3 @@
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('PURGE_UNREAD_ARTICLES', 1, 'true', 'Purge unread articles',3);
+
+update ttrss_version set schema_version = 26;
diff --git a/schema/versions/pgsql/26.sql b/schema/versions/pgsql/26.sql
new file mode 100644 (file)
index 0000000..d7593c5
--- /dev/null
@@ -0,0 +1,3 @@
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('PURGE_UNREAD_ARTICLES', 1, 'true', 'Purge unread articles',3);
+
+update ttrss_version set schema_version = 26;