user.install 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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'] = array(
  11. 'description' => 'Stores module data as key/value pairs per user.',
  12. 'fields' => array(
  13. 'uid' => array(
  14. 'description' => 'Primary key: {users}.uid for user.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ),
  20. 'module' => array(
  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' => array(
  28. 'description' => 'The identifier of the data.',
  29. 'type' => 'varchar_ascii',
  30. 'length' => 128,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ),
  34. 'value' => array(
  35. 'description' => 'The value.',
  36. 'type' => 'blob',
  37. 'not null' => FALSE,
  38. 'size' => 'big',
  39. ),
  40. 'serialized' => array(
  41. 'description' => 'Whether value is serialized.',
  42. 'type' => 'int',
  43. 'size' => 'tiny',
  44. 'unsigned' => TRUE,
  45. 'default' => 0,
  46. ),
  47. ),
  48. 'primary key' => array('uid', 'module', 'name'),
  49. 'indexes' => array(
  50. 'module' => array('module'),
  51. 'name' => array('name'),
  52. ),
  53. 'foreign keys' => array(
  54. 'uid' => array('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(array(
  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(array(
  76. 'uid' => 1,
  77. 'name' => 'placeholder-for-uid-1',
  78. 'mail' => 'placeholder-for-uid-1',
  79. 'status' => TRUE,
  80. ))
  81. ->save();
  82. }
  83. /**
  84. * @addtogroup updates-8.1.0-beta
  85. * @{
  86. */
  87. /**
  88. * Fix invalid token in the status_blocked email body.
  89. */
  90. function user_update_8100() {
  91. $config_factory = \Drupal::configFactory();
  92. $config = $config_factory->getEditable('user.mail');
  93. $mail = $config->get('status_blocked');
  94. if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
  95. $mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
  96. $config->set('status_blocked', $mail)->save(TRUE);
  97. }
  98. }
  99. /**
  100. * @} End of "addtogroup updates-8.1.0-beta".
  101. */