I'm trying to add a task to the existing "Rebuild User Caches" process.
My thinking, and current setup, is to extend the User DataWriter, and specifically the "rebuildCustomFields" method to invoke my DB update.
This is roughly what I am thinking, but I would welcome some thoughts - thank you.
As you see, the existing core method "rebuildCustomFields" is being extended.
My thinking, and current setup, is to extend the User DataWriter, and specifically the "rebuildCustomFields" method to invoke my DB update.
This is roughly what I am thinking, but I would welcome some thoughts - thank you.
As you see, the existing core method "rebuildCustomFields" is being extended.
PHP:
class LikesGiven_DataWriter_User extends XFCP_LikesGiven_DataWriter_User
{
public function rebuildCustomFields()
{
$response = parent::rebuildCustomFields();
$this->_getUserModel()->rebuildUserLikeGivenCache($this->get('user_id'));
return $response;
}
protected function _getUserModel()
{
return $this->getModelFromCache('XenForo_Model_User');
}
}
PHP:
class LikesGiven_Model_User extends XFCP_LikesGiven_Model_User
{
public function rebuildUserLikeGivenCache($userId)
{
$count = $this->_getLikeModel()->countLikesGivenByUser($userId);
$db = $this->_getDb();
$db->update('xf_user_like_given',
array('like_given_count' => $count),
'user_id = ' . $db->quote($userId)
);
}
}