I'm getting following errors when viewing userprofiles:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\Program Files\Apache Group\Apache2\htdocs\intranet\sites\default\modules\token\token.module on line 342.
warning: array_keys() [function.array-keys]: The first argument should be an array in C:\Program Files\Apache Group\Apache2\htdocs\intranet\sites\default\modules\token\token.module on line 345.
warning: array_values() [function.array-values]: The argument should be an array in C:\Program Files\Apache Group\Apache2\htdocs\intranet\sites\default\modules\token\token.module on line 346.
warning: Invalid argument supplied for foreach() in C:\Program Files\Apache Group\Apache2\htdocs\intranet\sites\default\modules\token\token.module on line 409.
warning: Invalid argument supplied for foreach() in C:\Program Files\Apache Group\Apache2\htdocs\intranet\sites\default\modules\pathauto\pathauto.inc on line 566.

I think it is connected to either Ldap_integration or Realname modules. Something Patch #4 from this issue http://drupal.org/node/886200 seems to fix the problem. I replaced array_merge($tokens['global']['default'], $tokens[$type][$id]); with merge($tokens['global']['default'], $tmp_tokens);. But I'm not sure if this is the right way to fix it.

Comments

bakanyaka’s picture

Forgot to add: I only getting this error when logged in as a simple user and viewing other users profile. Administrators can view any profiles without errors, also users get no errors while viewing own profiles.

greggles’s picture

Go to admin/reports/status and it will let you know which modules are causing this problem.

dave reid’s picture

Status: Active » Postponed (maintainer needs more info)
staze’s picture

I also see this issue, but it only pops up about one in every 100 times I load a page, and goes back away.

admin/reports/status shows all green.

btmash’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new968 bytes

From what I have noticed, this seems to be happening with the token module. What I narrowed it down to occurring was:

1) The other 'non-global' tokens get created.
2) Token module checks if the global tokens exist (they don't at this time).
3) Token module creates global set of tokens.

However, it seems like the non-global tokens that were created get wiped out and so its trying to merge the global tokens against something that no longer exists. The patch I wrote basically moves the code so that the global tokens get created first and the other type after. It **seems** to fix the issue though it requires further review and testing.

dave reid’s picture

Status: Needs review » Needs work

I still think this is happening by some kind of edge case, otherwise this would have been reported way sooner. This is treating the symptom, but not the cause.

btmash’s picture

You're right - I did some more testing and found that while the errors no longer show up on the page, some other strange issues are occurring. As a note, they involved

1) Pathauto
2) LDAP Integration (specifically the LDAP Data module)

which I'm trying to figure out on what the issue could be.

f2boot’s picture

Here is the explanation I have been able to build:

If you set LDAP Data Synchronization on "Every time user object loaded in Drupal"
(the problem does not seem to happen otherwise)

you enter this process (read "calls" between each line):

module_invoke_all('token_values', 'global')

token: token_token_values $type=global

drupal_get_title
menu_get_active_title
menu_get_active_trail
menu_set_active_trail
menu_tree_page_data
menu_tree_check_access
_menu_tree_check_access

_menu_link_translate
   execute menu item load_functions for item
   [link_title] => My account
   [load_functions] => a:1:{i:1;s:22:"user_uid_optional_load";})
   [page_callback] => user_view
   [access_callback] => user_view_access

user: user_uid_optional_load
user: user_load
user: user_module_invoke load
ldapintegration: ldapdata_user load    

since we are in "Every time user object loaded in Drupal" (would stop otherwise)

user: user_save
user: user_module_invoke update
pathauto: pathauto_user $op = update
pathauto: pathauto_get_placeholders
token: token_get_values  with flush = true => empties $tokens

the problem is that token_get_values is called recursively (see first and last line of the process)
you run it once then it gets called
once for the user you want to see the profile of
and once for current user
note the last line of the process: $tokens array gets emptied before rebuilding it for the current user so $token data for the profile of the other user is erased => hence raising the error ...

i guess
$tokens['user']['current user id'] and $tokens['user']['other user profile id']
should be kept somehow through "Special-case global tokens" piece of code
and remerged after...

harvlad’s picture

I had these error messages after creating a new unverified ldap user. Changing ldap/data/syncronizing options to "When user logs in" fixed the issue. For us this was fine as it suited our requirements. It was previously set to "Every time user object loaded in Drupal"

hefox’s picture

Status: Needs work » Needs review
StatusFileSize
new500 bytes

As comment 8 indicates, this is caused by someone resetting the tokens static cache during module_invoke_all('global', 'default').

There was a $temp_tokens variable that was always being set with the current tokens, so replaced $tokens[$type][$id] with it for the case that tokens got wiped and it is also working. The advantage of this patch vs the other is that if someone decides to do the same, ie wipe the internal cache, but during $token[$type][$id], it won't fall prone to a similar error.

However, I'd advised looking into *why* someone would be wiping the cache while generating tokens also.

hefox’s picture

Title: array_merge() error when viewing user profiles » array_merge() errors in token_get_values

Changing title to reflect that the issue can happen during other situations (I am getting it during custom module's database updates).

Status: Needs review » Needs work

The last submitted patch, 1000894_token_array_merge_errors.patch, failed testing.

greggles’s picture

If tokens change during the page request it makes sense to clear them.

For example, autonodetitle creates a temporary title of "ant" so when Pathauto gets tokens it needs to flush them in case the "ant" token title is set.

I'm not sure why this failed testing :(

I didn't review the code.

greggles’s picture

hefox clarified the cause of this being a call to token_get_values from *within* a call to token_get_values. That is somewhat irregular. I can imagine it happening if you build the tokens on a node where a field is using a filter that includes token processing.

froboy’s picture

Status: Needs work » Needs review
froboy’s picture

I tested the patch and it seems to solve the problem for me. I do need to rebuild LDAP data on every user load so this will really help me out.

I can't tell why the testing failed either... resubmitted to see if it was a fluke.

Status: Needs review » Needs work

The last submitted patch, 1000894_token_array_merge_errors.patch, failed testing.

reaneyk’s picture

subscribe

dave reid’s picture

Status: Needs work » Closed (duplicate)