Improve autoflush of read items
This commit is contained in:
parent
880b4517d0
commit
4346b27648
@ -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.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
19
index.php
19
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'
|
||||
)));
|
||||
});
|
||||
});
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
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',
|
||||
'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 <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>'
|
||||
);
|
||||
);
|
51
model.php
51
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 {
|
||||
|
@ -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)
|
||||
)
|
||||
');
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
<?= Helper\form_label(t('Language'), 'language') ?>
|
||||
<?= 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_text('max_days', $values, $errors) ?><br/>
|
||||
<?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?>
|
||||
<?= Helper\form_select('autoflush', $autoflush_options, $values, $errors) ?><br/>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Update') ?>" class="btn btn-blue"/>
|
||||
|
Loading…
Reference in New Issue
Block a user