1 user.install | user_update_1024() |
Add a "changed" column to the "users" table.
Related topics
File
- core/
modules/ user/ user.install, line 1370 - Install, update and uninstall functions for the user module.
Code
function user_update_1024() {
// On older databases originating from Drupal 5, the "changed" column was
// renamed to "access" in system_update_136(), and the "changed" index on the
// "access" column may still persist. That column index needs to be removed
// before adding the new "changed" column.
// See: https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_136/5.x
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();
}
}