After upgrading D6 from an older version (in this case, 6.13 to 6.29), the Automatic alias toggle box on many nodes stopped working. I've tracked it down to the logic in path_set_alias of the path.module. Pathauto.inc is passing the correct source, alias and pid on line 503 of pathauto.inc

path_set_alias($path['source'], $path['alias'], $path['pid'], $path['language']);

However, the query on line 119 of path.module is not checking to see if the existing row that is found has the same alias being sent by pathauto.

$existing = db_fetch_array(db_query("SELECT pid, src FROM {url_alias} WHERE dst = '%s' AND language = '%s' ORDER BY pid DESC", $alias, $language));

In effect, this means that any new aliases that get created from the /admin/build/path interface interfere with pathauto's ability to set the alias, hence the bug.

In my opinion, if core is going to support multiple url aliases to a given path, then the logic should be there to confirm that the alias has changed. That could be something like changing line 120 to:

if (!$existing || $existing['dst'] != $alias || ($existing['pid'] == $pid && $existing['src'] != $path))

However, I'm not familiar enough with paths to know if that's the correct approach. Edit: Upon further reflection, this approach will not work b/c the pid that pathauto is attempting to update is the additional alias, not the one with the correct pathauto dst. I think additional actions will need to be taken within the switch statement that starts on line 474 to delete one of the duplicate aliases.

Thanks for any feedback you can offer.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

a-fro’s picture

I went to simplytest.me and was easily able to reproduce the issue with the following steps:

  1. Start with a clean install of Drupal 6.29
  2. Add pathauto and token and enable (along with path)
  3. Create a node and set the automatic alias
  4. Create a new alias to that same node with interface at /admin/build/path
  5. Edit the node, and try to re-set the automatic alias

We have path redirect enabled as well, which is saving the alias to the path_redirect table. But the original alias is not being updated due to the bug described above.

Thanks!

a-fro’s picture

Issue summary: View changes
a-fro’s picture

Since path.module is not handling aliases as expected, lines 492 and 493 of pathauto.inc no longer apply:

// Intentionally fall through to the next condition since we still
// want to replace the existing alias.

This patch manually deletes the offending alias so that a new one can be created, or, in the case of the bug described here, the alias that was added to the path_redirect gets deleted so that the original pathauto alias functions again.

a-fro’s picture

I'm including a small refactor that reorders switch and adds a new alias in case 2, since we're deleting the old one.

a-fro’s picture

Status: Active » Needs review

Status: Needs review » Needs work
Dave Reid’s picture

Priority: Critical » Normal