diff --git a/common.php b/common.php index d254843..de6e7d0 100644 --- a/common.php +++ b/common.php @@ -9,14 +9,12 @@ require 'vendor/PicoDb/Table.php'; require 'schema.php'; require 'model.php'; - -const DB_VERSION = 5; +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'; @@ -29,13 +27,12 @@ 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 23f2fa3..0e904a9 100644 --- a/index.php +++ b/index.php @@ -94,7 +94,6 @@ Router\post_action('login', function() { Router\get_action('show', function() { - $id = Request\param('id'); Response\html(Template\layout('read_item', array( @@ -170,8 +169,10 @@ Router\post_action('change-item-status', function() { Router\get_action('history', function() { - - Response\html(Template\layout('history', array( + // start auto purge if correctly set in preferences + Model\flush_read(); + + Response\html(Template\layout('history', array( 'items' => Model\get_read_items(), 'menu' => 'history' ))); @@ -388,8 +389,10 @@ Router\post_action('config', function() { Router\notfound(function() { + // start auto purge if correctly set in preferences + Model\flush_read(); - $items = Model\get_unread_items(); + $items = Model\get_unread_items(); if (empty($items)) { @@ -400,4 +403,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 c944a0d..3b6fc64 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -14,6 +14,7 @@ return array( 'Password' => 'Mot de passe', 'Confirmation' => 'Confirmation', 'Language' => 'Langue', + 'Number of days to keep (-1 disable auto flush)' => 'Nombre de jour à conserver (-1 désactive la purge auto)', 'Update' => 'Mettre à jour', 'More informations' => 'Plus d\'informations', 'Database' => 'Base de données', @@ -79,9 +80,9 @@ return array( 'The password is required' => 'Le mot de passe est obligatoire', 'The minimum length is 6 characters' => 'La longueur minimale est de 6 caractères', 'The confirmation is required' => 'La confirmation est obligatoire', - 'Passwords doesn\'t match' => 'Les mots de passe ne sont pas identique', + 'Passwords doesn\'t match' => 'Les mots de passe ne sont pas identiques', 'Do you really want to remove these items from your history?' => 'Voulez-vous vraiment supprimer les éléments de votre historique ?', '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 7aefc48..cb2a129 100644 --- a/model.php +++ b/model.php @@ -258,7 +258,7 @@ function get_item($id) ->eq('id', $id) ->findOne(); } - + function get_nav_item($item) { @@ -365,11 +365,23 @@ function flush_unread() } -function flush_read() -{ +function flush_read() { + + $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 + } + \PicoTools\singleton('db') ->table('items') ->eq('status', 'read') + ->lt('updated',$max_age) ->save(array('status' => 'removed')); } @@ -426,7 +438,7 @@ function get_config() { return \PicoTools\singleton('db') ->table('config') - ->columns('username', 'language') + ->columns('username', 'language','max_days') ->findOne(); } @@ -435,7 +447,7 @@ function get_user() { return \PicoTools\singleton('db') ->table('config') - ->columns('username', 'password', 'language') + ->columns('username', 'password', 'language','max_days') ->findOne(); } @@ -484,7 +496,9 @@ function validate_config_update(array $values) new Validators\Required('password', t('The password is required')), 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\Equals('password', 'confirmation', t('Passwords doesn\'t match')), + new Validators\Required('max_days', t('The number of days to keep read item is required')) + )); } else { diff --git a/schema.php b/schema.php index 07797db..4ba1083 100644 --- a/schema.php +++ b/schema.php @@ -2,6 +2,11 @@ namespace Schema; +function version_6($pdo) +{ + $pdo->exec('ALTER TABLE config ADD COLUMN max_days INTEGER DEFAULT -1'); +} + function version_5($pdo) { @@ -65,4 +70,5 @@ function version_1($pdo) FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE ) '); -} \ No newline at end of file +} + diff --git a/templates/config.php b/templates/config.php index 048da99..41b628b 100644 --- a/templates/config.php +++ b/templates/config.php @@ -16,6 +16,9 @@
+ +
+
@@ -51,4 +54,4 @@
  • http://miniflux.net
  • - \ No newline at end of file +