Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.126.2.29
diff -u -p -r1.126.2.29 pathauto.module
--- pathauto.module	25 Jul 2010 05:16:12 -0000	1.126.2.29
+++ pathauto.module	27 Jul 2010 05:36:52 -0000
@@ -408,44 +408,46 @@ function pathauto_taxonomy($op, $type, $
 // User related functions.
 
 /**
- * Implements hook_user() for users, trackers, and blogs.
+ * Implements hook_user() for users and blogs.
  */
-function pathauto_user($op, &$edit, &$user, $category = FALSE) {
+function pathauto_user($op, &$edit, &$account, $category = FALSE) {
   switch ($op) {
     case 'insert':
-    case 'update':
-      _pathauto_include();
-      // Use the username to automatically create an alias
-      $pathauto_user = (object) array_merge((array) $user, $edit);
-      if ($user->name) {
-        $placeholders = pathauto_get_placeholders('user', $pathauto_user);
-        $src = 'user/'. $user->uid;
-        $alias = pathauto_create_alias('user', $op, $placeholders, $src, $user->uid);
-
-        if (module_exists('blog')) {
-          $new_user = drupal_clone($user);
-          if ($category == 'account') {
-            $new_user->roles = isset($edit['roles']) ? $edit['roles'] : array();
-            $new_user->roles[DRUPAL_AUTHENTICATED_RID] = t('authenticated user'); // Add this back
-          }
-          if (node_access('create', 'blog', $new_user)) {
-            $src = 'blog/'. $user->uid;
-            $alias = pathauto_create_alias('blog', $op, $placeholders, $src, $user->uid);
-          }
-          else {
-            pathauto_path_delete_all("blog/{$user->uid}");
+      // When hook_user('insert') is run, most of the account object has been
+      // saved into $account, except for $account->data and $account->roles.
+      // Since tokens may depend on the user's data or permissions, we need to
+      // ensure we have a 'full' user object.
+      $merged_account = drupal_clone($account);
+
+      // Merge in account data.
+      $merged_account->data = array();
+      $user_fields = user_fields();
+      foreach ($edit as $key => $value) {
+        if ((substr($key, 0, 4) !== 'auth') && ($key != 'roles') && (!in_array($key, $user_fields)) && ($value !== NULL)) {
+          $merged_account->data[$key] = $value;
+        }
+      }
+
+      // Merge in user roles.
+      if (isset($edit['roles']) && is_array($edit['roles'])) {
+        $roles = user_roles();
+        foreach (array_keys($edit['roles']) as $rid) {
+          if (!isset($merged_account->roles[$rid])) {
+            $merged_account->roles[$rid] = $roles[$rid];
           }
         }
       }
+
+      pathauto_user_update_alias($merged_account, 'insert');
+      break;
+    case 'after_update':
+      pathauto_user_update_alias($account, 'update');
       break;
     case 'delete':
       // If the user is deleted, remove the path aliases
-      $user = (object) $user;
-      pathauto_path_delete_all("user/{$user->uid}");
+      pathauto_path_delete_all("user/{$account->uid}");
       // They may have enabled these modules and/or feeds when the user was created, so let's try to delete all of them
-      pathauto_path_delete_all("blog/{$user->uid}");
-      break;
-    default:
+      pathauto_path_delete_all("blog/{$account->uid}");
       break;
   }
 }
@@ -483,7 +485,7 @@ function pathauto_user_update_alias($acc
       pathauto_create_alias('blog', $op, $placeholders, "blog/{$account->uid}", $account->uid);
     }
     else {
-      pathauto_path_delete_all("blog/{$user->uid}");
+      pathauto_path_delete_all("blog/{$account->uid}");
     }
   }
 }
