Allow producer to be executed only for a given user

This commit is contained in:
Frederic Guillot 2017-01-15 17:48:13 -05:00
parent 99225f53b3
commit 4ab9ca165c
2 changed files with 19 additions and 3 deletions

View File

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

View File

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