honeypot.install 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Honeypot module.
  5. */
  6. /**
  7. * Implements of hook_schema().
  8. */
  9. function honeypot_schema() {
  10. $schema['honeypot_user'] = array(
  11. 'description' => 'Table that stores failed attempts to submit a form.',
  12. 'fields' => array(
  13. 'uid' => array(
  14. 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ),
  19. 'timestamp' => array(
  20. 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
  21. 'type' => 'int',
  22. 'unsigned' => TRUE,
  23. 'not null' => TRUE,
  24. ),
  25. ),
  26. 'indexes' => array(
  27. 'uid' => array('uid'),
  28. 'timestamp' => array('timestamp'),
  29. ),
  30. );
  31. return $schema;
  32. }
  33. /**
  34. * Implements hook_install().
  35. */
  36. function honeypot_install() {
  37. $t = get_t();
  38. drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
  39. '!link' => l($t('configure Honeypot'), 'admin/config/content/honeypot'),
  40. )));
  41. }
  42. /**
  43. * Implements hook_uninstall().
  44. */
  45. function honeypot_uninstall() {
  46. db_delete('variable')
  47. ->condition('name', db_like('honeypot_') . '%', 'LIKE')
  48. ->execute();
  49. $cache_tables = array('variables', 'cache_bootstrap');
  50. foreach ($cache_tables as $table) {
  51. if (db_table_exists($table)) {
  52. cache_clear_all($table, 'cache');
  53. }
  54. }
  55. }
  56. /**
  57. * Implements hook_update_N().
  58. */
  59. function honeypot_update_7001() {
  60. $ret = array();
  61. // Leaving this in because I had it in version 1.3. Silly me.
  62. return $ret;
  63. }
  64. /**
  65. * Update form names after upgrade from 6.x version.
  66. */
  67. function honeypot_update_7002() {
  68. $map = array(
  69. 'user_register' => 'user_register_form',
  70. 'contact_mail_page' => 'contact_site_form',
  71. 'contact_mail_user' => 'contact_personal_form',
  72. );
  73. foreach ($map as $d6_name => $d7_name) {
  74. $value = variable_get('honeypot_form_' . $d6_name, 0);
  75. if ($value) {
  76. variable_set('honeypot_form_' . $d7_name, $value);
  77. }
  78. variable_del('honeypot_form_' . $d6_name);
  79. }
  80. $comment_form_value = variable_get('honeypot_form_comment_form', 0);
  81. if ($comment_form_value) {
  82. $types = node_type_get_types();
  83. if (!empty($types)) {
  84. foreach ($types as $type) {
  85. $d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
  86. variable_set($d7_name, $comment_form_value);
  87. }
  88. }
  89. }
  90. variable_del('honeypot_form_comment_form');
  91. }
  92. /**
  93. * Add {honeypot_users} database table if it doesn't exist.
  94. */
  95. function honeypot_update_7003() {
  96. // Make sure the {honeypot_users} table doesn't already exist.
  97. if (!db_table_exists('honeypot_user')) {
  98. $table = array(
  99. 'description' => 'Table that stores failed attempts to submit a form.',
  100. 'fields' => array(
  101. 'uid' => array(
  102. 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
  103. 'type' => 'int',
  104. 'unsigned' => TRUE,
  105. 'not null' => TRUE,
  106. ),
  107. 'timestamp' => array(
  108. 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
  109. 'type' => 'int',
  110. 'unsigned' => TRUE,
  111. 'not null' => TRUE,
  112. ),
  113. ),
  114. 'indexes' => array(
  115. 'uid' => array('uid'),
  116. 'timestamp' => array('timestamp'),
  117. ),
  118. );
  119. db_create_table('honeypot_user', $table);
  120. }
  121. }