$usernameChangeUpdates

Jeremy P

XenForo developer
Staff member
How would I go about adding to the static $usernameChangeUpdates array in XenForo_DataWriter_User? I've tried a couple of different things and they all seem to throw errors. Is it possible?
 
Yes it is possible.

you just need to add your fields to the static variable in the user dw.

For example, my gallery is doing this:
PHP:
XenForo_DataWriter_User::$usernameChangeUpdates['permanent']['baz'] = array(
'ragtek_galleryimages', 'username', 'user_id');
at init_dependencies listener
 
So you basically did something like this:
Code:
<?php

class EWRmedio_Listener_Init
{
    public static function listen(XenForo_Dependencies_Abstract $dependencies, array $data)
    {
        XenForo_DataWriter_User::$usernameChangeUpdates['permanent']['ewrmedio_media_username']
            = array('EWRmedio_media', 'username', 'user_id');
        XenForo_DataWriter_User::$usernameChangeUpdates['permanent']['ewrmedio_comments_username']
            = array('EWRmedio_comments', 'username', 'user_id');
    }
}
My question is... why would you do this in init_dependencies? Wouldn't it be better to do it in an extended datawriter?
Code:
<?php

class EWRmedio_DataWriter_User extends XFCP_EWRmedio_DataWriter_User
{
    parent::$usernameChangeUpdates['permanent']['ewrmedio_media_username']
        = array('EWRmedio_media', 'username', 'user_id');
    parent::$usernameChangeUpdates['permanent']['ewrmedio_comments_username']
        = array('EWRmedio_comments', 'username', 'user_id');
}
 
I tried using an extended datawriter and couldn't get it to work. Have you had success with that code?
 
I've tried a lot of different things with extending that datawriter, had success with none but what ragtek suggested with init_dependencies a month ago. Not very compelled to go play with/change that again but if someone has success with it, I'm curious to know.
 
It doesn't work because it's a static variable and not a method.
 
In XenForo 1.2 this was moved from the User DW to the Usermodel.
PHP:
    /**
    * Updates existing content with a new username, or updated user ID
    *
    * @param integer $existingUserId
    * @param string $newUserName
    * @param string $oldUserName
    * @param integer $newUserId (set if the user ownership has changed)
    */
    public function changeContentUser($existingUserId, $newUserName = null, $oldUserName = null, $newUserId = null)
 
Top Bottom