Improve autoflush of read items

This commit is contained in:
Frederic Guillot 2013-05-26 13:09:34 -04:00
parent 880b4517d0
commit 4346b27648
6 changed files with 52 additions and 40 deletions

View File

@ -9,12 +9,14 @@ require 'vendor/PicoDb/Table.php';
require 'schema.php'; require 'schema.php';
require 'model.php'; require 'model.php';
const DB_VERSION = 6; const DB_VERSION = 6;
const APP_VERSION = 'master'; const APP_VERSION = 'master';
const APP_USERAGENT = 'Miniflux - http://miniflux.net'; const APP_USERAGENT = 'Miniflux - http://miniflux.net';
const HTTP_TIMEOUT = 5; const HTTP_TIMEOUT = 5;
const LIMIT_ALL = -1; const LIMIT_ALL = -1;
function get_db_filename() function get_db_filename()
{ {
return 'data/db.sqlite'; return 'data/db.sqlite';
@ -27,12 +29,13 @@ PicoTools\container('db', function() {
'driver' => 'sqlite', 'driver' => 'sqlite',
'filename' => get_db_filename() 'filename' => get_db_filename()
)); ));
if ($db->schema()->check(DB_VERSION)) { if ($db->schema()->check(DB_VERSION)) {
return $db; return $db;
} }
else { else {
die('Unable to migrate database schema.'); die('Unable to migrate database schema.');
} }
}); });

View File

@ -94,6 +94,7 @@ Router\post_action('login', function() {
Router\get_action('show', function() { Router\get_action('show', function() {
$id = Request\param('id'); $id = Request\param('id');
Response\html(Template\layout('read_item', array( Response\html(Template\layout('read_item', array(
@ -169,8 +170,6 @@ Router\post_action('change-item-status', function() {
Router\get_action('history', 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(), 'items' => Model\get_read_items(),
@ -250,7 +249,7 @@ Router\get_action('confirm-flush-history', function() {
Router\get_action('flush-history', function() { Router\get_action('flush-history', function() {
Model\flush_read(); Model\mark_as_removed();
Response\redirect('?action=history'); Response\redirect('?action=history');
}); });
@ -354,6 +353,7 @@ Router\get_action('config', function() {
'values' => Model\get_config(), 'values' => Model\get_config(),
'db_size' => filesize(get_db_filename()), 'db_size' => filesize(get_db_filename()),
'languages' => Model\get_languages(), 'languages' => Model\get_languages(),
'autoflush_options' => Model\get_autoflush_options(),
'menu' => 'config' 'menu' => 'config'
))); )));
}); });
@ -383,14 +383,15 @@ Router\post_action('config', function() {
'values' => $values, 'values' => $values,
'db_size' => filesize(get_db_filename()), 'db_size' => filesize(get_db_filename()),
'languages' => Model\get_languages(), 'languages' => Model\get_languages(),
'autoflush_options' => Model\get_autoflush_options(),
'menu' => 'config' 'menu' => 'config'
))); )));
}); });
Router\notfound(function() { Router\notfound(function() {
// start auto purge if correctly set in preferences
Model\flush_read(); Model\autoflush();
$items = Model\get_unread_items(); $items = Model\get_unread_items();

View File

@ -1,6 +1,10 @@
<?php <?php
return array( return array(
'Remove automatically read items' => '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', 'French' => 'Français',
'English' => 'Anglais', 'English' => 'Anglais',
'unread' => 'non lus', 'unread' => 'non lus',
@ -14,7 +18,6 @@ return array(
'Password' => 'Mot de passe', 'Password' => 'Mot de passe',
'Confirmation' => 'Confirmation', 'Confirmation' => 'Confirmation',
'Language' => 'Langue', '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', 'Update' => 'Mettre à jour',
'More informations' => 'Plus d\'informations', 'More informations' => 'Plus d\'informations',
'Database' => 'Base de données', 'Database' => 'Base de données',

View File

@ -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() function export_feeds()
{ {
$opml = new Export(get_feeds()); $opml = new Export(get_feeds());
@ -356,34 +368,28 @@ function mark_as_read()
} }
function flush_unread() function mark_as_removed()
{ {
\PicoTools\singleton('db') \PicoTools\singleton('db')
->table('items') ->table('items')
->eq('status', 'unread') ->eq('status', 'read')
->save(array('status' => 'removed')); ->save(array('status' => 'removed'));
} }
function flush_read() { function autoflush()
{
$autoflush = \PicoTools\singleton('db')->table('config')->findOneColumn('autoflush');
$max_days = \PicoTools\singleton('db') if ($autoflush) {
->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') \PicoTools\singleton('db')
->table('items') ->table('items')
->eq('status', 'read') ->eq('status', 'read')
->lt('updated',$max_age) ->lt('updated', strtotime('-'.$autoflush.'day'))
->save(array('status' => 'removed')); ->save(array('status' => 'removed'));
} }
}
function update_items($feed_id, array $items) function update_items($feed_id, array $items)
@ -438,7 +444,7 @@ function get_config()
{ {
return \PicoTools\singleton('db') return \PicoTools\singleton('db')
->table('config') ->table('config')
->columns('username', 'language','max_days') ->columns('username', 'language', 'autoflush')
->findOne(); ->findOne();
} }
@ -447,7 +453,7 @@ function get_user()
{ {
return \PicoTools\singleton('db') return \PicoTools\singleton('db')
->table('config') ->table('config')
->columns('username', 'password', 'language','max_days') ->columns('username', 'password', 'language')
->findOne(); ->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\MinLength('password', t('The minimum length is 6 characters'), 6),
new Validators\Required('confirmation', t('The confirmation is required')), 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')) new Validators\Required('autoflush', t('Value required'))
)); ));
} }
else { else {

View File

@ -2,9 +2,10 @@
namespace Schema; namespace Schema;
function version_6($pdo) 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)
) )
'); ');
} }

View File

@ -16,8 +16,8 @@
<?= Helper\form_label(t('Language'), 'language') ?> <?= Helper\form_label(t('Language'), 'language') ?>
<?= Helper\form_select('language', $languages, $values, $errors) ?><br/> <?= Helper\form_select('language', $languages, $values, $errors) ?><br/>
<?= Helper\form_label(t('History : number of days to store (-1 disable auto flush)'), 'max_days') ?> <?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?>
<?= Helper\form_text('max_days', $values, $errors) ?><br/> <?= Helper\form_select('autoflush', $autoflush_options, $values, $errors) ?><br/>
<div class="form-actions"> <div class="form-actions">
<input type="submit" value="<?= t('Update') ?>" class="btn btn-blue"/> <input type="submit" value="<?= t('Update') ?>" class="btn btn-blue"/>