I get the following error: One of my sites, user edit its comment, and the comment post date was the user's register date. I spent lot's of time to investigate, and I've found, the global $user, and all of the $user array by user_load() had tons of unnecessary data.

When in user/%/edit page hit the submit button, the user_save() get all of $form_state['value'] included the complete $node object.

I haven't better idea: I cleaned the $form_state['values'] before user_save(), then undo before node_form_submit() starts:

  // prevent to store all values in user->data field, and give it back, before node_form_submit
  $cache = $form_state['values'];
  foreach ($account as $key => $value) {
    if (isset($value)) {
      $account_keys[] = $key;
    }
  }
  foreach ($form_state['values'] as $key => $value) {
    if (!in_array($key, $account_keys)) {
      unset ($form_state['values'][$key]);

    }
  }
  user_save($account, $form_state['values'], $category);
  $form_state['values'] = $cache;

Are there any possible better solution?

CommentFileSizeAuthor
#1 account_profile.patch3.08 KBszantog
account_profile.patch2.06 KBszantog

Comments

szantog’s picture

StatusFileSize
new3.08 KB

The previous patch works - until turning on a new module, that alter to the user_form too. The altered new data isn't saved, because it isn't in $account array. In patch there are a _multi_array_key_exist helper function, but i don't want to comy here.

  // prevent to store all values in user->data field.
  $account_form_state = array();
  module_load_include('pages.inc', 'user');
  $account_form = user_profile_form(array(), $account);

  //If $form_state['values'][<element>] is exist in original user profile form, give it to $account_form_state, and separate the node_form
  foreach ($form_state['values'] as $key => $value) {
    if (_multi_array_key_exists($key, $account_form)) {
      $account_form_state[$key] = $form_state['values'][$key];
    }
  }
  user_save($account, $account_form_state, $category);
cpliakas’s picture

Status: Needs review » Reviewed & tested by the community

Applied the patch, and it seems to work as expected. No more node dump in the data column! Thanks for your work on this issue, szantog.

~Chris

kenorb’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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