Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Alternate behavior for path redirect interaction:
When generating a new url alias, if the exact alias exists in path_redirect (alias and src), instead of generated a new url alias with '-0' at the end, the url is deleted from path_redirect table.
Comment | File | Size | Author |
---|---|---|---|
#9 | 261615_pathauto_9_redirect_delete.patch | 1.1 KB | greggles |
#8 | redirect_delete-261615-8.d6.patch | 1.64 KB | Freso |
redirect_delete.patch | 1010 bytes | aufumy | |
Comments
Comment #1
aufumy CreditAttribution: aufumy commentedchanging status to patch (code needs review)
Comment #2
gregglesCan you describe some steps to reproduce the problem to test this patch?
Comment #3
aufumy CreditAttribution: aufumy commentedHi Greggles
1. Enable pathauto and path_redirect modules. Notice that the default pattern for nodes is '[title-raw]' in "/admin/settings/pathauto"
2. Create a story "/node/add/story" , e.g. title = 'My Nodes', url is automatically generated in url_alias table
3. Add a url redirect "/admin/build/path-redirect/add", to make sure an old url of an html page works and points to the story created.
From: docs/my-nodes.html
To: node/1
Now there are 2 urls pointing to 'node/1' : 'my-nodes' and 'docs/my-nodes.html'
4. Decision is made to regenerate pathauto following as closely as possible the old url pattern
5. However, in the case when the pathauto/token generated url would exactly match, when pathauto runs, if there was no entry in the url redirect table for the story it would normally create the url alias "docs/my-nodes.html", however since there is a matching entry it creates "docs/my-nodes.html-0". So now there are 2 urls which point to the story.
I suggest instead when pathauto runs, if it finds exactly the same matching url pointing to the same node, it deletes it from path redirect, and adds the one url as "docs/my-nodes.html"
Therefore when the primary url desired for 'node/1' is exactly the same as an existing url in path_redirect, instead of changing the primary url, by adding '-0', the secondary urls are removed from path_redirect.
Thanks
Audrey
Comment #4
gregglesAudrey - thanks for the detailed steps to repeat the bug and for the patch. A slightly easier way (and perhaps more common case) is:
1. Create a node with the title "my title" when your pathauto setting is [title-raw]
2. Edit the node and change the title to "my title 2"
3. Edit the node and change the title back to "my title"
The problem manifests itself under this simplified scenario as well ;)
In my opinion, this appears ready to go. I'd like to see if Freso has any feeling on it.
One weakness I found is that if there is an existing feed alias then that isn't handled quite properly but I think that is a problem with the way that Pathauto makes assumptions about feed aliases and not really with this specific bug.
Comment #5
Freso CreditAttribution: Freso commentedMy first impression (from just reading the patch) was that this ought to be fixed by path_redirect, but after actually reading the comments, I agree. At least with the scenario in #3. I think the test case provided in #4 should be handled properly by path_redirect... but then I realised we're injecting the redirect directly into the database. Doesn't path_redirect have a function that'll do this? If not, I'd say we should go and file a feature request! :)
To summarise:
The patch looks good as a temporary fix for 5.x-2.x/6.x-1.x. For 6.x-2.x, we should work towards using a function in path_redirect. (Now I'm side tracking again, but with the API function we could use
function_exists
instead ofdb_table_exists
- thus saving a hit to the db, no? =))Comment #6
Freso CreditAttribution: Freso commentedActually, after posting this, I realised it's a
SELECT
there, and noINSERT
ing orUPDATE
'ing is going on, so I'm not sure theDELETE
is in the proper place... ? Where do we set up the path_redirect? I know I'm making the issue a bit more complicated now, but perhapsdb_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s'", $alias, 0, 1)
should becomedb_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s' AND redirect = '%s'", $alias, $src, 0, 1)
instead (I'm not familiar withdb_query_range()
syntax, so that may not be fully kosher), and have the deletion happen at the insertion point?Comment #7
Freso CreditAttribution: Freso commentedEh.
db_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s'", $alias, 0, 1)
should becomedb_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s' AND redirect <> '%s'", $alias, $src, 0, 1)
, not what I wrote in the previous comment.Comment #8
Freso CreditAttribution: Freso commentedAnd here's my idea in a basic patch form. I'm not sure about which variables to pass to the SQL (of
$old_alias
,$dest
,$src
), and I'm not sure of exactly where the deletion should happen. Let alone, whether placing it here makes other things go wonky... (This issue should be added to the list of functionality test cases!)I do think the best solution to this whole ordeal is for
path_redirect_save()
to handle this, but I also realise this can't be expected to happen in time for 5.x-2.3/6.x-1.1.Comment #9
gregglesAfter discussion offline, Freso and I agree that this is a problem for Pathauto to clean up. He also encouraged me to use the real API instead of just a db query.
The attached patch makes the assumption that if path_redirect_save exists then the path_redirect database table exists. That seems like a reasonable assumption to me.
Comment #10
greggles..and...
@aufumy - can you test this patch and see if it works for you?
Comment #11
Freso CreditAttribution: Freso commentedPatch looks good and works as expected (tested on 6.x-1.x). RTBC.
Comment #12
gregglesThanks Freso and aufumy - this is now fixed in both 6.x and 5.x.
Woohoo - one step closer on http://groups.drupal.org/node/11551 :)
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.