diff --git a/common.php b/common.php index de6e7d0..5fc9893 100644 --- a/common.php +++ b/common.php @@ -9,12 +9,14 @@ require 'vendor/PicoDb/Table.php'; require 'schema.php'; require 'model.php'; + const DB_VERSION = 6; const APP_VERSION = 'master'; const APP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_TIMEOUT = 5; const LIMIT_ALL = -1; + function get_db_filename() { return 'data/db.sqlite'; @@ -27,12 +29,13 @@ PicoTools\container('db', function() { 'driver' => 'sqlite', 'filename' => get_db_filename() )); + if ($db->schema()->check(DB_VERSION)) { return $db; } else { + die('Unable to migrate database schema.'); } -}); - +}); \ No newline at end of file diff --git a/index.php b/index.php index 0e904a9..23259a8 100644 --- a/index.php +++ b/index.php @@ -94,6 +94,7 @@ Router\post_action('login', function() { Router\get_action('show', function() { + $id = Request\param('id'); Response\html(Template\layout('read_item', array( @@ -169,10 +170,8 @@ Router\post_action('change-item-status', function() { Router\get_action('history', function() { - // start auto purge if correctly set in preferences - Model\flush_read(); - - Response\html(Template\layout('history', array( + + Response\html(Template\layout('history', array( 'items' => Model\get_read_items(), 'menu' => 'history' ))); @@ -250,7 +249,7 @@ Router\get_action('confirm-flush-history', function() { Router\get_action('flush-history', function() { - Model\flush_read(); + Model\mark_as_removed(); Response\redirect('?action=history'); }); @@ -354,6 +353,7 @@ Router\get_action('config', function() { 'values' => Model\get_config(), 'db_size' => filesize(get_db_filename()), 'languages' => Model\get_languages(), + 'autoflush_options' => Model\get_autoflush_options(), 'menu' => 'config' ))); }); @@ -383,16 +383,17 @@ Router\post_action('config', function() { 'values' => $values, 'db_size' => filesize(get_db_filename()), 'languages' => Model\get_languages(), + 'autoflush_options' => Model\get_autoflush_options(), 'menu' => 'config' ))); }); Router\notfound(function() { - // start auto purge if correctly set in preferences - Model\flush_read(); - $items = Model\get_unread_items(); + Model\autoflush(); + + $items = Model\get_unread_items(); if (empty($items)) { @@ -403,4 +404,4 @@ Router\notfound(function() { 'items' => $items, 'menu' => 'unread' ))); -}); +}); \ No newline at end of file diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index c6807df..e87df66 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,10 @@ 'Supprimer automatiquement les éléments lus', + 'Never' => 'Jamais', + 'After %d day' => 'Après %d jour', + 'After %d days' => 'Après %d jours', 'French' => 'Français', 'English' => 'Anglais', 'unread' => 'non lus', @@ -14,7 +18,6 @@ return array( 'Password' => 'Mot de passe', 'Confirmation' => 'Confirmation', 'Language' => 'Langue', - 'History : number of days to store (-1 disable auto flush)' => 'Historique : nombre de jours à conserver (-1 désactive la purge auto)', 'Update' => 'Mettre à jour', 'More informations' => 'Plus d\'informations', 'Database' => 'Base de données', @@ -85,4 +88,4 @@ return array( 'Do you really want to remove this subscription: "%s"?' => 'Voulez-vous vraiment supprimer cet abonnement : "%s" ?', 'Nothing to read, do you want to update your subscriptions?' => 'Il n\'y a rien à lire, voulez-vous mettre à jour vos abonnements ?' -); +); \ No newline at end of file diff --git a/model.php b/model.php index cb2a129..7c374f3 100644 --- a/model.php +++ b/model.php @@ -30,6 +30,18 @@ function get_languages() } +function get_autoflush_options() +{ + return array( + '0' => t('Never'), + '1' => t('After %d day', 1), + '5' => t('After %d days', 5), + '15' => t('After %d days', 15), + '30' => t('After %d days', 30) + ); +} + + function export_feeds() { $opml = new Export(get_feeds()); @@ -258,7 +270,7 @@ function get_item($id) ->eq('id', $id) ->findOne(); } - + function get_nav_item($item) { @@ -356,33 +368,27 @@ function mark_as_read() } -function flush_unread() +function mark_as_removed() { \PicoTools\singleton('db') ->table('items') - ->eq('status', 'unread') + ->eq('status', 'read') ->save(array('status' => 'removed')); } -function flush_read() { +function autoflush() +{ + $autoflush = \PicoTools\singleton('db')->table('config')->findOneColumn('autoflush'); - $max_days = \PicoTools\singleton('db') - ->table('config') - ->columns('max_days') - ->findOne(); - $max_days=$max_days['max_days']; - - $max_age = 0; - if ($max_days != -1 ){ - $max_age = time()- ($max_days*86400); //86400 = 1 day - } + if ($autoflush) { - \PicoTools\singleton('db') - ->table('items') - ->eq('status', 'read') - ->lt('updated',$max_age) - ->save(array('status' => 'removed')); + \PicoTools\singleton('db') + ->table('items') + ->eq('status', 'read') + ->lt('updated', strtotime('-'.$autoflush.'day')) + ->save(array('status' => 'removed')); + } } @@ -438,7 +444,7 @@ function get_config() { return \PicoTools\singleton('db') ->table('config') - ->columns('username', 'language','max_days') + ->columns('username', 'language', 'autoflush') ->findOne(); } @@ -447,7 +453,7 @@ function get_user() { return \PicoTools\singleton('db') ->table('config') - ->columns('username', 'password', 'language','max_days') + ->columns('username', 'password', 'language') ->findOne(); } @@ -497,8 +503,7 @@ function validate_config_update(array $values) new Validators\MinLength('password', t('The minimum length is 6 characters'), 6), new Validators\Required('confirmation', t('The confirmation is required')), new Validators\Equals('password', 'confirmation', t('Passwords doesn\'t match')), - new Validators\Required('max_days', t('The number of days to keep read item is required')) - + new Validators\Required('autoflush', t('Value required')) )); } else { diff --git a/schema.php b/schema.php index 4ba1083..3ec5beb 100644 --- a/schema.php +++ b/schema.php @@ -2,9 +2,10 @@ namespace Schema; + function version_6($pdo) { - $pdo->exec('ALTER TABLE config ADD COLUMN max_days INTEGER DEFAULT -1'); + $pdo->exec('ALTER TABLE config ADD COLUMN autoflush INTEGER DEFAULT 0'); } @@ -71,4 +72,3 @@ function version_1($pdo) ) '); } - diff --git a/templates/config.php b/templates/config.php index 5699d69..bf4f710 100644 --- a/templates/config.php +++ b/templates/config.php @@ -16,8 +16,8 @@
- -
+ +