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

$usernameChangeUpdates

Discussion in 'XenForo Development Discussions' started by Jeremy P, Jul 9, 2011.

  1. Jeremy P

    Jeremy P Well-Known 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?
     
  2. ragtek

    ragtek Guest

    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
     
    Jeremy P likes this.
  3. Jaxel

    Jaxel Well-Known Member

    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');
    }
     
  4. Jeremy P

    Jeremy P Well-Known Member

    I tried using an extended datawriter and couldn't get it to work. Have you had success with that code?
     
  5. James

    James Well-Known Member

    That code should work, then use a listener to extend the XenForo_DataWriter_User.
     
  6. Jeremy P

    Jeremy P Well-Known Member

    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.
     
  7. ragtek

    ragtek Guest

    It doesn't work because it's a static variable and not a method.
     
  8. xf_phantom

    xf_phantom Well-Known Member

    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)
     
    Jeremy P likes this.

Share This Page