Hi,

Not sure if this is a Pathauto, or Workbench Moderation issue (or if it's core's Path module as http://drupal.org/node/748886 suggests) so please correct me if I'm wrong posting here.

Basically, I have a content type which is set to Create a new revision on save, it does not get automatically published, and this uses Workbench Moderation to provide a workflow for the content.

My issue is this:
1) Edit a published node, that already has "Generate automatic URL alias" ticked
2) Untick the automatic alias box, and enter a custom alias.
3) Save the revision as draft
4) Edit the node again

The custom alias has disappeared and when I either publish the draft, or go back to editing it the "Generate automatic URL alias" box is ticked again and my custom alias is gone.

There's also a sort of opposite issue as well:
1) Create node with custom alias and save + publish
2) Edit node and tick Generate automatic URL alias, and save as draft
3) Custom alias now disappears and live page now uses automatically generated alias before the revision is even published.

This just seems like a wider issue with path aliasing and revisions, the Pathauto Persist module was mentioned in the other issue, but that doesn't even take into account vids so I can't see that making anything any better.

Any help would be greatly appreciated!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ayrmax’s picture

Hi.
I have the same issue in combination with workbench. I spend some time to figure out why and where it happens.

The workbench module registers the shutdown function workbench_moderation_store() via drupal_register_shutdown_function() this workbench function is loading the uncached node from the database and performs a node_save() on it. This uncached node doesn't have the $node->path['pathauto'] flag which seems to indicate if there should be generated a path with the pattern or if the user has entered his own path.

You can fix the problem in two ways:

1. In the Workbench module in the function workbench_moderation_store() add the line:
$live_revision->path['pathauto'] = 0;
before the
node_save($live_revision);.

2. The other way (i think there is the problem) is in the Pathauto module:
In the function pathauto_node_update_alias() change the line:
if (isset($node->path['pathauto']) && empty($node->path['pathauto'])) {
to
if ((isset($node->path['pathauto']) && empty($node->path['pathauto'])) || !isset($node->path['pathauto'])) {

Both ways fixed the problem for me, but the second fix may have some other side effects like mayb e it stops the bulk operation for updating the path alias from within the content overview from working. Havn't tested this.

Ayrmax’s picture

I think this is the real issue:
http://drupal.org/node/936222

acbramley’s picture

Hey @Ayrmax thanks for replying, looks like that would solve our issue. I will link this there, but I think we should leave this open for now

joel_osc’s picture

Just an FYI that there is a similar problem with pathauto, workbench and entity translation #1969226: Enabling moderation on an entity translated node can result in incorrect urls which is also fixed by #1 - thanks @Ayrmax.

acbramley’s picture

This patch does fix the problem where the custom alias disappears upon saving the draft, but this introduces another bug where the new custom alias is used for the published version of the node before the draft revision has been published.

matthewgann’s picture

http://drupal.org/node/936222

#108 seems to fix this for me.

jp.stacey’s picture

#936222: Merge in pathauto_persist module functionality to prevent losing manual aliases with node_save() calls is really solving a different issue: with revisions in use, the automatic alias, once generated, is "sticky" and won't update.

@Ayrmax's suggestion in comment #1 worked for us, so please find it attached in patch form, for convenience.

Danny_Joris’s picture

I've tried #1 and #7 and come to the same conclusion as #5. The custom alias is applied to the published version.

Danny_Joris’s picture

I tried patch #130 pathauto-state from https://drupal.org/node/936222#comment-7395866 and while the code and approach is way different (added db table), I'm finding that with workbench moderation, the outcome is exactly the same as #7. For me that patch still has the same issue as described in #5.

I left a comment there too: https://drupal.org/node/936222#comment-7994053

Danny_Joris’s picture

#5 seems to be reported in the workbench moderation queue as well: #1896102: Revision management of URL paths

Danny_Joris’s picture

Issue summary: View changes

better description

jweowu’s picture

Regarding #7, may I point out that

if ((isset($node->path['pathauto']) && empty($node->path['pathauto'])) || !isset($node->path['pathauto'])) {

can also be written as:

if (empty($node->path['pathauto'])) {

(which is rather dramatically more readable).

That raises the question of why the original code had gone to the extra effort of ensuring that the value was set:

if (isset($node->path['pathauto']) && empty($node->path['pathauto'])) {

As Ayrmax points out in #1, removing that test probably has side-effects.

Baysaa’s picture

@jweowu if you don't check with isset() wouldn't the empty() check create undefined index warnings if it's indeed not set?

jweowu’s picture

Baysaa: empty() incorporates isset(). If isset() would return FALSE, then so will empty().

(If empty() was just a boolean test, there wouldn't be any point in it existing.)

mvonfrie’s picture

I still have the issue that my manual aliases get replaced by autogenerated ones during bulk generate aliases in 7.x-1.2+19-dev. I agree with other users that manual aliases should never be replaced by autogenerated ones on node/entity save or during bulk generation because website users/administrators have a reason to use manual aliases when they do. In my case external sites rely heavliy on three pages of my site using special aliases. If they don't do after a bulk update the external sites and some logic inside my website don't work anymore. Furthermore it is a legal problem in this special case if the interaction between drupal website and external site doesn't work.

cilefen’s picture

I can confirm this problem in 7.x-1.2.

cilefen’s picture

Leeteq’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
acbramley’s picture

Status: Active » Closed (duplicate)

Try the patch from #936222: Merge in pathauto_persist module functionality to prevent losing manual aliases with node_save() calls it's about to be committed (hopefully) and in my opinion this issue should be closed as duplicate.