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.
|
|
|
|
*/
|
|
|
|
|
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' => [
|
2012-11-27 22:26:22 +00:00
|
|
|
'description' => 'Primary key: {users}.uid for user.',
|
|
|
|
'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' => [
|
|
|
|
'uid' => ['users' => 'uid'],
|
|
|
|
],
|
|
|
|
];
|
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() {
|
2014-05-14 21:10:04 +00:00
|
|
|
$storage = \Drupal::entityManager()->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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|