function user_install

Same name in other branches
  1. 9 core/modules/user/user.install \user_install()
  2. 8.9.x core/modules/user/user.install \user_install()
  3. 10 core/modules/user/user.install \user_install()
  4. 11.x core/modules/user/user.install \user_install()

Implements hook_install().

File

modules/user/user.install, line 303

Code

function user_install() {
    // Insert a row for the anonymous user.
    db_insert('users')->fields(array(
        'uid' => 0,
        'name' => '',
        'mail' => '',
    ))
        ->execute();
    // We need some placeholders here as name and mail are uniques and data is
    // presumed to be a serialized array. This will be changed by the settings
    // form in the installer.
    db_insert('users')->fields(array(
        'uid' => 1,
        'name' => 'placeholder-for-uid-1',
        'mail' => 'placeholder-for-uid-1',
        'created' => REQUEST_TIME,
        'changed' => REQUEST_TIME,
        'status' => 1,
        'data' => NULL,
    ))
        ->execute();
    // Built-in roles.
    $rid_anonymous = db_insert('role')->fields(array(
        'name' => 'anonymous user',
        'weight' => 0,
    ))
        ->execute();
    $rid_authenticated = db_insert('role')->fields(array(
        'name' => 'authenticated user',
        'weight' => 1,
    ))
        ->execute();
    // Sanity check to ensure the anonymous and authenticated role IDs are the
    // same as the drupal defined constants. In certain situations, this will
    // not be true.
    if ($rid_anonymous != DRUPAL_ANONYMOUS_RID) {
        db_update('role')->fields(array(
            'rid' => DRUPAL_ANONYMOUS_RID,
        ))
            ->condition('rid', $rid_anonymous)
            ->execute();
    }
    if ($rid_authenticated != DRUPAL_AUTHENTICATED_RID) {
        db_update('role')->fields(array(
            'rid' => DRUPAL_AUTHENTICATED_RID,
        ))
            ->condition('rid', $rid_authenticated)
            ->execute();
    }
}

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