From 30ea882cc749dcf4a731c53c9efe122fe5aea090 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 22 May 2013 13:13:56 +0200 Subject: [PATCH] Minor code refactoring --- common.php | 6 ------ cronjob.php | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/common.php b/common.php index 5bceb24..d254843 100644 --- a/common.php +++ b/common.php @@ -23,12 +23,6 @@ function get_db_filename() } -function is_console() -{ - return php_sapi_name() === 'cli'; -} - - PicoTools\container('db', function() { $db = new PicoDb\Database(array( diff --git a/cronjob.php b/cronjob.php index f7346ee..b30183e 100644 --- a/cronjob.php +++ b/cronjob.php @@ -2,28 +2,27 @@ require 'common.php'; -if (is_console()) { +if (php_sapi_name() === 'cli') { $options = getopt('', array( 'limit::', 'call-interval::', 'update-interval::' )); - - $limit = empty($options['limit']) ? LIMIT_ALL : (int)$options['limit']; - $update_interval = empty($options['update-interval']) ? null : (int)$options['update-interval']; - $call_interval = empty($options['call-interval']) ? null : (int)$options['call-interval']; -} else { - - $limit = empty($_GET['limit']) ? LIMIT_ALL : (int)$_GET['limit']; - $update_interval = empty($_GET['update-interval']) ? null : (int)$_GET['update-interval']; - $call_interval = empty($_GET['call-interval']) ? null : (int)$_GET['call-interval']; } +else { + + $options = $_GET; +} + +$limit = ! empty($options['limit']) && ctype_digit($options['limit']) ? (int) $options['limit'] : LIMIT_ALL; +$update_interval = ! empty($options['update-interval']) && ctype_digit($options['update-interval']) ? (int) $options['update-interval'] : null; +$call_interval = ! empty($options['call-interval']) && ctype_digit($options['call-interval']) ? (int) $options['call-interval'] : null; 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)); } Model\update_feeds($limit);