From 07d0efe959e6ee03a7a4d2dca11a69e35a265461 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 15 Nov 2007 06:41:53 +0100 Subject: [PATCH] new preference: PURGE_UNREAD_ARTICLES (closes #161), fix bug in user purge --- functions.php | 40 +++++++++++++++++++++++++++++++++++ sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 4 +++- schema/ttrss_schema_pgsql.sql | 4 +++- schema/versions/mysql/26.sql | 3 +++ schema/versions/pgsql/26.sql | 3 +++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 schema/versions/mysql/26.sql create mode 100644 schema/versions/pgsql/26.sql diff --git a/functions.php b/functions.php index 744a728e..4a6613a6 100644 --- a/functions.php +++ b/functions.php @@ -81,8 +81,26 @@ 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 @@ -97,6 +115,7 @@ 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 { @@ -106,6 +125,7 @@ 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'"); } @@ -123,6 +143,7 @@ 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); @@ -185,6 +206,25 @@ } + 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"]; diff --git a/sanity_check.php b/sanity_check.php index bff12e38..4e99dc20 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -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 __("Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 24041bb8..cf29e012 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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), diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index c75e210f..af8f1c54 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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 index 00000000..d7593c5e --- /dev/null +++ b/schema/versions/mysql/26.sql @@ -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 index 00000000..d7593c5e --- /dev/null +++ b/schema/versions/pgsql/26.sql @@ -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; -- 2.39.5