#520760: SA-CORE-2009-007 user signature format

This added a 'signature_format' column to the users table. Head2Head needs to add the column, and also make sure that for existing users, it is pre-populated with a text format that makes sense.

Comments

JacobSingh’s picture

Assigned: Unassigned » JacobSingh
JacobSingh’s picture

Assigned: JacobSingh » Unassigned
Status: Active » Needs review
StatusFileSize
new1.77 KB

Accidentally committed the attached.

Making needs review, but is actually in HEAD.

JacobSingh’s picture

StatusFileSize
new1.79 KB

Heh, just realized the documentation is stupid. :)

Committing a fix and here's a complete patch.

David_Rothstein’s picture

Status: Needs review » Needs work

This isn't complete because it leaves everyone with '0' in the database table; we need to assign all users (at least those who have an actual signature) a real signature format.

The D6->D7 update does that in http://api.drupal.org/api/function/filter_update_7005/7 (at the bottom of that function) but the problem is that it's not so simple for us, since on an existing D7 install that is already in place, the site no longer has a single default text format.

Seems like there are two things we could do here and I'm not sure which is correct:

  1. We could use the fallback format here (i.e., plain text). That's simplest, and also probably the most "correct" thing to do for a case where we do not know what the existing text format was intended to be; however, it will have the practical effect of breaking any HTML that people included in their signatures. Something like (untested):
    db_update('users')
      ->fields(array(
        'signature_format' => filter_fallback_format(),
      ))
      ->condition('signature', '', '!=')
      ->condition('signature_format', 0)
      ->execute();
    
  2. Alternatively, we could find the default text format for each user and save it. This is probably most likely to result in the correct data, but choosing a text format that could theoretically be any format (in any markup language) and assuming that existing signatures are at all sensible when matched with that is seriously sketchy behavior that brings the vengeance of the text format gods down upon us :) Something like (untested):
    $uids = db_select('users')
      ->condition('signature', '', '!=')
      ->condition('signature_format', 0)
      ->execute()
      ->fetchCol();
    foreach(user_load_multiple($uids) as $account) {
      user_save($account, array('signature_format' => filter_default_format($account)));
    }
    

    Not sure if there are any sites running HEAD to HEAD that have tons of users with preexisting signatures - if so, they would want to run the above code in a batch :(

JacobSingh’s picture

I think we just go for option 1. This is head2head, so I think it's okay here. In a "real" update function, I'd probably say do #2.

-J

JacobSingh’s picture

Status: Needs work » Needs review
StatusFileSize
new702 bytes

I committed something similar to option #1 because might as well have it in the project since it is less broken then what is there currently.

Attached is the followup diff.

I didn't include all the conditions that @David put in because:

1). We're adding the field so we know there are no values in it yet.

2). If a user has a signature or not, we should be giving them a format I suppose.

David_Rothstein’s picture

Status: Needs review » Fixed

Looks OK to me.

I definitely agree with your first point - since it's unlikely anyone deployed this to a live site between your two commits :)

For your second point, if a user doesn't have a signature yet we probably don't actually need to assign them a format (since the theory is that they haven't had an opportunity to select one yet). As an example, I'm not sure whether it's a bug or by design, but user #1 created by Drupal during installation starts off with 0 as their signature format and that kind of makes sense, since it means they will never have the wrong choice pre-selected when they go to edit their account page for the first time.

For our use cases in Head2Head, it probably doesn't matter a whole lot either way, though.

JacobSingh’s picture

Ah good point...

Status: Fixed » Closed (fixed)

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