Add an auto flush function while reaching action=default or action=history.

It will flush all read items older than the specified number of days in
the preferences

1 correction in the translation file fr_FR
This commit is contained in:
MonsieurPaulLeBoulanger 2013-05-23 13:44:45 +02:00
parent 9b6dfeca4e
commit f03c543ded
6 changed files with 45 additions and 21 deletions

View File

@ -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.');
}
});
});

View File

@ -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'
)));
});
});

View File

@ -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 <a href="?action=refresh-all" data-action="refresh-all">update your subscriptions?</a>' =>
'Il n\'y a rien à lire, voulez-vous <a href="?action=refresh-all" data-action="refresh-all">mettre à jour vos abonnements ?</a>'
);
);

View File

@ -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 {

View File

@ -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
)
');
}
}

View File

@ -16,6 +16,9 @@
<?= Helper\form_label(t('Language'), 'language') ?>
<?= Helper\form_select('language', $languages, $values, $errors) ?><br/>
<?= Helper\form_label(t('Number of days to keep (-1 disable auto flush)'), 'max_days') ?>
<?= Helper\form_text('max_days', $values, $errors) ?><br/>
<div class="form-actions">
<input type="submit" value="<?= t('Update') ?>" class="btn btn-blue"/>
</div>
@ -51,4 +54,4 @@
<li><?= t('Official website:') ?> <a href="http://miniflux.net" target="_blank">http://miniflux.net</a></li>
</ul>
</div>
</section>
</section>