XF 2.1 How to iterate over the entire user table?

I need to periodically iterate over the entire user table to do some auto-promoting (we twiddle the users group based on post count, days active, etc..). I was trying to do this by getting an array of user id's and then using the finder to pull up each one in sequence and then save it. It works fine if I don't have the same (of course it does little), but php exhausts memory if I have the save..

PHP:
$users = \XF::db()->fetchAll("SELECT user_id FROM xf_user WHERE 1 = 1");
foreach($users as $user_id) {
     $user = \XF::app()->find('XF:User', $user_id);

     // Do some stuff with $user here
     // ...
     // Now save modified user.
     $user->save();
}

I know I could just tweak the rows in the database directly, but it seemed this is what the Entity mechanism is for.
 
Yeah, but it's constrained by a lot more parameters due to the fact that some of the groups require compliance with the non-profit membership standards.

But the question is really independent of the motives.
 
I'd rather extend the available criteria system than add a second one that does the same job.

Anyway, if you want to follow your route, have a look at the cronjob & job of the usergroup promotion system, it has all you need. You just need to adjust the body of the jobs loop
 
Top Bottom