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

Force updating a user's custom user field

Discussion in 'XenForo Development Discussions' started by Jake Hakoda Shirley, Jul 10, 2012.

  1. Jake Hakoda Shirley

    Jake Hakoda Shirley Active Member

    Hey guys, on the back end of things I am running a cron tab that syncs user's stats with a custom user field for easy display on the forum. My issue is that when I alter the values in the database, they aren't updated on the forum end until I 'edit' the user and save the newly loaded values in the Admin CP. Is there a cache that keeps all of the user field values, and if so, how can I automatically rebuild that.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yeah, it's cached in xf_user_profile.custom_fields. The cache can be rebuilt by running this:

    Admin CP -> Tools -> Rebuild Caches -> Rebuild User Caches

    This is the code if you want to create this in your cron:

    library/XenForo/CacheRebuilder/User.php
     
  3. Jake Hakoda Shirley

    Jake Hakoda Shirley Active Member

    Multiple times today you have helped me Jake. From one Jake to another, I humbly thank you for your contribution to the community.
     
  4. Jake Hakoda Shirley

    Jake Hakoda Shirley Active Member

    Hey Jake, my server host offers self-defined cron jobs, so that's what I have been using to do a lot of my automated server stuff. When I 'include' that PHP file, I am getting the following error:
    Code:
    Fatal error: Class 'XenForo_CacheRebuilder_Abstract' not found in /home/hungeradmin/hungercraft.net/library/XenForo/CacheRebuilder/User.php on line 8
    Do I need to run this script from within XenForo, or is there some what I can run it from an external script?
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yeah it's not gonna work like that. If your cron is a PHP script that initializes the XF application then you can use the classes and stuff. If you are manually manipulating the database (ie no datawriters) then refer to this function for code that you can use:

    XenForo_Model_UserField::getUserFieldValues

    This function simply queries the fields for the specified user_id and puts them into an array. The array that is returned by this function is then serialized, and that is what is written to xf_user_profile.custom_fields.
     
  6. Jake Hakoda Shirley

    Jake Hakoda Shirley Active Member

    While that is a useful function if I needed the info somewhere else, I am merely trying to manually update the user's custom user fields (xf_user_field_value table values) and have them display like they normally would. Is there a way I can integrate my external PHP script into an internal cron job that invokes the DataWriter->revuildCustomFields() function?

    Sorry, while I have worked a little bit with pages, I am completely new to this area of XenForo.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

Share This Page