1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Questions and Support' started by Rob, Mar 25, 2012.

  1. Rob

    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
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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:

    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.
     
    Rob likes this.
  3. Rob

    Rob Well-Known Member

  4. Rob

    Rob Well-Known Member

    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.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Like I said:

    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);
    
     
  6. Rob

    Rob Well-Known Member

    I've taken your advice and the cron still isnt running.... I get this in server error log:-
    Followed by:
     
  7. Rob

    Rob Well-Known Member

    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...
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This will increase the timeout:

    Code:
    ini_set('max_execution_time', 5000);
    
    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.
     
  9. Rob

    Rob Well-Known Member

    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
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes. The task both promotes and demotes appropriately.
     
    Rob likes this.
  11. Rob

    Rob Well-Known Member

    Lovely! Im all set!
     

Share This Page