Hi,

This is a follow-up post, which could be seen as a duplicate of:

* "Node aliases lost/changed when using i18n synchronize translations" - http://drupal.org/node/358722
* "Pathauto should not mess up aliases when node_load, node_save is used" - http://drupal.org/node/726964 (duplicate)

as it solves the i18n synchronization issue as well.

But it is not a duplicate as this patch goes much further as just i18n, but rather fixes the problem at the root and provides a test case, _why_ this is a bug.

It proves that there is a problem by adding three test cases (Dave Reid asked this in 726964) from which one fails.

It also fixes the problem in the attached patch. Afterwards all test cases are passed.

Now comes the problem description (this is a repeat of the test cases in human form):

Pathauto is storing certain information at the moment the node is edited to see if the automatic alias or the manual alias is used.

Lets assume we have content/[title] as automatic alias and content/[nid] as manual alias and lets assume we have set the manual alias.

So alias is: content/[nid]

Current behavior: (Node edit - No changes)

* Edit form is opened
* $node->pathauto_perform_alias = false
* On save:
$node->path = content/[nid]

Current behavior: (node_save() - No changes)

* node is loaded. 
* node is saved.
* On save:
 $node->pathauto_perform_alias is not set => it performs alias
$node->path = content/[title]

BUG! The alias should not have been changed.

Scenario 2:

We have automatic alias set.

Current behavior: (Node edit - Title change)

* Edit form is opened
* $node->pathauto_perform_alias = true
* On save:
$node->path = content/[new title]

Current behavior: (Node save - Title change)

* node is opened
* $node->title = [new title]
* On save:
$node->pathauto_perform_alias is not set => it performs alias
$node->path = content/[new title]

CORRECT.

This means we have two cases here from which one is correct and the other one fails.

One could be tempted to never change aliases when node_save is used, but this would let Scenario 2 fail then.

The solution however is really easy:

If node_save is used instead of submitting of the node through the edit form do:

in nodeapi/presave:

- Load the old node
- Compute the pathauto_perform_alias based on the old node data
- Set $node->pathauto_perform_alias

From here on there is no difference anymore if the node was submitted through the edit form or via node_save().

If a contributed module wants to make sure that the alias is re-computed it can always set: $node->pathauto_perform_alias manually.

For this to still work a third testcase is added.

Please, Dave Reid test this and apply it.

The i18n synchonization issue and other form related problems can be solved instantly with this patch and regressions can be caught through the test suite.

Best Wishes,

Fabian (LionsAd)

Comments

dave reid’s picture

Status: Needs review » Closed (duplicate)

There are already several issues with this topic already open, we don't need another one.

fabianx’s picture

Status: Closed (duplicate) » Needs review

The real issue with this patch is (after discussion with Dave Reid):

- Usage of comparison logic (pathauto_create_alias) should not be done in prepare or update. (due to performance considerations)

However for the record:

There is an easy solution:

Use http://drupal.org/project/pathauto_persist module for now and it "just works" and also after adding the module in setUp stage add some check up passes the new test suite.

Best Wishes,

Fabian (LionsAd)

fabianx’s picture

mably’s picture

Status: Needs review » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.