realname.install 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for Realname module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function realname_schema() {
  10. $schema['realname'] = array(
  11. 'description' => 'Computed Real Names to reduce overhead.',
  12. 'fields' => array(
  13. 'uid' => array(
  14. 'description' => 'User ID, links to User table.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ),
  20. 'realname' => array(
  21. 'description' => 'The generated real name of the user.',
  22. 'type' => 'varchar',
  23. 'length' => 255,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. ),
  27. 'created' => array(
  28. 'description' => 'The UNIX timestamp of when the real name was created.',
  29. 'type' => 'int',
  30. 'unsigned' => TRUE,
  31. 'not null' => TRUE,
  32. 'default' => 0,
  33. ),
  34. ),
  35. 'primary key' => array('uid'),
  36. 'indexes' => array(
  37. 'realname' => array('realname'),
  38. ),
  39. 'foreign keys' => array(
  40. 'users' => array(
  41. 'table' => 'users',
  42. 'columns' => array('uid' => 'uid'),
  43. ),
  44. ),
  45. );
  46. return $schema;
  47. }
  48. /**
  49. * Implements hook_requirements().
  50. */
  51. function realname_requirements($phase) {
  52. $requirements = array();
  53. $t = get_t();
  54. if ($phase == 'runtime') {
  55. if (!variable_get('realname_suppress_user_name_mail_validation', FALSE) && strpos(variable_get('user_mail_register_admin_created_body', FALSE), '[user:name-raw]') === FALSE) {
  56. $requirements['user_mail_register_admin_created_body'] = array(
  57. 'title' => $t('E-mail: "Welcome (new user created by administrator)" template'),
  58. 'value' => $t('Not configured'),
  59. 'severity' => REQUIREMENT_WARNING,
  60. 'description' => $t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template, if using username for login.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-admin-created')))),
  61. );
  62. }
  63. if (!variable_get('realname_suppress_user_name_mail_validation', FALSE) && strpos(variable_get('user_mail_register_no_approval_required_body', FALSE), '[user:name-raw]') === FALSE) {
  64. $requirements['user_mail_register_no_approval_required_body'] = array(
  65. 'title' => $t('E-mail: "Welcome (no approval required)" template'),
  66. 'value' => $t('Not configured'),
  67. 'severity' => REQUIREMENT_WARNING,
  68. 'description' => $t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template, if using username for login.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-no-approval-required')))),
  69. );
  70. }
  71. if (!variable_get('realname_suppress_user_name_mail_validation', FALSE) && strpos(variable_get('user_mail_status_activated_body', FALSE), '[user:name-raw]') === FALSE) {
  72. $requirements['user_mail_status_activated_body'] = array(
  73. 'title' => $t('E-mail: "Account activation" template'),
  74. 'value' => $t('Not configured'),
  75. 'severity' => REQUIREMENT_WARNING,
  76. 'description' => $t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template, if using username for login.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-activated')))),
  77. );
  78. }
  79. }
  80. return $requirements;
  81. }
  82. /**
  83. * Implements hook_disable().
  84. */
  85. function realname_disable() {
  86. drupal_set_message(t('You need to replace the token <code>[user:name-raw]</code> with <code>[user:name]</code> in e-mail templates.'), 'warning');
  87. }
  88. /**
  89. * Implements hook_uninstall().
  90. */
  91. function realname_uninstall() {
  92. variable_del('realname_pattern');
  93. variable_del('realname_suppress_user_name_mail_validation');
  94. }
  95. /**
  96. * Update the {realname} table for Drupal 7.
  97. */
  98. function realname_update_7000() {
  99. // Add the {realname}.created field if it doesn't already exist.
  100. if (!db_field_exists('realname', 'created')) {
  101. $fields['created'] = array(
  102. 'description' => 'The UNIX timestamp of when the real name was created.',
  103. 'type' => 'int',
  104. 'unsigned' => TRUE,
  105. 'not null' => TRUE,
  106. 'default' => 0,
  107. );
  108. db_add_field('realname', 'created', $fields['created']);
  109. }
  110. $fields['realname'] = array(
  111. 'description' => 'The generated real name of the user.',
  112. 'type' => 'varchar',
  113. 'length' => '255',
  114. 'not null' => TRUE,
  115. 'default' => '',
  116. );
  117. db_change_field('realname', 'realname', 'realname', $fields['realname']);
  118. }
  119. /**
  120. * Remove variables from D6 that are no longer needed.
  121. */
  122. function realname_update_7001() {
  123. variable_del('realname_fields');
  124. variable_del('realname_homepage');
  125. variable_del('realname_max_username');
  126. variable_del('realname_myacct');
  127. variable_del('realname_nodeapi');
  128. variable_del('realname_nofollow');
  129. variable_del('realname_notver');
  130. variable_del('realname_profile_module');
  131. variable_del('realname_recalculate');
  132. variable_del('realname_search_enable');
  133. variable_del('realname_search_login');
  134. variable_del('realname_theme');
  135. variable_del('realname_user_disable');
  136. variable_del('realname_use_title');
  137. variable_del('realname_view');
  138. }