2015-08-18 00:00:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the user module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_schema().
|
|
|
|
*/
|
|
|
|
function user_schema() {
|
2017-04-13 14:53:35 +00:00
|
|
|
$schema['users_data'] = [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'Stores module data as key/value pairs per user.',
|
2017-04-13 14:53:35 +00:00
|
|
|
'fields' => [
|
|
|
|
'uid' => [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'Primary key: {users}.uid for user.',
|
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2017-04-13 14:53:35 +00:00
|
|
|
],
|
|
|
|
'module' => [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'The name of the module declaring the variable.',
|
|
|
|
'type' => 'varchar_ascii',
|
|
|
|
'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2017-04-13 14:53:35 +00:00
|
|
|
],
|
|
|
|
'name' => [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'The identifier of the data.',
|
|
|
|
'type' => 'varchar_ascii',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2017-04-13 14:53:35 +00:00
|
|
|
],
|
|
|
|
'value' => [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'The value.',
|
|
|
|
'type' => 'blob',
|
|
|
|
'not null' => FALSE,
|
|
|
|
'size' => 'big',
|
2017-04-13 14:53:35 +00:00
|
|
|
],
|
|
|
|
'serialized' => [
|
2015-08-18 00:00:26 +00:00
|
|
|
'description' => 'Whether value is serialized.',
|
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'default' => 0,
|
2017-04-13 14:53:35 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'primary key' => ['uid', 'module', 'name'],
|
|
|
|
'indexes' => [
|
|
|
|
'module' => ['module'],
|
|
|
|
'name' => ['name'],
|
|
|
|
],
|
|
|
|
'foreign keys' => [
|
|
|
|
'uid' => ['users' => 'uid'],
|
|
|
|
],
|
|
|
|
];
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_install().
|
|
|
|
*/
|
|
|
|
function user_install() {
|
|
|
|
$storage = \Drupal::entityManager()->getStorage('user');
|
|
|
|
// Insert a row for the anonymous user.
|
|
|
|
$storage
|
2017-04-13 14:53:35 +00:00
|
|
|
->create([
|
2015-08-18 00:00:26 +00:00
|
|
|
'uid' => 0,
|
|
|
|
'status' => 0,
|
2015-09-04 20:20:09 +00:00
|
|
|
'name' => '',
|
2017-04-13 14:53:35 +00:00
|
|
|
])
|
2015-08-18 00:00:26 +00:00
|
|
|
->save();
|
|
|
|
|
|
|
|
// We need some placeholders here as name and mail are unique.
|
|
|
|
// This will be changed by the settings form in the installer.
|
|
|
|
$storage
|
2017-04-13 14:53:35 +00:00
|
|
|
->create([
|
2015-08-18 00:00:26 +00:00
|
|
|
'uid' => 1,
|
|
|
|
'name' => 'placeholder-for-uid-1',
|
|
|
|
'mail' => 'placeholder-for-uid-1',
|
|
|
|
'status' => TRUE,
|
2017-04-13 14:53:35 +00:00
|
|
|
])
|
2015-08-18 00:00:26 +00:00
|
|
|
->save();
|
|
|
|
}
|
2016-04-20 16:56:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fix invalid token in the status_blocked email body.
|
|
|
|
*/
|
|
|
|
function user_update_8100() {
|
|
|
|
$config_factory = \Drupal::configFactory();
|
|
|
|
$config = $config_factory->getEditable('user.mail');
|
|
|
|
$mail = $config->get('status_blocked');
|
|
|
|
if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
|
|
|
|
$mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
|
|
|
|
$config->set('status_blocked', $mail)->save(TRUE);
|
|
|
|
}
|
|
|
|
}
|