Just been looking at what we do for signature fields, it's a bit confusing so I might get this wrong.

I don't normally let what other software does dictate how I think Drupal should work, but in the case of Sigs for Forums we're trying to let people import from vBulletin without losing any data, so the field lengths need to match.

The field length for vB signatures is (MySQL) MEDIUMTEXT, but the lengths used in Signatures for Forums appears to be a VARCHAR?

Also, I'm thinking we shouldn't change the actual length of the field in the database using the UI, firstly because the default of 255 is too short to import into from vBulletin (I use this module in conjunction with vB to Drupal all the time!); secondly, because an admin could easily truncate a whole bunch of user's signatures by accident/without thinking it through. The maximum length option was always meant to be a business logic thing.

So, yeah, signature: 'type' => 'text', 'size' => 'medium' Does that make sense? Hopefully it'll actually make some of what we're doing simpler.

Comments

Liam McDermott’s picture

Title: Signature field length » Signature field length should be mediumtext
Niklas Fiekas’s picture

Category: support » task

I see. This change was motivated by these lines from user.module.


      $user_schema = drupal_get_schema('users');
      if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) {
        form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' =>  $user_schema['fields']['signature']['length'])));
      }

But although the user can set the maximum field length that is used by hook_schema_alter() database fields should never get truncated. The changes will be never written to the database and just used by the given part of the user.module. The database field length will only really be changed during install and uninstall. Install sets a huge field length, uninstall sets it back to default (after showing a warning when the module is disabled).


/**
 * The new length of the signature field of the user table.
 *
 * Limiting factor |  Bytes
 * ----------------+-------
 * Drupal core     |    255
 * MySQL           | 65,535
 * SQLite          | 21,845
 */
define('SIGNATURE_FORUM_FIELD_LENGTH', 21845);

MEDIUMTEXT would be 16,777,216?

Making it MEDIUMTEXT isn't trivial and requires some thought and work, but we should probably do it, if we need full compatibility. On the other hand: Have you ever seen such a long signature?

Liam McDermott’s picture

Ah, I see how it works now! Good to know it doesn't affect the size of the field (unless it's on install/uninstall).

It would be good to have the field as mediumtext, yes. And to make it an unlimited size by default, I'll have to think about how to do that though. And yeah, it is a ridiculous size, not sure it's strictly necessary but I suppose we should strictly keep compatible with vBulletin (in this case).

Thanks very much for explaining this to me!

Clearbrook’s picture

I don't doubt that mediumtext is good conceptually. However, we are linking up with Drupal Core User module, and I am not happy with the idea of trying to modify it this way. If it were a contributed module whose Schema were being tweaked this far, I'd tend to agree with this line of reasoning. However, I don't like the idea that modules should modify Drupal Core lightly. If it is needed, it is needed. But I don't think it is, even here. I think it works fine as varchar, but what do I know? This is backend stuff and in truth, mediumtext can be loaded into varchar via SQL if someone is trying to import signatures from vBulletin. You hit the nail on the head when you say "...yeah, it is a ridiculous size, not sure it's strictly necessary..." Exactly...

255 is small, and that was one reason I have installed this module. But, as it is now, the 255 character limit is still enforced by Drupal Core User. A patch to User.module may be needed, and that is a big hurdle.

A Word Document of my Resume is about two pages, with a fair amount of white space. It comes to a character count of 4,119 with spaces. That would probably come down to about a page and half or a page and a quarter if not for all of the formatting, but even half of that is too much for a signature, IMHO. That would be a limit of about 2k characters, allowing for the unseen part of HTML tags, if allowed. I honestly don't want signatures that big cluttering up my site, and have a hard time thinking that anyone would, although I will grant that there are a lot of people with a lot of different tastes, and I would not be shocked to hear of such a person. I'd raise my eyebrows, but accept the fact that their choice is their choice.

That someone would want a signature with more than even half of 21,845 characters boggles my mind.

;'{P

Clearbrook’s picture

No patch to Drupal Core needed. I was able to make a patch that works to my needs and posted it.