contact.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the contact module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function contact_schema() {
  10. $schema['contact'] = array(
  11. 'description' => 'Contact form category settings.',
  12. 'fields' => array(
  13. 'cid' => array(
  14. 'type' => 'serial',
  15. 'unsigned' => TRUE,
  16. 'not null' => TRUE,
  17. 'description' => 'Primary Key: Unique category ID.',
  18. ),
  19. 'category' => array(
  20. 'type' => 'varchar',
  21. 'length' => 255,
  22. 'not null' => TRUE,
  23. 'default' => '',
  24. 'description' => 'Category name.',
  25. 'translatable' => TRUE,
  26. ),
  27. 'recipients' => array(
  28. 'type' => 'text',
  29. 'not null' => TRUE,
  30. 'size' => 'big',
  31. 'description' => 'Comma-separated list of recipient e-mail addresses.',
  32. ),
  33. 'reply' => array(
  34. 'type' => 'text',
  35. 'not null' => TRUE,
  36. 'size' => 'big',
  37. 'description' => 'Text of the auto-reply message.',
  38. ),
  39. 'weight' => array(
  40. 'type' => 'int',
  41. 'not null' => TRUE,
  42. 'default' => 0,
  43. 'description' => "The category's weight.",
  44. ),
  45. 'selected' => array(
  46. 'type' => 'int',
  47. 'not null' => TRUE,
  48. 'default' => 0,
  49. 'size' => 'tiny',
  50. 'description' => 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)',
  51. ),
  52. ),
  53. 'primary key' => array('cid'),
  54. 'unique keys' => array(
  55. 'category' => array('category'),
  56. ),
  57. 'indexes' => array(
  58. 'list' => array('weight', 'category'),
  59. ),
  60. );
  61. return $schema;
  62. }
  63. /**
  64. * Implements hook_install().
  65. */
  66. function contact_install() {
  67. // Insert a default contact category.
  68. db_insert('contact')
  69. ->fields(array(
  70. 'category' => 'Website feedback',
  71. 'recipients' => variable_get('site_mail', ini_get('sendmail_from')),
  72. 'selected' => 1,
  73. 'reply' => '',
  74. ))
  75. ->execute();
  76. }
  77. /**
  78. * Implements hook_uninstall().
  79. */
  80. function contact_uninstall() {
  81. variable_del('contact_default_status');
  82. variable_del('contact_threshold_limit');
  83. variable_del('contact_threshold_window');
  84. }
  85. /**
  86. * Implements hook_update_dependencies().
  87. */
  88. function contact_update_dependencies() {
  89. // contact_update_7001() relies on the {role_permission} table being updated
  90. // to the new format and filled with data.
  91. $dependencies['contact'][7001] = array(
  92. 'system' => 7007,
  93. );
  94. // contact_update_7002() relies on the {role_permission} table having the
  95. // module field, which is created in user_update_7006().
  96. $dependencies['contact'][7002] = array(
  97. 'user' => 7006,
  98. );
  99. return $dependencies;
  100. }
  101. /**
  102. * @addtogroup updates-6.x-to-7.x
  103. * @{
  104. */
  105. /**
  106. * Rename the threshold limit variable.
  107. */
  108. function contact_update_7000() {
  109. variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
  110. variable_del('contact_hourly_threshold');
  111. }
  112. /**
  113. * Rename the administer contact forms permission.
  114. */
  115. function contact_update_7001() {
  116. db_update('role_permission')
  117. ->fields(array('permission' => 'administer contact forms'))
  118. ->condition('permission', 'administer site-wide contact form')
  119. ->execute();
  120. }
  121. /**
  122. * Enable the 'access user contact forms' for registered users by default.
  123. */
  124. function contact_update_7002() {
  125. // Do not use user_role_grant_permission() since it relies on
  126. // hook_permission(), which will not run for contact module if it is
  127. // disabled.
  128. db_merge('role_permission')
  129. ->key(array(
  130. 'rid' => DRUPAL_AUTHENTICATED_RID,
  131. 'permission' => 'access user contact forms',
  132. 'module' => 'contact',
  133. ))
  134. ->execute();
  135. }
  136. /**
  137. * Change the weight column to normal int.
  138. */
  139. function contact_update_7003() {
  140. db_drop_index('contact', 'list');
  141. db_change_field('contact', 'weight', 'weight', array(
  142. 'type' => 'int',
  143. 'not null' => TRUE,
  144. 'default' => 0,
  145. 'description' => "The category's weight.",
  146. ), array(
  147. 'indexes' => array(
  148. 'list' => array('weight', 'category'),
  149. ),
  150. ));
  151. }
  152. /**
  153. * @} End of "addtogroup updates-6.x-to-7.x".
  154. */