If using [termpath] (or really any 'path-like' token) on node aliases those aliases does not get updated when a taxonomy term is updated. For example, imagine i've got the following taxonomy terms:

- Category
-- Subcategory

And my story pathauto setting looks like 'stories/[termpath-raw]/[title-raw]'. When i create or update an article called 'Article 1' and i add it to 'Subcategory' then the alias /stories/category/subcategory/article-1 is created. If i then edit the 'Subcategory' term and recall it 'Subcategory renamed' the alias gets not updated to /stories/category/subcategory-renamed/article-1 until the story gets updated again.

#14 810294-14.path_alias_update_queue.patch9.54 KBrszrama
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


greggles’s picture

Title: Node aliases using [termpath] broken when terms updated » Node aliases using [termpath] contain stale data after term is changed
Component: Tokens » Code

This is a known issue. Either I'm not imaginative enough or it's not reasonable to fix. So, I'm tempted to "won't fix" this but am leaving it open in case someone else has insight

klonos’s picture

Well, I don't have insight, but this is a really good feature request!

Usually terms do not get updated that much in most of my sites, but when/if they do this proves to be a major pain. I think that it should be handled by pathauto so definitely shouldn't be a 'won't fix'. Perhaps set to 'postponed'?

alroirm’s picture

I've been taking a look at the code and saw why you say "it's not reasonable to fix"...

However making pathauto export some actions like "update node aliases" would help some people to solve some of their particular problems with a trigger (newbie, just guessing).

greggles’s picture

Pathauto already provides such an action for nodes. It doesn't do so for terms or users but there are issues for that.

Dave Reid’s picture

Title: Node aliases using [termpath] contain stale data after term is changed » Update aliases for nodes associated with updated taxonomy terms
Version: 6.x-1.3 » 7.x-1.x-dev
Category: bug » feature

Better title for this feature request.

Dave Reid’s picture

Title: Update aliases for nodes associated with updated taxonomy terms » Add an 'URL alias update queue' for entities associated with an updated entity

I think what we'll have to do is add an 'entity URL alias update queue' in Pathauto. So let's say a taxonomy term is updated, we need to add all of its children into an update queue. At the end of the page request or on cron, we process a set number of items. We do the same thing when a term associated with 100 nodes is updated. We put those 100 nodes in the queue as well.

Dave Reid’s picture

So basics on how it would work:

When a taxonomy term is updated, fetch all the term IDs of its direct children and enqueue them in the URL alias update queue

function pathauto_taxonomy_term_update($term) {
  // Update alias ...

  if ($children = taxonomy_get_children($term->tid)) {
    $queue = DrupalQueue::get('pathauto_entity_update');
    foreach (array_keys($children) as $child_tid) {
      $item = array('entity_type' => 'taxonomy_term', 'id' => $child_tid);

  if ($nids = taxonomy_select_nodes($term->tid)) {
    $queue = DrupalQueue::get('pathauto_entity_update');
    foreach ($nids as $nid) {
      $item = array('entity_type' => 'node', 'id' => $nid);

function pathauto_cron() {
  $queue = DrupalQueue::get('pathauto_entity_update');
  for ($i = 0; $i < 25; $i++) {
    if ($item = $queue->claimItem()) {
      pathauto_entity_update_alias($item->data['entity_type'], $item->data['id']);
klonos’s picture

Good thinking Dave!

How would we detect terms that have been updated though? Perhaps this feature should be worked in pathauto and core taxonomy at the same time(?). Or is there a hook available already?

Dave Reid’s picture

hook_taxonomy_term_update() already exists in core and is implemented in pathauto.

greggles’s picture

This should have been here anyway:

(11:01:16 AM) greggles: yeah
(11:01:21 AM) greggles: I was thinking about that the other day
(11:01:25 AM) greggles: though it can be tricky
(11:02:01 AM) greggles: you have to potentially trace through the pattern for all objects, and whether or not the object just updated can impact the tokens for any other objects
(11:02:12 AM) greggles: with things like taxonomy, it's easy
(11:02:17 AM) greggles: node references? og? etc?
(11:02:20 AM) greggles: oooof
(11:03:04 AM) davereid: well we would start out with only supporting what core can do, which is just taxonomy children and entities associated with terms
(11:03:43 AM) davereid: If we just provide the queue to do it, other modules can do the work with figuring out what goes in it. :)

That works for me!

Dave Reid’s picture

The fun thing about this, is each level of taxonomy children will add their own children back into the queue as well. It propagates until *all* children are updated. Fun huh? :)

Dave Reid’s picture

Assigned: Unassigned » Dave Reid
klonos’s picture

Dave, I was going through #290421: pathauto patch to provide localized and entity translated taxonomy through i18n and some other issues (#736178: Add a [node:source] token for source node of a translated node for example), in order to re-test things with latest dev versions and patches just to see at what point some of my long-standing issues are solved or not... if solved at all. I was especially puzzled about this comment:

...changing the translation of the term doesn't update the i18n URL alias.

...here and I thought it might be relevant and I should bring it to your mind in case it already wasn't.

rszrama’s picture

Assigned: Dave Reid » Unassigned
Issue summary: View changes
Status: Active » Needs review
9.54 KB
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View

Alrighty, get ready for a big ol' patch to review.

This patch takes the approach you outlined above and expands on it. A summary of its functionality includes:

  1. Alters the info arrays of entity types whose alias update functions are managed by this module (node, taxonomy term, and user) to add a 'pathauto alias update callback' key.
  2. Adds an API function to determine an entity type's alias update callback. This allows Pathauto to concern itself solely with the update functions included in this module while allowing other modules to take care of their own.
  3. Adds a generic entity path alias update function that resolves the path update callback for a given entity type and entity ID then invokes it.
  4. Adds an API function to queue an update to a single entity's path alias.
  5. Defines the cron queue to process path alias updates during normal cron runs and adds the worker callback for it.
  6. Changes the behavior of taxonomy alias updates as outlined above, letting child updates navigate down the tree as each child term is updated; includes the enqueueing of related node updates.
  7. Nodes can also make use of user tokens in their paths, so we needed to update nodes authored by a given user on update as well; that's been added.
  8. Adds a variable for enabling / disabling the processing of the path alias update queue on cron and a related checkbox on the module's settings form.
  9. Adds a test that demonstrates the queue is working as expected on cron without and with queue processing enabled; it cascades through two sets of child terms to update their path aliases.

I did some user testing as well and happily watched child term updates process when their parent terms were updated and node updates process when their referenced terms or author user accounts were updated.

fwiw, this also makes my installation with 350k terms in a single vocabulary performant again when I update a term in that vocabulary. : )

Dave Reid’s picture

joseph.olstad’s picture

patch #14 needs reroll