The attached patch fixes a bug where pathauto is trying to work with a copy of the passed-in $user object, but is in PHP5 actually working with the original object, since object assignment is by reference in PHP5.

How to recreate: This was demonstrated in the context of a call to guestbook_page():

  // Set last visited time for own guestbook
  if ($account->uid > 0 && $account->uid == $user->uid) {
    user_save($user, array('guestbook_visited' => time()));
  }

Note that only the guestbook_visited array element is set.

When pathauto_user gets called with $op == 'update', in its processing, it does

if (module_exists('blog')) {
          $new_user = $user;
          if ($category == 'account') {
            $new_user->roles = isset($edit['roles']) ? $edit['roles'] : array();
            $new_user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; // Add this back
          }

Since objects are assigned by reference in PHP5, the resetting of $new_user->roles actually applies to the passed in $user, destroying the roles of the passed-in $user.

Expected behavior: Non-destructive handling of the passed-in $user.

Actual behavior: Roles of passed-in $user destroyed

CommentFileSizeAuthor
pathauto_clone_bug.patch664 bytesrfay

Comments

andypost’s picture

Status: Needs review » Reviewed & tested by the community

This is really very useful

greggles’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.