I want to use the [mail] pattern in user path aliases. When I run a bulk update, the [mail] pattern is empty.

The Token module derives the user-related tokens from the $user object supplied by the user_pathauto_bulkupdate() function (pathauto_user.inc):

function user_pathauto_bulkupdate() {
  $query = "SELECT uid, name, src, dst FROM {users} LEFT JOIN {url_alias} ON CONCAT('user/', CAST(uid AS CHAR)) = src WHERE uid > 0 AND src IS NULL";
  $result = db_query_range($query, 0, variable_get('pathauto_max_bulk_update', 50));
...
  while ($user = db_fetch_object($result)) {
    $placeholders = pathauto_get_placeholders('user', $user);
...

The database query only request the uid and name of users, therefore the passed $user object lacks the other fields required by the Token module.

  $query = "SELECT * FROM {users} LEFT JOIN {url_alias} ON CONCAT('user/', CAST(uid AS CHAR)) = src WHERE uid > 0 AND src IS NULL";

If I change the query to this the [mail] pattern works (but I'm trying to suggest this is the solution, I'ld rather leave that to the experts).

Comments

dave reid’s picture

Issue tags: +bulk

Tagging all the bulk alias issues for #713238: RFC: Pathauto Bulk module.

dave reid’s picture

It's going to be much better that the full user account object is loaded.

dave reid’s picture

Title: User bulkupdate patterns empty » Run user_load on all the user objects in bulk updating
Assigned: Unassigned » dave reid
AlexisWilke’s picture

Issue tags: +E_ALL

Hi Dave,

Another note in that regard, I get something like 12 E_NOTICEs for each user loaded.

However, I think that the * is not going to work in PostgreSQL. You have two tables and only want to return user.* and url_alias.src/dst. There is one common field "language" and psql would balk at it.

Also, user_load() has this call: user_module_invoke('load', $array, $user); which when skipped... makes it where some things do not happen.

Finally, I do not see where the src & dst are used. But it looks like they are used somewhere (the $node object is handled the same way.) I would propose something like this:

  [...]
  $query = "SELECT uid, src, dst FROM {users} LEFT JOIN {url_alias} ON CONCAT(CONCAT('user/', CAST(uid AS CHAR)), '/track') = src WHERE uid > 0 AND src IS NULL";
  $result = db_query_range($query, 0, variable_get('pathauto_max_bulk_update', 50));

  $count = 0;
  $placeholders = array();
  while ($u = db_fetch_object($result)) {
    $user = user_load($u->uid);
    $user->src = $u->src;
    $user->dst = $u->dst;
    $placeholders = pathauto_get_placeholders('user', $user);
    $src = 'user/'. $user->uid .'/track';
    if (pathauto_create_alias('tracker', 'bulkupdate', $placeholders, $src, $user->uid)) {
      $count++;
    }
  }
  [...]

Thank you.
Alexis Wilke

dave reid’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

What I mean by loading the full user account is exactly like the code you detailed. Actually using the user_load() or user_load_multiple() in D7 and so we'd only need the {users}.uid column. :)

AlexisWilke’s picture

Dave,

Looking at the code being called from here, you MUST include the alias source and destination. It is being used and has to be defined in the object here ($user in this case, $node for nodes, etc.)

What sucks is that they two fields are just called "src" and "dst" which could very well be overwriting other important fields of the object (say you create a foo module, with a $foo object saved in a table using "src" and "dst" as fields of foo...)

Anyway, that code I posted works, I'm using it in my websites. 8-)

Thank you.
Alexis

dave reid’s picture

Status: Active » Closed (duplicate)