2007-10-05 16:07:22 +00:00
|
|
|
<?php
|
|
|
|
|
2009-05-13 19:42:18 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the user module.
|
|
|
|
*/
|
|
|
|
|
2022-11-09 11:08:57 +00:00
|
|
|
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
|
|
|
|
2007-10-05 16:07:22 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2007-10-05 16:07:22 +00:00
|
|
|
*/
|
|
|
|
function user_schema() {
|
2017-03-04 01:20:24 +00:00
|
|
|
$schema['users_data'] = [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'Stores module data as key/value pairs per user.',
|
2017-03-04 01:20:24 +00:00
|
|
|
'fields' => [
|
|
|
|
'uid' => [
|
2018-11-05 13:07:51 +00:00
|
|
|
'description' => 'The {users}.uid this record affects.',
|
2012-11-27 22:26:22 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'module' => [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'The name of the module declaring the variable.',
|
2015-05-05 16:42:09 +00:00
|
|
|
'type' => 'varchar_ascii',
|
2013-06-19 09:14:55 +00:00
|
|
|
'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
|
2012-11-27 22:26:22 +00:00
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'name' => [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'The identifier of the data.',
|
2015-05-05 16:42:09 +00:00
|
|
|
'type' => 'varchar_ascii',
|
2012-11-27 22:26:22 +00:00
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'value' => [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'The value.',
|
|
|
|
'type' => 'blob',
|
|
|
|
'not null' => FALSE,
|
|
|
|
'size' => 'big',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'serialized' => [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'Whether value is serialized.',
|
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'default' => 0,
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'primary key' => ['uid', 'module', 'name'],
|
|
|
|
'indexes' => [
|
|
|
|
'module' => ['module'],
|
|
|
|
'name' => ['name'],
|
|
|
|
],
|
|
|
|
'foreign keys' => [
|
2018-11-08 14:08:28 +00:00
|
|
|
'data_user' => [
|
|
|
|
'table' => 'users',
|
|
|
|
'columns' => [
|
|
|
|
'uid' => 'uid',
|
|
|
|
],
|
|
|
|
],
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
];
|
2012-11-27 22:26:22 +00:00
|
|
|
|
2007-10-05 16:07:22 +00:00
|
|
|
return $schema;
|
|
|
|
}
|
|
|
|
|
2010-03-01 07:39:12 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_install().
|
|
|
|
*/
|
|
|
|
function user_install() {
|
2019-05-24 06:44:36 +00:00
|
|
|
$storage = \Drupal::entityTypeManager()->getStorage('user');
|
2010-03-01 07:39:12 +00:00
|
|
|
// Insert a row for the anonymous user.
|
2014-05-14 21:10:04 +00:00
|
|
|
$storage
|
2017-03-04 01:20:24 +00:00
|
|
|
->create([
|
2010-03-01 07:39:12 +00:00
|
|
|
'uid' => 0,
|
2014-05-14 21:10:04 +00:00
|
|
|
'status' => 0,
|
Issue #2349819 by amateescu, swentel, Leksat, larowlan, dawehner, Gábor Hojtsy, mpdonadio, benjy, jmuzz, yched, jibran, marthinal, dmsmidt: String field type doesn't consider empty string as empty value
2015-08-20 19:15:48 +00:00
|
|
|
'name' => '',
|
2017-03-04 01:20:24 +00:00
|
|
|
])
|
2014-05-14 21:10:04 +00:00
|
|
|
->save();
|
2010-03-01 07:39:12 +00:00
|
|
|
|
2015-04-02 10:59:11 +00:00
|
|
|
// We need some placeholders here as name and mail are unique.
|
2013-12-23 20:55:44 +00:00
|
|
|
// This will be changed by the settings form in the installer.
|
2014-05-14 21:10:04 +00:00
|
|
|
$storage
|
2017-03-04 01:20:24 +00:00
|
|
|
->create([
|
2010-03-01 07:39:12 +00:00
|
|
|
'uid' => 1,
|
|
|
|
'name' => 'placeholder-for-uid-1',
|
|
|
|
'mail' => 'placeholder-for-uid-1',
|
2014-06-09 00:07:03 +00:00
|
|
|
'status' => TRUE,
|
2017-03-04 01:20:24 +00:00
|
|
|
])
|
2014-05-14 21:10:04 +00:00
|
|
|
->save();
|
2010-03-01 07:39:12 +00:00
|
|
|
}
|
2016-02-01 10:08:41 +00:00
|
|
|
|
|
|
|
/**
|
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
|
|
|
* Implements hook_update_last_removed().
|
2016-02-01 10:08:41 +00:00
|
|
|
*/
|
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
|
|
|
function user_update_last_removed() {
|
2022-02-08 12:16:18 +00:00
|
|
|
return 9301;
|
2021-08-06 09:55:59 +00:00
|
|
|
}
|
2022-11-09 11:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove non-existent permissions created by migrations.
|
|
|
|
*/
|
|
|
|
function user_update_10000() {
|
|
|
|
$cleaned_roles = [];
|
|
|
|
$existing_permissions = array_keys(\Drupal::service('user.permissions')
|
|
|
|
->getPermissions());
|
|
|
|
$config_factory = \Drupal::configFactory();
|
|
|
|
$role_ids = $config_factory->listAll('user.role.');
|
|
|
|
foreach ($role_ids as $role_id) {
|
|
|
|
$role_config = $config_factory->getEditable($role_id);
|
|
|
|
$removed_permissions = array_diff($role_config->get('permissions'), $existing_permissions);
|
|
|
|
if (!empty($removed_permissions)) {
|
|
|
|
$cleaned_roles[] = $role_config->get('label');
|
|
|
|
\Drupal::logger('update')->notice(
|
|
|
|
'The role %role has had the following non-existent permission(s) removed: %permissions.',
|
|
|
|
[
|
|
|
|
'%role' => $role_config->get('label'),
|
|
|
|
'%permissions' => implode(', ', $removed_permissions),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$permissions = array_intersect($role_config->get('permissions'), $existing_permissions);
|
|
|
|
$role_config->set('permissions', $permissions);
|
|
|
|
$role_config->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($cleaned_roles)) {
|
|
|
|
return new PluralTranslatableMarkup(
|
|
|
|
count($cleaned_roles),
|
|
|
|
'The role %role_list has had non-existent permissions removed. Check the logs for details.',
|
|
|
|
'The roles %role_list have had non-existent permissions removed. Check the logs for details.',
|
|
|
|
['%role_list' => implode(', ', $cleaned_roles)]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|