XF 1.1 Need a way to email all users with a specific value in custom user fields

Rob

Well-known member
Im pretty much geared up for a massive xF migration from vB on monday. I got almost all bases covered but I still need a way to email all users who have a specific value in one of the custom profile fields.

As of yet I have not found a solution or any way to hack this.

Does anyone have any idea how this might be possible?

Thanks,

Rob
 
You can send email by group, and you can setup a group promotion based on custom fields. But for your purposes you will need to force the promotion to process all users which means editing this file:

library/XenForo/CronEntry/UserGroupPromotion.php

Remove the red code to get rid of the last_activity restriction and match all users:

Rich (BB code):
		$users = $userModel->getUsers(array(
			'user_state' => 'valid',
			'is_banned' => 0,
			'last_activity' => array('>', XenForo_Application::$time - 86400 * 3)
		), array(
			'join' => XenForo_Model_User::FETCH_USER_FULL
		));

Then you can manually run the task to force immediate promotions:

Admin CP -> Tools -> Cron Entries -> User Group Promotions -> Controls: Run

But if you have a lot of users then you may hit some server limits trying to process all of them at once with this file modification.
 
  • Like
Reactions: Rob
Actually.... error log is saying there is a memory limit exceeded. Any idea how I can do this?

Can I modify the above function to process this in steps? Once processed once then it should be ok.
 
Like I said:

But if you have a lot of users then you may hit some server limits trying to process all of them at once with this file modification.

How many users do you have? You will need to increase the memory_limit to handle them all. There is no batch processing for that task. You can try disabling the limit by adding this line to the library/config.php file:

Code:
ini_set('memory_limit', -1);
 
I've taken your advice and the cron still isnt running.... I get this in server error log:-
[Wed Mar 28 14:07:13 2012] [error] [client 82.39.xxx.xxx]PHP Fatal error: fatal flex scanner internal error--end of buffer missed in /var/www/xxx/xxx/httpdocs/library/XenForo/CronEntry/UserGroupPromotion.php on line 32, referer:http://www.mydomain.com/admin.php?cron/
Followed by:
[Wed Mar 28 14:08:01 2012] [error] [client 82.39.xxx.xxx] PHP Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/xxx/xxx/httpdocs/library/XenForo/DataWriter.php on line 715, referer: http://www.mydomain.com/admin.php?cron/
 
I dont think I have the physical resources available to run this query against 30,000 users at once...

Is there any way I can split up the above query to work on a fraction of users at once?

I was thinking along the lines of:-
Code:
        $users = $userModel->getUsers(array(
            'user_state' => 'valid',
            'is_banned' => 0,
            'user_id' => array('>', 0),
            'user_id' => array('<', 5000),
        ), array(
            'join' => XenForo_Model_User::FETCH_USER_FULL
        ));

Ok, Im sure that syntax is wrong but you get the idea...
 
This will increase the timeout:

Code:
ini_set('max_execution_time', 5000);

Is there any way I can split up the above query to work on a fraction of users at once?

The model doesn't support that. You would have to edit the user model.

This whole idea is a workaround to begin with. If you continue to have problems then it may be easier to just customize the email form with an addon. But then you need a developer.
 
I have got the thing to complete with a silly timeout level. Now it's complete I have reverted that file back to defaults since it should now deal with new users correctly.

Quick question, the promotion is set up to add someone to the group if they tick a box (custom profile field)....
If they come along and untick the box will they then be demoted?

Thanks,

Rob
 
Top Bottom