Newer
Older

Angie Byron
committed
/**
* @file
* Install, update and uninstall functions for the user module.
*/
use Drupal\Core\Language\Language;

Angie Byron
committed
use Drupal\field\Field;

Dries Buytaert
committed
* Implements hook_schema().
*/
function user_schema() {

Jennifer Hodgdon
committed
// The table name here is plural, despite Drupal table naming standards,
// because "user" is a reserved word in many databases.

Angie Byron
committed
$schema['users'] = array(

Dries Buytaert
committed
'description' => 'Stores user data.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,

Dries Buytaert
committed
'description' => 'Primary Key: Unique user ID.',
'default' => 0,

Dries Buytaert
committed
'uuid' => array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'name' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',

Dries Buytaert
committed
'description' => 'Unique user name.',
'langcode' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => "The {language}.langcode of the user's profile.",
),
'pass' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',

Dries Buytaert
committed
'description' => "User's password (hashed).",
),
'mail' => array(
'type' => 'varchar',

Dries Buytaert
committed
'length' => 254,
'not null' => FALSE,
'default' => '',

Dries Buytaert
committed
'description' => "User's e-mail address.",
),
'signature' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',

Dries Buytaert
committed
'description' => "User's signature.",
'signature_format' => array(
'type' => 'varchar',
'length' => 255,

Angie Byron
committed
'not null' => FALSE,

Angie Byron
committed
'description' => 'The filter format ID of the signature.',
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,

Dries Buytaert
committed
'description' => 'Timestamp for when user was created.',
),
'access' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,

Dries Buytaert
committed
'description' => 'Timestamp for previous time user accessed the site.',
),
'login' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,

Dries Buytaert
committed
'description' => "Timestamp for user's last login.",
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',

Dries Buytaert
committed
'description' => 'Whether the user is active(1) or blocked(0).',
),
'timezone' => array(
'type' => 'varchar',

Angie Byron
committed
'length' => 32,
'not null' => FALSE,

Angie Byron
committed
'description' => "User's time zone.",
'preferred_langcode' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => 'The {language}.langcode that the user prefers for receiving emails and viewing the site.',

Dries Buytaert
committed
'preferred_admin_langcode' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => 'The {language}.langcode that the user prefers for viewing administration pages.',
),
'init' => array(
'type' => 'varchar',

Dries Buytaert
committed
'length' => 254,
'not null' => FALSE,
'default' => '',

Dries Buytaert
committed
'description' => 'E-mail address used for initial account creation.',
),
'indexes' => array(
'access' => array('access'),

Gábor Hojtsy
committed
'created' => array('created'),
'mail' => array('mail'),

Dries Buytaert
committed
'unique keys' => array(

Dries Buytaert
committed
'uuid' => array('uuid'),

Dries Buytaert
committed
'name' => array('name'),
),
'primary key' => array('uid'),
);
$schema['users_data'] = array(
'description' => 'Stores module data as key/value pairs per user.',
'fields' => array(
'uid' => array(
'description' => 'Primary key: {users}.uid for user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'module' => array(
'description' => 'The name of the module declaring the variable.',
'type' => 'varchar',
'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The identifier of the data.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'serialized' => array(
'description' => 'Whether value is serialized.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'default' => 0,
),
),
'primary key' => array('uid', 'module', 'name'),
'indexes' => array(
'module' => array('module'),
'name' => array('name'),
),
'foreign keys' => array(
'uid' => array('users' => 'uid'),
),
);

Angie Byron
committed
$schema['users_roles'] = array(

Dries Buytaert
committed
'description' => 'Maps users to roles.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,

Angie Byron
committed
'description' => 'Primary Key: {users}.uid for user.',
),
'rid' => array(

catch
committed
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,

Alex Pott
committed
'description' => 'Primary Key: ID for the role.',
),
'primary key' => array('uid', 'rid'),

Dries Buytaert
committed
'indexes' => array(
'rid' => array('rid'),
),
'foreign keys' => array(

Dries Buytaert
committed
'user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
);
return $schema;
}

Dries Buytaert
committed
/**
* Implements hook_install().
*/
function user_install() {
// Insert a row for the anonymous user.
db_insert('users')
->fields(array(
'uid' => 0,

Angie Byron
committed
'uuid' => \Drupal::service('uuid')->generate(),

Dries Buytaert
committed
'name' => '',
'mail' => '',
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,

Dries Buytaert
committed
))
->execute();

Angie Byron
committed
// We need some placeholders here as name and mail are uniques.
// This will be changed by the settings form in the installer.

Dries Buytaert
committed
db_insert('users')
->fields(array(
'uid' => 1,

Angie Byron
committed
'uuid' => \Drupal::service('uuid')->generate(),

Dries Buytaert
committed
'name' => 'placeholder-for-uid-1',
'mail' => 'placeholder-for-uid-1',
'created' => REQUEST_TIME,
'status' => 1,
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,

Dries Buytaert
committed
))
->execute();
}