diff --git a/.gitignore b/.gitignore index 9d8b304..f8a3104 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ update* make-archive.sh *.sqlite -*.db \ No newline at end of file diff --git a/README.markdown b/README.markdown index cd7de1f..00197f4 100644 --- a/README.markdown +++ b/README.markdown @@ -67,28 +67,27 @@ FAQ ### How to update your feeds with a cronjob? -You just need to be inside the directory `miniflux` and run the script `cronjob.php`. +You just need to be inside the directory `miniflux` and run the script `cronjob.php`. + +Parameters | Type | Value +--------------------|--------------------------------|----------------------------- +--limit | optional | time in minutes +--call-interval | optional, excluded by --limit, require --update-interval | time in minutes < update interval time +--update-interval | optional, excluded by --limit, require --call-interval | time in minutes >= call interval time -Prameters | Type | Value --------------------|--------------------------------|----------------------------- ---limit | optional |time in minutes ---call-interval | optional, exclude by --limit, requires --update-interval |time in minutes < update inteval time ---update-interval | optional, exclude by --limit, requires --call-interval |time in minutes >= call interval time - Examples: crontab -e + # Update all feeds 0 */4 * * * cd /path/to/miniflux && php cronjob.php >/dev/null 2>&1 - - # Updates the 10 oldest feeds each time + # Update the 10 oldest feeds each time 0 */4 * * * cd /path/to/miniflux && php cronjob.php --limit=10 >/dev/null 2>&1 - - # Updates all feeds in 60mn (updates the 8 oldest feeds each time with a total of 120 feeds). - 0 */4 * * * cd /path/to/miniflux && php cronjob.php --call-interval=4 --update-interval=60 >/dev/null 2>&1 + # Update all feeds in 60 minutes (updates the 8 oldest feeds each time with a total of 120 feeds). + * */4 * * * cd /path/to/miniflux && php cronjob.php --call-interval=4 --update-interval=60 >/dev/null 2>&1 ### How Miniflux update my feeds from the user interface? diff --git a/miniflux/common.php b/miniflux/common.php index e41803b..5bceb24 100644 --- a/miniflux/common.php +++ b/miniflux/common.php @@ -16,16 +16,19 @@ const APP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_TIMEOUT = 5; const LIMIT_ALL = -1; + function get_db_filename() { return 'data/db.sqlite'; } -function is_console() + +function is_console() { return php_sapi_name() === 'cli'; } + PicoTools\container('db', function() { $db = new PicoDb\Database(array( diff --git a/miniflux/cronjob.php b/miniflux/cronjob.php index b85920b..4e048fe 100644 --- a/miniflux/cronjob.php +++ b/miniflux/cronjob.php @@ -1,22 +1,24 @@ = $call_interval) { + if ($update_interval !== null && $call_interval !== null && $limit === LIMIT_ALL && $update_interval >= $call_interval) { $feeds_count = \PicoTools\singleton('db')->table('feeds')->count(); - $limit = ceil($feeds_count / ( $update_interval / $call_interval )) ; // compute new limit - } - + $limit = ceil($feeds_count / ($update_interval / $call_interval)); // compute new limit + } + Model\update_feeds($limit); } diff --git a/miniflux/model.php b/miniflux/model.php index 8365a2d..7aefc48 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -107,6 +107,7 @@ function import_feed($url) return false; } + function update_feeds($limit = LIMIT_ALL) { $feeds_id = get_feeds_id($limit); @@ -135,6 +136,7 @@ function update_feed($feed_id) APP_USERAGENT ); + // Update the `last_checked` column each time, HTTP cache or not update_feed_last_checked($feed_id); if (! $resource->isModified()) { @@ -166,13 +168,12 @@ function get_feeds_id($limit = LIMIT_ALL) $table_feeds = \PicoTools\singleton('db')->table('feeds') ->asc('last_checked'); - if($limit !== LIMIT_ALL) { + if ($limit !== LIMIT_ALL) { $table_feeds->limit((int)$limit); } return $table_feeds->listing('id', 'id'); - } @@ -193,15 +194,18 @@ function get_feed($feed_id) ->findOne(); } -function update_feed_last_checked($feed_id) { + +function update_feed_last_checked($feed_id) +{ \PicoTools\singleton('db') ->table('feeds') ->eq('id', $feed_id) ->save(array( - 'last_checked' => time(), + 'last_checked' => time() )); } + function update_feed_cache_infos($feed_id, $last_modified, $etag) { \PicoTools\singleton('db') @@ -209,8 +213,7 @@ function update_feed_cache_infos($feed_id, $last_modified, $etag) ->eq('id', $feed_id) ->save(array( 'last_modified' => $last_modified, - 'etag' => $etag, - 'last_checked' => time(), + 'etag' => $etag )); } diff --git a/miniflux/schema.php b/miniflux/schema.php index 9907b10..07797db 100644 --- a/miniflux/schema.php +++ b/miniflux/schema.php @@ -2,11 +2,13 @@ namespace Schema; + function version_5($pdo) { $pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER'); } + function version_4($pdo) { $pdo->exec("CREATE INDEX idx_status ON items(status)");