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

$usernameChangeUpdates

Jeremy P

Well-known member
#1
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?
 
R

ragtek

Guest
#2
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
 

Jaxel

Well-known member
#3
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');
}
 

Jeremy P

Well-known member
#6
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.
 

xf_phantom

Well-known member
#8
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)