Commit e3b239c3 authored by Drew Webber's avatar Drew Webber
Browse files

Issue #1835754 by mcdruid, Fabianx, mfb, izmeez, hargobind: Tweak...

Issue #1835754 by mcdruid, Fabianx, mfb, izmeez, hargobind: Tweak user_update_7020() for sites with an existing user.changed field and/or index"
parent bb5b229a
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -935,6 +935,15 @@ function user_update_7019() {
 * Add changed field to users table.
 */
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,
@@ -946,13 +955,20 @@ function user_update_7020() {
      '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
    // Set the initial value for existing users.
    db_update('users')
      ->expression('changed', 'created')
      ->execute();
  }

}
/**
 * @} End of "addtogroup updates-7.x-extra".
 */