Ron Natalie
Member
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..
I know I could just tweak the rows in the database directly, but it seemed this is what the Entity mechanism is for.
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.