123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- <?php
- function user_schema() {
- $schema['authmap'] = array(
- 'description' => 'Stores distributed authentication mapping.',
- 'fields' => array(
- 'aid' => array(
- 'description' => 'Primary Key: Unique authmap ID.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'uid' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "User's {users}.uid.",
- ),
- 'authname' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Unique authentication name.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Module which is controlling the authentication.',
- ),
- ),
- 'unique keys' => array(
- 'authname' => array('authname'),
- ),
- 'primary key' => array('aid'),
- 'foreign keys' => array(
- 'user' => array(
- 'table' => 'users',
- 'columns' => array('uid' => 'uid'),
- ),
- ),
- );
- $schema['role_permission'] = array(
- 'description' => 'Stores the permissions assigned to user roles.',
- 'fields' => array(
- 'rid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'Foreign Key: {role}.rid.',
- ),
- 'permission' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'A single permission granted to the role identified by rid.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "The module declaring the permission.",
- ),
- ),
- 'primary key' => array('rid', 'permission'),
- 'indexes' => array(
- 'permission' => array('permission'),
- ),
- 'foreign keys' => array(
- 'role' => array(
- 'table' => 'role',
- 'columns' => array('rid' => 'rid'),
- ),
- ),
- );
- $schema['role'] = array(
- 'description' => 'Stores user roles.',
- 'fields' => array(
- 'rid' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique role ID.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Unique role name.',
- 'translatable' => TRUE,
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The weight of this role in listings and the user interface.',
- ),
- ),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- 'primary key' => array('rid'),
- 'indexes' => array(
- 'name_weight' => array('name', 'weight'),
- ),
- );
-
-
- $schema['users'] = array(
- 'description' => 'Stores user data.',
- 'fields' => array(
- 'uid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique user ID.',
- 'default' => 0,
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 60,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Unique user name.',
- ),
- 'pass' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "User's password (hashed).",
- ),
- 'mail' => array(
- 'type' => 'varchar',
- 'length' => 254,
- 'not null' => FALSE,
- 'default' => '',
- 'description' => "User's e-mail address.",
- ),
- 'theme' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "User's default theme.",
- ),
- 'signature' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "User's signature.",
- ),
- 'signature_format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the signature.',
- ),
- 'created' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Timestamp for when user was created.',
- ),
- 'access' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Timestamp for previous time user accessed the site.',
- ),
- 'login' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "Timestamp for user's last login.",
- ),
- 'status' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Whether the user is active(1) or blocked(0).',
- ),
- 'timezone' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => FALSE,
- 'description' => "User's time zone.",
- ),
- 'language' => array(
- 'type' => 'varchar',
- 'length' => 12,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "User's default language.",
- ),
- 'picture' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "Foreign key: {file_managed}.fid of user's picture.",
- ),
- 'init' => array(
- 'type' => 'varchar',
- 'length' => 254,
- 'not null' => FALSE,
- 'default' => '',
- 'description' => 'E-mail address used for initial account creation.',
- ),
- 'data' => array(
- 'type' => 'blob',
- 'not null' => FALSE,
- 'size' => 'big',
- 'serialize' => TRUE,
- 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.',
- ),
- ),
- 'indexes' => array(
- 'access' => array('access'),
- 'created' => array('created'),
- 'mail' => array('mail'),
- 'picture' => array('picture'),
- ),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- 'primary key' => array('uid'),
- 'foreign keys' => array(
- 'signature_format' => array(
- 'table' => 'filter_format',
- 'columns' => array('signature_format' => 'format'),
- ),
- ),
- );
- $schema['users_roles'] = array(
- 'description' => 'Maps users to roles.',
- 'fields' => array(
- 'uid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Primary Key: {users}.uid for user.',
- ),
- 'rid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Primary Key: {role}.rid for role.',
- ),
- ),
- 'primary key' => array('uid', 'rid'),
- 'indexes' => array(
- 'rid' => array('rid'),
- ),
- 'foreign keys' => array(
- 'user' => array(
- 'table' => 'users',
- 'columns' => array('uid' => 'uid'),
- ),
- 'role' => array(
- 'table' => 'role',
- 'columns' => array('rid' => 'rid'),
- ),
- ),
- );
- return $schema;
- }
- function user_install() {
-
- db_insert('users')
- ->fields(array(
- 'uid' => 0,
- 'name' => '',
- 'mail' => '',
- ))
- ->execute();
-
-
-
- db_insert('users')
- ->fields(array(
- 'uid' => 1,
- 'name' => 'placeholder-for-uid-1',
- 'mail' => 'placeholder-for-uid-1',
- 'created' => REQUEST_TIME,
- 'status' => 1,
- 'data' => NULL,
- ))
- ->execute();
-
- $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();
-
-
-
- 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();
- }
- }
- function user_update_dependencies() {
-
-
- $dependencies['user'][7006] = array(
- 'system' => 7007,
- );
-
-
-
- $dependencies['user'][7010] = array(
- 'filter' => 7000,
- );
-
-
-
-
-
- $dependencies['user'][7012] = array(
- 'system' => 7061,
- );
-
-
-
- $dependencies['user'][7013] = array(
- 'system' => 7059,
- );
- return $dependencies;
- }
- function _update_7000_user_role_grant_permissions($rid, array $permissions, $module) {
-
- foreach ($permissions as $name) {
- db_merge('role_permission')
- ->key(array(
- 'rid' => $rid,
- 'permission' => $name,
- ))
- ->fields(array(
- 'module' => $module,
- ))
- ->execute();
- }
- }
- function user_update_7000(&$sandbox) {
- $sandbox['#finished'] = 0;
-
- $hash_count_log2 = 11;
-
- if (!isset($sandbox['user_from'])) {
- db_change_field('users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
- $sandbox['user_from'] = 0;
- $sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
- }
- else {
- require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
-
- $has_rows = FALSE;
-
- $count = 1000;
- $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", $sandbox['user_from'], $count);
- foreach ($result as $account) {
- $has_rows = TRUE;
-
-
- if (!preg_match('/^[0-9a-f]{32}$/', $account->pass)) {
- continue;
- }
- $new_hash = user_hash_password($account->pass, $hash_count_log2);
- if ($new_hash) {
-
- $new_hash = 'U' . $new_hash;
- db_update('users')
- ->fields(array('pass' => $new_hash))
- ->condition('uid', $account->uid)
- ->execute();
- }
- }
- $sandbox['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
- $sandbox['user_from'] += $count;
- if (!$has_rows) {
- $sandbox['#finished'] = 1;
- return t('User passwords rehashed to improve security');
- }
- }
- }
- function user_update_7001() {
- db_drop_field('users', 'threshold');
- db_drop_field('users', 'mode');
- db_drop_field('users', 'sort');
- }
- function user_update_7002(&$sandbox) {
- $sandbox['#finished'] = 0;
-
- if (!isset($sandbox['user_from'])) {
- db_change_field('users', 'timezone', 'timezone', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE));
- $sandbox['user_from'] = 0;
- $sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
- $sandbox['user_not_migrated'] = 0;
- }
- else {
- $timezones = system_time_zones();
-
- $count = 10000;
- $contributed_date_module = db_field_exists('users', 'timezone_name');
- $contributed_event_module = db_field_exists('users', 'timezone_id');
- $results = db_query_range("SELECT uid FROM {users} ORDER BY uid", $sandbox['user_from'], $count);
- foreach ($results as $account) {
- $timezone = NULL;
-
-
- if ($contributed_date_module) {
- $date_timezone = db_query("SELECT timezone_name FROM {users} WHERE uid = :uid", array(':uid' => $account->uid))->fetchField();
- if (isset($timezones[$date_timezone])) {
- $timezone = $date_timezone;
- }
- }
-
-
- if (!$timezone && $contributed_event_module) {
- try {
- $event_timezone = db_query("SELECT t.name FROM {users} u LEFT JOIN {event_timezones} t ON u.timezone_id = t.timezone WHERE u.uid = :uid", array(':uid' => $account->uid))->fetchField();
- $event_timezone = str_replace(' ', '_', $event_timezone);
- if (isset($timezones[$event_timezone])) {
- $timezone = $event_timezone;
- }
- }
- catch (PDOException $e) {
-
-
- }
- }
- if ($timezone) {
- db_update('users')
- ->fields(array('timezone' => $timezone))
- ->condition('uid', $account->uid)
- ->execute();
- }
- else {
- $sandbox['user_not_migrated']++;
- db_update('users')
- ->fields(array('timezone' => NULL))
- ->condition('uid', $account->uid)
- ->execute();
- }
- $sandbox['user_from']++;
- }
- $sandbox['#finished'] = $sandbox['user_from'] / $sandbox['user_count'];
- if ($sandbox['user_from'] == $sandbox['user_count']) {
- if ($sandbox['user_not_migrated'] > 0) {
- variable_set('empty_timezone_message', 1);
- drupal_set_message(format_string('Some user time zones have been emptied and need to be set to the correct values. Use the new <a href="@config-url">time zone options</a> to choose whether to remind users at login to set the correct time zone.', array('@config-url' => url('admin/config/regional/settings'))), 'warning');
- }
- return t('Migrated user time zones');
- }
- }
- }
- function user_update_7003() {
-
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- if ($setting = variable_get('user_mail_status_deleted_notify', FALSE)) {
- variable_set('user_mail_status_canceled_notify', $setting);
- variable_del('user_mail_status_deleted_notify');
- }
-
- if ($setting = variable_get('user_mail_status_deleted_subject', FALSE)) {
- variable_set('user_mail_status_canceled_subject', $setting);
- variable_del('user_mail_status_deleted_subject');
- }
- if ($setting = variable_get('user_mail_status_deleted_body', FALSE)) {
- variable_set('user_mail_status_canceled_body', $setting);
- variable_del('user_mail_status_deleted_body');
- }
- }
- function user_update_7005(&$sandbox) {
- $mail_field = array(
- 'type' => 'varchar',
- 'length' => 254,
- 'not null' => FALSE,
- 'default' => '',
- 'description' => "User's e-mail address.",
- );
- $init_field = array(
- 'type' => 'varchar',
- 'length' => 254,
- 'not null' => FALSE,
- 'default' => '',
- 'description' => 'E-mail address used for initial account creation.',
- );
- db_drop_index('users', 'mail');
- db_change_field('users', 'mail', 'mail', $mail_field, array('indexes' => array('mail' => array('mail'))));
- db_change_field('users', 'init', 'init', $init_field);
- }
- function user_update_7006(&$sandbox) {
- $module_field = array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "The module declaring the permission.",
- );
-
-
- if (!db_field_exists('role_permission', 'module')) {
-
- db_add_field('role_permission', 'module', $module_field);
- }
- }
- function user_update_7007() {
- db_add_field('role', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
- db_add_index('role', 'name_weight', array('name', 'weight'));
- }
- function user_update_7008() {
- if (!isset($GLOBALS['conf']['user_register'])) {
-
- variable_set('user_register', USER_REGISTER_VISITORS);
- }
- }
- function user_update_7009() {
- $spec = array(
- 'type' => 'blob',
- 'not null' => FALSE,
- 'size' => 'big',
- 'serialize' => TRUE,
- 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.',
- );
- db_change_field('users', 'data', 'data', $spec);
- }
- function user_update_7010() {
-
- db_change_field('users', 'signature_format', 'signature_format', array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the signature.',
- ));
-
-
-
-
-
-
-
-
-
-
- db_update('users')
- ->fields(array('signature_format' => NULL))
- ->condition('signature', '')
- ->condition('signature_format', 0)
- ->execute();
-
-
-
-
-
-
-
-
-
-
-
-
- $existing_formats = db_query("SELECT format FROM {filter_format}")->fetchCol();
- $default_format = variable_get('filter_default_format', 1);
- db_update('users')
- ->fields(array('signature_format' => $default_format))
- ->isNotNull('signature_format')
- ->condition('signature_format', $existing_formats, 'NOT IN')
- ->execute();
- }
- function user_update_7011() {
- }
- function user_update_7012(&$sandbox) {
- $picture_field = array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "Foreign key: {file_managed}.fid of user's picture.",
- );
- if (!isset($sandbox['progress'])) {
-
-
- if (!db_field_exists('users', 'picture_fid')) {
-
- db_add_field('users', 'picture_fid', $picture_field);
- }
-
- $sandbox['progress'] = 0;
- $sandbox['last_user_processed'] = -1;
- $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField();
- }
-
-
- $limit = 500;
- $result = db_query_range("SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed']));
- foreach ($result as $user) {
-
- if (file_exists($user->picture)) {
-
- $files = file_load_multiple(array(), array('uri' => $user->picture));
- if (count($files)) {
- $file = reset($files);
- }
- else {
-
- $file = new stdClass();
- $file->uri = $user->picture;
- $file->filename = drupal_basename($file->uri);
- $file->filemime = file_get_mimetype($file->uri);
- $file->uid = $user->uid;
- $file->status = FILE_STATUS_PERMANENT;
- $file = file_save($file);
- }
- db_update('users')
- ->fields(array('picture_fid' => $file->fid))
- ->condition('uid', $user->uid)
- ->execute();
- }
-
- $sandbox['progress']++;
- $sandbox['last_user_processed'] = $user->uid;
- }
-
-
- $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
-
-
- if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) {
- db_drop_field('users', 'picture');
- db_change_field('users', 'picture_fid', 'picture', $picture_field);
- }
- }
- function user_update_7013(&$sandbox) {
- if (!isset($sandbox['progress'])) {
-
- $sandbox['progress'] = 0;
- $sandbox['last_uid_processed'] = -1;
- $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} u WHERE u.picture <> 0")->fetchField();
- }
-
- $limit = 500;
- $result = db_query_range('SELECT f.*, u.uid as user_uid FROM {users} u INNER JOIN {file_managed} f ON u.picture = f.fid WHERE u.picture <> 0 AND u.uid > :uid ORDER BY u.uid', 0, $limit, array(':uid' => $sandbox['last_uid_processed']))->fetchAllAssoc('fid', PDO::FETCH_ASSOC);
- foreach ($result as $row) {
- $uid = $row['user_uid'];
- $file = (object) $row;
- file_usage_add($file, 'user', 'user', $uid);
-
- $sandbox['progress']++;
- $sandbox['last_uid_processed'] = $uid;
- }
-
- $sandbox['#finished'] = empty($sandbox['max']) || ($sandbox['progress'] / $sandbox['max']);
- }
- function user_update_7014() {
- db_update('role_permission')
- ->fields(array('permission' => 'skip comment approval'))
- ->condition('permission', 'post comments without approval')
- ->execute();
- return t("Renamed the 'post comments without approval' permission to 'skip comment approval'.");
- }
- function user_update_7015() {
- db_change_field('users', 'signature_format', 'signature_format', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the signature.',
- ));
- }
- function user_update_7016() {
-
- db_change_field('users', 'uid', 'uid', array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ));
- }
- function user_update_7017() {
- $message = '';
- $tokens = array(
- '!site' => '[site:name]',
- '!username' => '[user:name]',
- '!mailto' => '[user:mail]',
- '!login_uri' => '[site:login-url]',
- '!uri_brief' => '[site:url-brief]',
- '!edit_uri' => '[user:edit-url]',
- '!login_url' => '[user:one-time-login-url]',
- '!uri' => '[site:url]',
- '!date' => '[date:medium]',
- '!password' => '',
- );
- $result = db_select('variable', 'v')
- ->fields('v', array('name'))
- ->condition('name', db_like('user_mail_') . '%', 'LIKE')
- ->execute();
- foreach ($result as $row) {
-
- if ($value = variable_get($row->name, FALSE)) {
- if (empty($message) && (strpos($value, '!password') !== FALSE)) {
- $message = t('The ability to send users their passwords in plain text has been removed in Drupal 7. Your existing email templates have been modified to remove it. You should <a href="@template-url">review these templates</a> to make sure they read properly.', array('@template-url' => url('admin/config/people/accounts')));
- }
- variable_set($row->name, str_replace(array_keys($tokens), $tokens, $value));
- }
- }
- return $message;
- }
- function user_update_7018() {
- if (!db_index_exists('users', 'picture')) {
- db_add_index('users', 'picture', array('picture'));
- }
- }
|