You are here

function user_revision_enable in User Revision 7

Implements hook_enable().

File

./user_revision.install, line 23
Install, update and uninstall functions for the user_revision module.

Code

function user_revision_enable() {
  $users = db_select('users', 'u')
    ->fields('u', array(
    'uid',
    'vid',
    'name',
    'mail',
    'theme',
    'signature',
    'signature_format',
    'status',
    'timezone',
    'language',
    'picture',
    'data',
  ))
    ->condition('u.uid', 0, '!=')
    ->execute()
    ->fetchAll();
  foreach ($users as $user) {
    db_insert('user_revision')
      ->fields(array(
      'uid' => $user->uid,
      'log' => '',
      'timestamp' => REQUEST_TIME,
      'authorid' => $user->uid,
      'name' => $user->name,
      'mail' => $user->mail,
      'theme' => $user->theme,
      'signature' => $user->signature,
      'signature_format' => $user->signature_format,
      'status' => $user->status,
      'timezone' => $user->timezone,
      'language' => $user->language,
      'picture' => $user->picture,
      'data' => $user->data,
    ))
      ->execute();
  }
  $user_revisions = db_select('user_revision', 'ur')
    ->fields('ur', array(
    'uid',
    'vid',
  ))
    ->condition('ur.uid', 0, '!=')
    ->execute()
    ->fetchAll();

  // Update revision id of all non-anonymous users.
  foreach ($user_revisions as $user_revision) {
    db_update('users')
      ->condition('uid', $user_revision->uid)
      ->fields(array(
      'vid' => $user_revision->vid,
    ))
      ->execute();
  }
  $schema['users'] = array();
  user_revision_schema_alter($schema);
  foreach ($schema['users']['unique keys'] as $name => $spec) {
    db_add_unique_key('users', $name, $spec);
  }
}