When a taxonomy term alias is built (and deleted) it is done based on the assumption that the term path is taxonomy/term/123 (unless its a forum!).
The reality is that the term path should be determined using taxonomy_term_path.
Here are some patches...
This one patches the pathauto module so it correctly - if inefficiently - removes ALL term paths (+ feed paths).
Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.44.4.101
diff -u -p -r1.44.4.101 pathauto.module
--- pathauto.module 24 Jun 2008 16:04:11 -0000 1.44.4.101
+++ pathauto.module 29 Jul 2008 15:45:38 -0000
@@ -332,10 +332,23 @@ function pathauto_taxonomy($op, $type, $
case 'delete':
// If the category is deleted, remove the path aliases
$category = (object) $object;
- path_set_alias('taxonomy/term/'. $category->tid);
- path_set_alias(taxonomy_term_path($category));
- path_set_alias('forum/'. $category->tid);
- path_set_alias('taxonomy/term/'. $category->tid .'/0/feed');
+ $forum_vid = variable_get('forum_nav_vocabulary', '');
+ if ($forum_vid == $category->vid) {
+ path_set_alias('forum/'. $category->tid);
+ path_set_alias('taxonomy/term/'. $category->tid .'/0/feed');
+ }
+ else {
+ path_set_alias('taxonomy/term/'. $category->tid);
+ path_set_alias(taxonomy_term_path($category));
+ path_set_alias('taxonomy/term/'. $category->tid .'/0/feed');
+ path_set_alias(taxonomy_term_path($category) .'/0/feed');
+
+ $feedappend = variable_get('pathauto_'. $module .'_applytofeeds', '');
+ if (!empty($feedappend)) {
+ path_set_alias('taxonomy/term/'. $category->tid .'/'. $feedappend);
+ path_set_alias(taxonomy_term_path($category) .'/'. $feedappend);
+ }
+ }
break;
default:
break;
This patch fixes the feed alias path generation which assumes the feed should be generates using taxonomy/term/*/0/feed. Not ALWAYS the case - sometimes you may have that vocab controlled by a view.
Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.1.2.51
diff -u -p -r1.1.2.51 pathauto.inc
--- pathauto.inc 18 Jun 2008 20:05:08 -0000 1.1.2.51
+++ pathauto.inc 29 Jul 2008 15:45:38 -0000
@@ -321,8 +321,9 @@ function pathauto_create_alias($module,
// For forums and taxonomies, the src doesn't always form the base of the rss feed (ie. image galleries)
if ($module == 'taxonomy' || $module == 'forum') {
- $update_data = _pathauto_existing_alias_data("taxonomy/term/$entity_id/$feedappend");
- _pathauto_set_alias("taxonomy/term/$entity_id/$feedappend", "$alias/feed", $module, $entity_id, $update_data['pid'], $verbose, $update_data['old_alias']);
+ $src_path = ($module == 'forum') ? "taxonomy/term/$entity_id/$feedappend" : "$src/$feedappend";
+ $update_data = _pathauto_existing_alias_data($src_path);
+ _pathauto_set_alias($src_path, "$alias/feed", $module, $entity_id, $update_data['pid'], $verbose, $update_data['old_alias']);
}
else {
$update_data = _pathauto_existing_alias_data("$src/$feedappend");
The other issue to get this solves is patched in #278368: taxonomy_term_path being passed TID instead of Term Object. There is an issue where the term ID is passed (rather than the term object) to taxonomy_term_path.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 288639-pathauto-taxonomy-term-path-D6.patch | 2.73 KB | dave reid |
| #7 | pathauto-patch0.gif | 15.7 KB | dakku |
| #7 | pathauto-patch1.gif | 20.16 KB | dakku |
| #6 | pathauto1.gif | 7.66 KB | dakku |
| #6 | pathauto2.gif | 12.44 KB | dakku |
Comments
Comment #1
gregglesCould you attach the patches?
It would also be helpful to have some more generalized "how to test this patch" instructions. I understand the general concepts, but something like:
1. Enable forum
2. Create a forum term
3. Delete the forum term
Expected results: aliases for forum and forum feed are also deleted
Actual results: aliases are not deleted
Something like that would make it super easy to review/commit this.
Comment #2
nicholasthompsonSure I've attached it to this as a single patch for the two files.
How to test... good question!
Ok, on the site I was working one which exposed this issue I had changed a vocabs module to "my_module" (example) and then implemented
hook_term_pathin that module. This hook then returned a new source path for terms in that vocab, eg"example-term/" . $term->tid.This meant that any nodes tagged with a term in that vocab were linking through to (example) example-term/123.
There is another issue open where term source paths are broken due to a Term ID rather than a Term Object being passed to
taxonomy_term_path(#278368: taxonomy_term_path being passed TID instead of Term Object). This was an initial problem fixed by that issue. After that, pathauto tries to build the alias for the term feed.It assumed that my term's feed was on taxonomy/term/123/feed (I'd changd the
$feedappedin the module configuration from 0/feed to feed). This is incorrect behaviour - it should have used example-term/123/feed.The problem is, we cant simply "assume" that its the source path with the feed appended on the end because the forum module uses forum as a source term path, but it uses taxonomy/term as the term path for forum term feeds (if that makes sense).
This means we needed a clause to make sure this isn't a forum. MAYBE this patch (or a future fix) should have an option for the feed term path separately (or an option to force to taxonomy/term?)
Also - in terms of deleting... It is difficult to KNOW the term source path to clean up when a term is deleted. What if you changed your pathauto token templates of feedappend value after a bunch of aliases had been generated?
This patch changed the technique from a "try to delete everything" approach to a "try to delete everything with an ounce of configuration awareness" approach. It's still not perfect, but it will detect the users feedappend configuration and try to clean that up...
Comment #3
dakku commentedhaha, a year on and the same issue, I take it the issue was never quite dealth with... here is a problem I have:
I have implemented my own hook_term_path and define the src path as blog/term/tid. Pathauto works ok for normal term aliases BUT
all the feed aliases are generated as "taxonomy/term/tid/all/feed".. these should be "blog/term/tid/all/feed"
anyone?
Comment #4
greggles@dakku - did you try this patch.... ? If you did and can review it then it is more likely to get in than just laughing at the amount of time that has passed without a review.
Comment #5
dakku commentedHi Greggles,
Thanks for your reply, that patch was created by my colleague Nick Thompson and I beleive it is live on one of our production sites (http://www.pponline.co.uk). Based on that I am happy to assume it works. However, the site I am having problem with is in D6, so I cannot test it directly. However I can setup a D5 test install and let you know.
Its not a matter of laughing at the passage of time or lack of review, its simply the amount of time that must have been wasted (by not only me but others too) who are in the same boat in trying to debug and get to the root of the problem..
Thanks
Comment #6
dakku commentedok, i have done a test install using:
- Drupal 5.18
- Pathauto 5.x-2.x-dev
- Token 5.x-1.x-dev
Here are the steps I followed:
Created a very simple module called "myblog" that implemented hook_term_path
http://drupal.org/files/issues/pathauto1.gif
Created a vocab called "test"
updated vocab table
In the database I edited the vocab table and edited the "module" column for my vocan to "myblog"
Configured Pathauto for my vocab
http://drupal.org/files/issues/pathauto2.gif
created 2 terms in my "test" vocab called "term1" and "term2"
http://drupal.org/files/issues/pathauto4.gif
checked the url aliases
http://drupal.org/files/issues/pathauto3.gif
As you can see, the aliases for the terms worked fine BUT the terms aliases are not, the SRC is set as "taxonomy/term/tid/all/feed" instead of "myblog/term/tid/all/feed"
As far as the patch above is concerned, I am going to try it out, but I am not sure how it will play with the latest dev version of pathauto, will post back..
Comment #7
dakku commentedOk, I tried the patch from #2 http://drupal.org/node/288639#comment-944533 and here are the results:
1) Downloaded the patch and applied it (http://drupal.org/files/issues/pathauto-patch0.gif)
2) Wiped the old pathauto aliases
3) bulk created new aliases (http://drupal.org/files/issues/pathauto-patch1.gif)
If anyone else could confirm these results perhaps this patch can be commited into the latest dev branch?
(ps: sorry if this isnt the "right" way to review a patch, but you get the idea and proof I guess.)
Comment #8
dave reidSplit off some deleting handling into #861106: Simplify code for deleting an alias plus its base paths.
Revised patch that just makes sure to use taxonomy_term_path at all times. This will be addressed in D7 with #841804: entity_uri() should be used wherever possible.
Comment #10
dave reidComment #11
dave reidComment #12
dave reidtaxonomy_term_path() is now used whenever necessary and makes the latest patch obsolete.