function user_update_7020

Add changed field to users table.

Related topics

File

modules/user/user.install, line 937

Code

function user_update_7020() {
  // The "changed" column was renamed to "access" in system_update_136(), and
  // the "changed" index on "access" column may persist on old MySQL databases.
  if (db_index_exists('users', 'changed')) {
    if (!db_index_exists('users', 'access')) {
      db_add_index('users', 'access', array(
        'access',
      ));
    }
    db_drop_index('users', 'changed');
  }
  $spec = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Timestamp for when user was changed.',
  );
  $keys = array(
    'indexes' => array(
      'changed' => array(
        'changed',
      ),
    ),
  );
  // In some cases sites have added the changed field themselves e.g. via a
  // contrib or custom module. Ensure the field uses core's new schema.
  if (db_field_exists('users', 'changed')) {
    db_change_field('users', 'changed', 'changed', $spec, $keys);
  }
  else {
    db_add_field('users', 'changed', $spec, $keys);
    // Set the initial value for existing users.
    db_update('users')->expression('changed', 'created')
      ->execute();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.