Monday, September 2, 2013

How To Easily Rebuild The Custom Field Cache On xenForo

How To Easily Rebuild The Custom Field Cache On xenForo. To build back cache is actually very easy to do, but for beginners who wear xenforo forum will usually be difficult. Therefore, I will share a tutorial how to build a cache back properly on the forum xenforo. Take the tour which I will share below correctly and appropriately.


All the custom fields for the users are stored in a couple of places.\

  • The first one is the database table xf_user_field_value in which it maintains a relation between the field_id and the user_id
  • The second one is a php serialized version of it, that is stored inside custom_fields in the xf_user_profile table
If you were to code an addon that writes to a custom field, you would need to keep updating both the table and the serialized version. Using a custom field might be a good idea since there are already hooks in the system for it, and should it need to be editable there is all the functionality already coded in for making it appear in Personal Information or Preferences.

This value is recalculated when the user edits his information and clicks on "save". Another way is when you go to the Maintenance tasks in the AdminCP and "Rebuild user information"

In some cases, you might not want to rebuild all user information as that would also do posts, and any other information associated to the user. If you wanted to only rebuild the custom fields, a simple PHP file with the following code will suffice.
RebuildCustomFields.php


<?php

$startTime = microtime(true);

require('./library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader('./library');

XenForo_Application::initialize('./library');
XenForo_Application::set('page_start_time', $startTime);
XenForo_Application::setDebugMode(true);

$db = XenForo_Application::getDb();
$userIds = $db->fetchCol("SELECT user_id FROM xf_user");

$model = new XenForo_Model_User();
foreach ($userIds as $id)
{
print "Rebuilding $id<br/>\r\n";
$model->rebuildCustomFieldCache($id);
}

How To Easily Rebuild The Custom Field Cache On xenForo


It is How To Easily Rebuild The Custom Field Cache On xenForo, good luck!

thumbnail Title: How To Easily Rebuild The Custom Field Cache On xenForo
Posted by:Stuard Van
Published :2013-09-02T10:00:00-07:00
Rating: 5
Reviewer: 5 Reviews
How To Easily Rebuild The Custom Field Cache On xenForo
Share :
Related articles:

1 comment :