function user_revision_install in User Revision 7.2
Same name and namespace in other branches
- 8 user_revision.install \user_revision_install()
- 7 user_revision.install \user_revision_install()
Implements hook_install().
File
- ./
user_revision.install, line 189 - Install, update and uninstall functions for the user_revision module.
Code
function user_revision_install() {
$schema['users'] = array();
include_once 'user_revision.module';
user_revision_schema_alter($schema);
foreach ($schema['users']['fields'] as $name => $spec) {
db_add_field('users', $name, $spec);
}
// Set all initial vid values equal to uid values.
db_update('users')
->expression('vid', 'uid')
->execute();
// Add unique keys.
foreach ($schema['users']['unique keys'] as $key => $spec) {
db_add_unique_key('users', $key, $spec);
}
// Update weight of module in system table.
db_update('system')
->fields(array(
'weight' => 99,
))
->condition('name', 'user_revision', '=')
->execute();
// Prepare Batch API to add all users to the revision table.
$total_count = db_select('users', 'u')
->condition('u.uid', 0, '!=')
->countQuery()
->execute()
->fetchField();
$batch = array(
'operations' => array(
array(
'user_revision_table_init_data_batch_process',
array(
$total_count,
),
),
),
'finished' => 'user_revision_table_init_data_batch_finished',
'title' => t('Updating revision table'),
'init_message' => t('Initializing.'),
'progress_message' => t('Completed @current of @total.'),
'error_message' => t('An error has occurred.'),
'file' => drupal_get_path('module', 'user_revision') . '/user_revision.batch.inc',
);
// Execute Batch API.
batch_set($batch);
}