user.install 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the user module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function user_schema() {
  10. $schema['users_data'] = [
  11. 'description' => 'Stores module data as key/value pairs per user.',
  12. 'fields' => [
  13. 'uid' => [
  14. 'description' => 'Primary key: {users}.uid for user.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ],
  20. 'module' => [
  21. 'description' => 'The name of the module declaring the variable.',
  22. 'type' => 'varchar_ascii',
  23. 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. ],
  27. 'name' => [
  28. 'description' => 'The identifier of the data.',
  29. 'type' => 'varchar_ascii',
  30. 'length' => 128,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ],
  34. 'value' => [
  35. 'description' => 'The value.',
  36. 'type' => 'blob',
  37. 'not null' => FALSE,
  38. 'size' => 'big',
  39. ],
  40. 'serialized' => [
  41. 'description' => 'Whether value is serialized.',
  42. 'type' => 'int',
  43. 'size' => 'tiny',
  44. 'unsigned' => TRUE,
  45. 'default' => 0,
  46. ],
  47. ],
  48. 'primary key' => ['uid', 'module', 'name'],
  49. 'indexes' => [
  50. 'module' => ['module'],
  51. 'name' => ['name'],
  52. ],
  53. 'foreign keys' => [
  54. 'uid' => ['users' => 'uid'],
  55. ],
  56. ];
  57. return $schema;
  58. }
  59. /**
  60. * Implements hook_install().
  61. */
  62. function user_install() {
  63. $storage = \Drupal::entityManager()->getStorage('user');
  64. // Insert a row for the anonymous user.
  65. $storage
  66. ->create([
  67. 'uid' => 0,
  68. 'status' => 0,
  69. 'name' => '',
  70. ])
  71. ->save();
  72. // We need some placeholders here as name and mail are unique.
  73. // This will be changed by the settings form in the installer.
  74. $storage
  75. ->create([
  76. 'uid' => 1,
  77. 'name' => 'placeholder-for-uid-1',
  78. 'mail' => 'placeholder-for-uid-1',
  79. 'status' => TRUE,
  80. ])
  81. ->save();
  82. }
  83. /**
  84. * Fix invalid token in the status_blocked email body.
  85. */
  86. function user_update_8100() {
  87. $config_factory = \Drupal::configFactory();
  88. $config = $config_factory->getEditable('user.mail');
  89. $mail = $config->get('status_blocked');
  90. if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
  91. $mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
  92. $config->set('status_blocked', $mail)->save(TRUE);
  93. }
  94. }