From 4313909052bd947c391a239e6bf93c7ce80ea244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 15 Dec 2014 20:38:35 -0500 Subject: [PATCH] Add option to flush all unread items after X days, default 45 days (avoid very large database) --- controllers/config.php | 3 ++- controllers/item.php | 3 ++- cronjob.php | 3 ++- locales/cs_CZ/translations.php | 1 + locales/de_DE/translations.php | 1 + locales/es_ES/translations.php | 1 + locales/fr_FR/translations.php | 1 + locales/it_IT/translations.php | 1 + locales/pt_BR/translations.php | 1 + locales/zh_CN/translations.php | 1 + models/config.php | 20 +++++++++++++++++--- models/item.php | 19 ++++++++++++++++++- models/schema.php | 5 +++++ templates/config.php | 5 ++++- 14 files changed, 57 insertions(+), 8 deletions(-) diff --git a/controllers/config.php b/controllers/config.php index c80fef2..53e0b8f 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -119,7 +119,8 @@ Router\get_action('config', function() { 'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()), 'languages' => Model\Config\get_languages(), 'timezones' => Model\Config\get_timezones(), - 'autoflush_options' => Model\Config\get_autoflush_options(), + 'autoflush_read_options' => Model\Config\get_autoflush_read_options(), + 'autoflush_unread_options' => Model\Config\get_autoflush_unread_options(), 'paging_options' => Model\Config\get_paging_options(), 'theme_options' => Model\Config\get_themes(), 'sorting_options' => Model\Config\get_sorting_directions(), diff --git a/controllers/item.php b/controllers/item.php index 1ff286a..d15c217 100644 --- a/controllers/item.php +++ b/controllers/item.php @@ -9,7 +9,8 @@ use PicoFarad\Template; // Display unread items Router\get_action('unread', function() { - Model\Item\autoflush(); + Model\Item\autoflush_read(); + Model\Item\autoflush_unread(); $order = Request\param('order', 'updated'); $direction = Request\param('direction', Model\Config\get('items_sorting_direction')); diff --git a/cronjob.php b/cronjob.php index a7388f7..1ce3de9 100644 --- a/cronjob.php +++ b/cronjob.php @@ -31,5 +31,6 @@ if ($update_interval !== null && $call_interval !== null && $limit === Model\Fee } Model\Feed\refresh_all($limit); -Model\Item\autoflush(); +Model\Item\autoflush_read(); +Model\Item\autoflush_unread(); Model\Config\write_debug(); diff --git a/locales/cs_CZ/translations.php b/locales/cs_CZ/translations.php index f5b2c65..4ba395c 100644 --- a/locales/cs_CZ/translations.php +++ b/locales/cs_CZ/translations.php @@ -215,4 +215,5 @@ return array( // 'Default' => '', // 'Value required' => '', // 'Must be an integer' => '', + // 'Remove automatically unread items' => '', ); diff --git a/locales/de_DE/translations.php b/locales/de_DE/translations.php index f70e980..08d0431 100644 --- a/locales/de_DE/translations.php +++ b/locales/de_DE/translations.php @@ -215,4 +215,5 @@ return array( 'Default' => 'Standard', 'Value required' => 'Wert ist erforderlich', 'Must be an integer' => 'Muss eine Ganzzahl sein', + // 'Remove automatically unread items' => '', ); diff --git a/locales/es_ES/translations.php b/locales/es_ES/translations.php index 4810d07..d938d92 100644 --- a/locales/es_ES/translations.php +++ b/locales/es_ES/translations.php @@ -215,4 +215,5 @@ return array( // 'Default' => '', // 'Value required' => '', // 'Must be an integer' => '', + // 'Remove automatically unread items' => '', ); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 2d9f45b..d11165c 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -215,4 +215,5 @@ return array( 'Default' => 'Défaut', 'Value required' => 'Value required', 'Must be an integer' => 'Must be an integer', + 'Remove automatically unread items' => 'Supprimer automatiquement les éléments non lus', ); diff --git a/locales/it_IT/translations.php b/locales/it_IT/translations.php index f05c935..c1df5ba 100644 --- a/locales/it_IT/translations.php +++ b/locales/it_IT/translations.php @@ -215,4 +215,5 @@ return array( // 'Default' => '', // 'Value required' => '', // 'Must be an integer' => '', + // 'Remove automatically unread items' => '', ); diff --git a/locales/pt_BR/translations.php b/locales/pt_BR/translations.php index b82ca37..d1c4c33 100644 --- a/locales/pt_BR/translations.php +++ b/locales/pt_BR/translations.php @@ -215,4 +215,5 @@ return array( // 'Default' => '', // 'Value required' => '', // 'Must be an integer' => '', + // 'Remove automatically unread items' => '', ); diff --git a/locales/zh_CN/translations.php b/locales/zh_CN/translations.php index e013561..2e3206c 100644 --- a/locales/zh_CN/translations.php +++ b/locales/zh_CN/translations.php @@ -215,4 +215,5 @@ return array( // 'Default' => '', // 'Value required' => '', // 'Must be an integer' => '', + // 'Remove automatically unread items' => '', ); diff --git a/models/config.php b/models/config.php index c8504b1..ccd7781 100644 --- a/models/config.php +++ b/models/config.php @@ -9,7 +9,7 @@ use PicoDb\Database; use PicoFeed\Config as ReaderConfig; use PicoFeed\Logging; -const DB_VERSION = 29; +const DB_VERSION = 30; const HTTP_USER_AGENT = 'Miniflux (http://miniflux.net)'; // Get PicoFeed config @@ -121,8 +121,8 @@ function get_display_mode() ); } -// Autoflush choices for items -function get_autoflush_options() +// Autoflush choices for read items +function get_autoflush_read_options() { return array( '0' => t('Never'), @@ -134,6 +134,18 @@ function get_autoflush_options() ); } +// Autoflush choices for unread items +function get_autoflush_unread_options() +{ + return array( + '0' => t('Never'), + '15' => t('After %d days', 15), + '30' => t('After %d days', 30), + '45' => t('After %d days', 45), + '60' => t('After %d days', 60), + ); +} + // Number of items per pages function get_paging_options() { @@ -271,6 +283,7 @@ function get_all() 'language', 'timezone', 'autoflush', + 'autoflush_unread', 'nocontent', 'items_per_page', 'theme', @@ -293,6 +306,7 @@ function validate_modification(array $values) new Validators\Required('username', t('The user name is required')), new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50), new Validators\Required('autoflush', t('Value required')), + new Validators\Required('autoflush_unread', t('Value required')), new Validators\Required('items_per_page', t('Value required')), new Validators\Integer('items_per_page', t('Must be an integer')), new Validators\Required('theme', t('Value required')), diff --git a/models/item.php b/models/item.php index a1fd93b..191af4d 100644 --- a/models/item.php +++ b/models/item.php @@ -381,7 +381,7 @@ function mark_feed_as_read($feed_id) } // Mark all read items to removed after X days -function autoflush() +function autoflush_read() { $autoflush = (int) Config\get('autoflush'); @@ -406,6 +406,23 @@ function autoflush() } } +// Mark all unread items to removed after X days +function autoflush_unread() +{ + $autoflush = (int) Config\get('autoflush_unread'); + + if ($autoflush > 0) { + + // Mark read items removed after X days + Database::get('db') + ->table('items') + ->eq('bookmark', 0) + ->eq('status', 'unread') + ->lt('updated', strtotime('-'.$autoflush.'day')) + ->save(array('status' => 'removed', 'content' => '')); + } +} + // Update all items function update_all($feed_id, array $items, $enable_grabber = false) { diff --git a/models/schema.php b/models/schema.php index 9bf297d..6666db6 100644 --- a/models/schema.php +++ b/models/schema.php @@ -5,6 +5,11 @@ namespace Schema; use PDO; use Model\Config; +function version_30($pdo) +{ + $pdo->exec('ALTER TABLE config ADD COLUMN autoflush_unread INTEGER DEFAULT 45'); +} + function version_29($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN fever_token INTEGER DEFAULT "'.substr(Config\generate_token(), 0, 8).'"'); diff --git a/templates/config.php b/templates/config.php index 0326c17..732e3f4 100644 --- a/templates/config.php +++ b/templates/config.php @@ -28,7 +28,10 @@
-
+
+ + +