user.install 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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' => 'The {users}.uid this record affects.',
  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. 'data_user' => [
  55. 'table' => 'users',
  56. 'columns' => [
  57. 'uid' => 'uid',
  58. ],
  59. ],
  60. ],
  61. ];
  62. return $schema;
  63. }
  64. /**
  65. * Implements hook_install().
  66. */
  67. function user_install() {
  68. $storage = \Drupal::entityTypeManager()->getStorage('user');
  69. // Insert a row for the anonymous user.
  70. $storage
  71. ->create([
  72. 'uid' => 0,
  73. 'status' => 0,
  74. 'name' => '',
  75. ])
  76. ->save();
  77. // We need some placeholders here as name and mail are unique.
  78. // This will be changed by the settings form in the installer.
  79. $storage
  80. ->create([
  81. 'uid' => 1,
  82. 'name' => 'placeholder-for-uid-1',
  83. 'mail' => 'placeholder-for-uid-1',
  84. 'status' => TRUE,
  85. ])
  86. ->save();
  87. }
  88. /**
  89. * Fix invalid token in the status_blocked email body.
  90. */
  91. function user_update_8100() {
  92. $config_factory = \Drupal::configFactory();
  93. $config = $config_factory->getEditable('user.mail');
  94. $mail = $config->get('status_blocked');
  95. if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
  96. $mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
  97. $config->set('status_blocked', $mail)->save(TRUE);
  98. }
  99. }