Requires node to be saved twice before title is updated - seems something is not right in process order. Don't know if it's a token issue or auto nodetitle issue. As far as I can tell all other tokens get updated so long as CCK is not a date field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

OnlineWD™’s picture

Seems to happen for reference fields also. This fixed it for me http://drupal.org/node/360359#comment-1460918.

bdimofte’s picture

Title: CCK Date Not Updated After Save » CCK Tokens Not Updated After Save
FileSize
821 bytes

I had this problem for text CCK fields.

The issue probably appears when some other module makes a call upon token module before the node object is actually updated. So, the old values are cached and auto_nodetitles uses them.
The solution is to flush those out-dated tokens.

Patch attached

fago’s picture

Status: Active » Closed (won't fix)

I'm aware of that caching problem, however I'd say it's by design of the token module. Your patch does just bypass the cache, what hurts performance. So I think this is something that should be fixed for token, and it is in d7.

fago’s picture

Title: CCK Tokens Not Updated After Save » Token caching problems.
Status: Closed (won't fix) » Active

Ok, let's reopen this and make it the issue to collect troubles due to token caching.

If some other modules use token too, token replacements gets cached. That's fine, however it might lead to "old token values" being used. As explained in #3, this a general problem with token caching we cannot work around without disabling the cache at all.

However, I don't think generally disabling the cache is a good idea, is it hurts performance.

Q2U’s picture

subscribe

bdimofte’s picture

This code is being run in the node presave process, when different modules make changes on the values that are going to be used by the modules following them.
So this is one of the moments when you have to use the flushing option imo.
Cached token values are for 'load', 'prepare' etc..

cpliakas’s picture

Status: Needs review » Active
FileSize
1.01 KB

I experienced the same issue, and I think the use case might be common enough to warrant a fix in this module. Specifically, my use case is as follows:

I am using ANT to generate a title based on a token, for sake of a concrete example let's say it is `uid`-`author`. I then have a rule that says, email users when the node has been updated with the subject "The node [node:title] has been updated". I would expect [node:title] to be `nid`-`author`, however it is always replaced with "ant" due to the caching issues mentioned above.

To solve my problem I was able to put the following code (very similar to the patch in #2 above) in a custom module as illustrated below:


/**
 * Implementation of hook_nodeapi().
 */
function mymodule_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ('update' == $op && ($setting = auto_nodetitle_get_setting($node->type)) && module_exists('token')) {
    token_replace($setting, 'node', $node, TOKEN_PREFIX, TOKEN_SUFFIX, array(), TRUE);
  }
}

I would argue that similar code should be in ANT, and performance wouldn't really be an issue because you are only flushing the static cache when the node is being created / updated. Attached is a patch that is a slight modification of #2 to make use of Token's constants, and we also don't need to capture $output since the replacements have already been made.

Thanks,
Chris

cpliakas’s picture

Status: Active » Needs review

Marking as "needs review"...

mtndan’s picture

Status: Active » Needs review

I've implemented the patch in #7 and am not seeing any performance impact. It's solved our problem too! Thank you!

iantresman’s picture

Patch #2 did it for me. I have both the tokens module, and Node reference module, and don't know whether one of them was causing the problem. Since I can't handle patches, the following manual changes did the trick:

  • Locate the file modules/auto_nodetitle/auto_nodetitle.module
  • Make a copy of auto_nodetitle.module to be used as a backup, just in case the patch doesn't one to work (in Windows, just highlight the file, click Edit|Copy and then click Edit|Paste)
  • Search through auto_nodetitle.module, looking for the code:
    function _auto_nodetitle_patternprocessor($output, $node) {
      if (module_exists('token')) {
        $output = token_replace($output, 'node', $node);
      }

    Change the line starting $output = so that it now reads:
    $output = token_replace($output, 'node', $node, '[', ']', array(), TRUE);

  • Save the file, and upload it to your Drupal installation.

No-one has noted any problems, so it would be nice to see the patch added to the -dev branch.

Clint Eagar’s picture

#2 Didn't work for me.

Testing #7 now.

UPDATE:
#7 didn't work for me either...any ideas?

My automatic node title setting: [field_customer_ref-title]: Invoice [nid]
The [nid] isn't getting ignored on first save. The node ref token is working fine.

Clint Eagar’s picture

None of the solutions in this thread worked for me, any ideas - it is critical that I can use NID in the page title. I tried using the serial CCK module but that token won't work either.

Clint Eagar’s picture

Finally (all hair now gone) found a solution: http://drupal.org/node/615410#comment-4105594

Using CCK Serial Module (patched), works great with auto node title and pathauto.

dandaman’s picture

Patch #2 fixed my problem. I guess my vote would be to commit this to the D6 version, but I understand the reasons why someone wouldn't want to have this for performance reasons, I guess. I'm glad to hear this has been addressed in the D7 version of Token as well.

greggles’s picture

#2 really should work.

Given that this happens on insert/update operations only the performance impact is not worth the potential for innacurate data (IMO).

Maybe this could be turned into a setting that defaults to not happening but can be overridden?

sarjeet.singh’s picture

thanks bdimofte.
Patch #2 is working for me.
it will be to commit in D6 version.

manish-31’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Fixed
gaurav.kapoor’s picture

Tested with D6 version. Looks good now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.