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
| Comment | File | Size | Author |
|---|---|---|---|
| pathauto_clone_bug.patch | 664 bytes | rfay |
Comments
Comment #1
andypostThis is really very useful
Comment #2
gregglesGreat - committed to
6.x-2.x http://drupal.org/cvs?commit=267546
6.x-1.x http://drupal.org/cvs?commit=267548
5.x-2.x http://drupal.org/cvs?commit=267550
Thanks, rfay!