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

Newcomer Needs a Little Help with a Simple(?) Loop

Discussion in 'XenForo Development Discussions' started by Trigger, Jan 13, 2013.

  1. Trigger

    Trigger Member

    Hello,

    I'm pretty new to PHP, but I figured this shouldn't be too difficult; I'm having trouble working with XenForo's classes/setup, unable to really find what I need.

    In short, I run a Minecraft server which makes use of a handy little plugin called JSONAPI, which allows me to pass arguments to the server securely from any PHP script/application.

    I've been following the tutorials section here, borrowing any parts that seem relevant to making a simple add-on, but I've got myself pretty stuck in looping through users.

    Essentially I want to loop through all my forum users, checking:

    • That they have filled in their Minecraft username in the custom user field (id 'minecraft')
    • Their highest ranked user group (of which I have 5; Member, Donator, VIP, Staff, Admin)
    Donator / VIP ranks are paid upgrades, and I'd like the loop to put members of those groups into the same-name group on the Minecraft server, which would be run every 5 minutes as a CronEntry so that players who purchase these options almost immediately get their server account upgraded.

    This loop should also then revert players back to the Member group within 5 minutes of their forum upgrade expiring if based on highest rank.
    I got XF setup with Eclipse PDT today, but even then I've not been able to see what/where the options I might need are.

    If anyone can lend a hand, I'd be most appreciative. (Don't worry about the JSONAPI stuff, that much I know how to do, I have a non-cron standalone script that already upgrades guest players to a member)

    Thanks,

    Adam
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    A good example for looping through user accounts is the promotion cron:

    library/XenForo/CronEntry/UserGroupPromotion.php

    That script selects all users who have been active in the last 3 days then checks to see if they qualify for a new promotion.

    For the sake of immediacy you kind of need to process all users every time, as opposed to processing based on last_activity which can take up to an hour to update in the user record. Processing all users is a waste and has potential to exceed server limits, but only if you have several thousand users. If you have thousands of users and memory is a concern then you can refer to this updated version of that script that I posted (which helps with maximum memory usage):

    http://xenforo.com/community/thread...cron-running-out-of-memory.31541/#post-362657
     

Share This Page