From 4ab9ca165c1a91d93f103c2953a0bf275ad3aeea Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 15 Jan 2017 17:48:13 -0500 Subject: [PATCH] Allow producer to be executed only for a given user --- app/models/user.php | 8 ++++++++ producer.php | 14 +++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/user.php b/app/models/user.php index 4ae10cf..5c0ee48 100644 --- a/app/models/user.php +++ b/app/models/user.php @@ -104,6 +104,14 @@ function get_all_users() ->findAll(); } +function get_all_user_ids() +{ + return Database::getInstance('db') + ->table(TABLE) + ->asc('id') + ->findAllByColumn('id'); +} + function get_user_by_id($user_id) { return Database::getInstance('db') diff --git a/producer.php b/producer.php index bdbc2e8..5cac34d 100644 --- a/producer.php +++ b/producer.php @@ -11,16 +11,24 @@ if (php_sapi_name() !== 'cli') { $options = getopt('', array( 'limit::', + 'user::', )); $limit = get_cli_option('limit', $options); +$user_id = get_cli_option('user', $options); $connection = new Pheanstalk(BEANSTALKD_HOST); -foreach (Model\User\get_all_users() as $user) { - foreach (Model\Feed\get_feed_ids_to_refresh($user['id'], $limit) as $feed_id) { +if ($user_id) { + $user_ids = array($user_id); +} else { + $user_ids = Model\User\get_all_user_ids(); +} + +foreach ($user_ids as $user_id) { + foreach (Model\Feed\get_feed_ids_to_refresh($user_id, $limit) as $feed_id) { $payload = serialize(array( 'feed_id' => $feed_id, - 'user_id' => $user['id'], + 'user_id' => $user_id, )); $connection