Just noticed that T&C saves the entire text in every user record, leading to some serious data bloat. I'll provide a patch when I can since there are some other issues with Legal that have been bothering me.

Comments

robert castelo’s picture

Yes, that's a bug.

Patch would be welcome.

Please make sure to provide a separate patch for each bug fixed and feature added. Makes it quicker to review and commit.

john.money’s picture

Title: By design? Saves T&C in every user record = data bloat » Patch to cleanup user data variables
Status: Active » Needs review
StatusFileSize
new1.28 KB

The following patch will cleanup the user data variable bloat. Normally, I wouldn't be concerned about it, but since the entire T&C is stored in every user record, it needed an immediate fix. Note that this patch will NOT work if you are using other contributed modules that hijack the user_register_submit function and do not return control to it (e.g. Logintoboggan, Invite, etc). You will need to manually clear the variables in the appropriate xxx_user_register_submit function.

Also, if you want to cleanup your existing user records, one solution would be to:

1. create a new T&C version so that all users have to accept
2. add the following to your login.module which is not incorporated into the attached patch since it is not needed for new/virgin installations

function legal_login_submit($form_id, $form_values) {
      
    global $user;
    $user = user_load(array('uid' => $form_values['uid']));

    legal_save_accept($user->uid, $form_values['tc_id']);

//GW mod - clean up existing user data varaible bloat
  user_save($user,array("conditions"=>NULL,"display"=>NULL,"current_id"=>NULL,"current_date"=>NULL));
//end mod

GW

john.money’s picture

Ignore previous patch... bad function name. Attached is corrected.

Gman’s picture

I have been looking into this issue as well. But our site uses LoginToboggan, so your patch will not work for us.

I think an approach would be the three places that 'legal_save_accept(...)' is called, to remove the associated $edit or $account entries that you remove in your patch.

I believe that approach will work more generally to make this module play well with others. I may be able to offer a patch along those lines.

john.money’s picture

LoginToboggan never passes control back to user_register_submit which is not so much a fault with LoginToboggan but with the limitations of the user module. At any rate, if you unset the legal variables within logintoboggan_user_register_submit, it will work like this:

function logintoboggan_user_register_submit($form_id, $form_values) {
  global $base_url;

  $mail = $form_values['mail'];
  $name = $form_values['name'];
  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $reg_pass_set = !variable_get('user_email_verification', TRUE);

  // If we are allowing user selected passwords then skip the auto-generate function
  // The new user's status should default to the site settings, unless reg_passwd_set == 1
  // (immediate login, we are going to assign a pre-auth role), and we want to allow
  // admin approval accounts access to the site.
  if ($reg_pass_set) {
    $pass = $form_values['pass'];
    $status = 1;
  }
  else {
    $pass = user_password();
    $status = variable_get('user_register', 1) == 1;
  }

  // Must unset mail confirmation to prevent it from being saved in the user table's 'data' field.
  if (isset($form_values['conf_mail'])) { unset($form_values['conf_mail']); }

//GW mod 01 - clean up user data variables for legal.module
  unset($form_values['conditions'], $form_values['display'], $form_values['current_id'], $form_values['current_date']);
//end mod

//GW mod 02 - clean up user data variables for user.module (since overriden by this module)
  unset($form_values['form_token'], $form_values['submit'], $form_values['op'], $form_values['notify'], $form_values['form_id'], $form_values['affiliates'], $form_values['destination']);
//end mod

Inicidentally, the second mod I list above are orphaned form variables which user.module cleans up but LoganToboggan does not. Can't provide a patch that covers all these possibilities since every module that hooks into user.module registration will have these same problems.

Steven’s picture

StatusFileSize
new3.06 KB

Riiiiight.

And here's a patch that doesn't do crazy stuff and just uses the normal documented way of preventing variables from spilling into the users.data column.

It also cleans up the screwed up users table the sane way, with a multi-part update, rather than adding a permanent piece of code just for legacy purposes.

I removed the 'extras' values from the data column too, since the stored values are only used when the terms and conditions change, and there are no guarantees that the old checkboxes match the new ones.

The legal.module chunks aren't code-style compliant, but then neither is the surrounding code.

Steven’s picture

Category: support » bug
robert castelo’s picture

Status: Needs review » Closed (fixed)