Update the {user}.signature_format column.

Related topics

File

modules/user/user.install, line 662
Install, update and uninstall functions for the user module.

Code

function user_update_7010() {

  // Update the database column to allow NULL values.
  db_change_field('users', 'signature_format', 'signature_format', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
    'description' => 'The {filter_format}.format of the signature.',
  ));

  // Replace the signature format with NULL if the signature is empty and does
  // not already have a stored text format.
  //
  // In Drupal 6, "0" (the former FILTER_FORMAT_DEFAULT constant) could be used
  // to indicate this situation, but in Drupal 7, only NULL is supported. This
  // update therefore preserves the ability of user accounts which were never
  // given a signature (for example, if the site did not have user signatures
  // enabled, or if the user never edited their account information) to not
  // have a particular text format assumed for them the first time the
  // signature is edited.
  db_update('users')
    ->fields(array(
    'signature_format' => NULL,
  ))
    ->condition('signature', '')
    ->condition('signature_format', 0)
    ->execute();

  // There are a number of situations in which a Drupal 6 site could store
  // content with a nonexistent text format. This includes text formats that
  // had later been deleted, or non-empty content stored with a value of "0"
  // (the former FILTER_FORMAT_DEFAULT constant). Drupal 6 would filter this
  // content using whatever the site-wide default text format was at the moment
  // the text was being displayed.
  //
  // In Drupal 7, this behavior is no longer supported, and all content must be
  // stored with an explicit text format (or it will not be displayed when it
  // is filtered). Therefore, to preserve the behavior of the site after the
  // upgrade, we must replace all instances described above with the current
  // value of the (old) site-wide default format at the moment of the upgrade.
  $existing_formats = db_query("SELECT format FROM {filter_format}")
    ->fetchCol();
  $default_format = variable_get('filter_default_format', 1);
  db_update('users')
    ->fields(array(
    'signature_format' => $default_format,
  ))
    ->isNotNull('signature_format')
    ->condition('signature_format', $existing_formats, 'NOT IN')
    ->execute();
}