PathAuto creates a url alias that already exists in redirects. For example:
Create a piece of content with a title of Foo Bar. This generates a url alias of /foo-bar for node 1.
Next change the title of node 1 from Foo Bar to Foo Bar Renamed. Changes the url alias to /foo-bar-renamed and adds a redirect from /foo-bar to /foo-bar-renamed for node 1.
Next create a new piece of content with the title of Foo Bar again. This would be node 2. Upon saving, it creates a url alias of /foo-bar however, this then redirects to node 1 because the /foo-bar exists in the redirect table.
This has created havoc for some of our users because we have public advisories that are standardized and allows follow a similar pattern for publication.
Thanks,
Ron
Comment | File | Size | Author |
---|---|---|---|
#12 | pathauto-avoid-alias-that-is-redirected-2170259-12.patch | 667 bytes | torotil |
Comments
Comment #1
WVxNitemare CreditAttribution: WVxNitemare commentedI was looking at the code for the function _pathauto_alias_exists and after browsing some of the issues here already perhaps the fix would be:
I've never suggested a fix before so not sure exactly how to do it... but this seems to work.
Comment #2
serundeputy CreditAttribution: serundeputy commentedrolling patch into pathauto.module
check if there is a redirect.
Comment #4
serundeputy CreditAttribution: serundeputy commentedre-rolling patch failed simple test
Comment #5
serundeputy CreditAttribution: serundeputy commentedputting in 'Needs review' to run simple tests on re-roll.
Comment #6
serundeputy CreditAttribution: serundeputy commentedComment #7
trrroy CreditAttribution: trrroy commentedThis patch worked for me.
As a side note, it does only work on the Pathauto generated urls (which is correct for this particular issue/module). I was still having a problem if I unchecked 'Generate Auto url alias' then entered my own alias. If there was an existing redirect, it still created the alias which caused a bad redirect to another node. I applied the patch for the Redirect module from #242 on Fix and prevent circular redirects which solved that problem.
Comment #8
trrroy CreditAttribution: trrroy commentedAfter a little more testing I found that the if/else causes only the redirect to be checked. This prevents an existing alias from being checked. The attached patch removes the alias check from the 'else' clause.
Comment #9
serundeputy CreditAttribution: serundeputy commentedsetting to unassigned to indicate free for review
Comment #10
Leeteq CreditAttribution: Leeteq commentedThis must be (re-)checked with the just released 1.3 version of Pathauto plus the "new" RC3 release of Redirect which fixed #1796596: Fix and prevent circular redirects.
If this is still a problem, maybe this issue should be added to as a child issue to #2548927: Plan for Pathauto 7.x-1.4 release?
Comment #11
torotil CreditAttribution: torotil at more onion commentedThis is still a problem. The patch could be refined by:
hook_pathauto_is_alias_reserved()
implementation on behalf of the redirect module.Comment #12
torotil CreditAttribution: torotil at more onion commentedHere is a patch implementing my own suggestions.
Language neutral redirects are already taken care of as
redirect_load_by_source()
already loads language neutral redirects as well.Comment #13
jjtoyas CreditAttribution: jjtoyas at Agiledrop - Your Trusted Drupal Teammates commentedFor me, everything works as expected.
Comment #14
BerdirI don't maintain pathauto 7.x,. but FWIW, this behavior is basically by design.
Use case: You have node 1 with Alias A and node 2 with alias B. You want to change node 2 to alias A, so you first edit node 1, change it to C, then redirect creates a A => C redirect. Now you edit B and change it to A, then you want the redirect to be replaced with the new alias and not create A-0.
It's a hook, if you want to change that behavior then you implement that hook in your own module.
Comment #15
torotil CreditAttribution: torotil at more onion commented@Berdir: I had similar doubts when first came across this, but after analysing edge cases I’ve come to the conclusion that this is indeed a bug that warrants fixing. Take a look at the following example:
Comment #16
BerdirValid use case, as I said, I won't be committing any 7.x patches anyway, but for an 8.x issue, I would at least expect it to be configurable, the behavior on existing sites should not change. And I think pathauto should not implement hooks for redirect, either it should be added to redirect.module or pathauto should check for the redirect module being enabled elsewhere. If redirect ever adds such a hook then you get fatal errors.
Comment #17
torotil CreditAttribution: torotil at more onion commentedI guess other maintainers are having similar views on committing changes to 7.x. So the likelihood of the redirect module adding this hook is negligible.
Leaving this to someone else then. I don’t expect to become a D8+ developer anytime soon.