spambot.install 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Implementation of hook_schema().
  4. */
  5. function spambot_schema() {
  6. $schema = array();
  7. $schema['node_spambot'] = array(
  8. 'description' => t('Node table to track author IP addresses. For use by spambot only.'),
  9. 'fields' => array(
  10. 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  11. 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  12. 'hostname' => array( 'type' => 'varchar', 'length' => 128, 'not null' => FALSE),
  13. ),
  14. 'primary key' => array('nid'),
  15. 'indexes' => array(
  16. 'uid' => array('uid'),
  17. ),
  18. );
  19. return $schema;
  20. }
  21. /**
  22. * Implementation of hook_uninstall().
  23. */
  24. function spambot_uninstall() {
  25. db_query("DELETE FROM {variable} WHERE name LIKE 'spambot_%'");
  26. }
  27. /**
  28. * Migrate settings from previous version of spambot (6.x-2.0)
  29. */
  30. function spambot_update_6300() {
  31. $ret = array();
  32. // In previous versions of spambot, the default message was 'Blacklisted. Now go away!'
  33. // If no custom message was configured, then configure it to 'Blacklisted. Now go away!'
  34. $message = variable_get('spambot_blocked_message', FALSE);
  35. if (!$message) {
  36. variable_set('spambot_blocked_message', t('Blacklisted. Now go away!'));
  37. }
  38. // Previous versions of spambot blacklisted on any of the three criteria
  39. variable_set('spambot_criteria_email', TRUE);
  40. variable_set('spambot_criteria_username', TRUE);
  41. variable_set('spambot_criteria_ip', TRUE);
  42. return $ret;
  43. }
  44. function spambot_update_6301() {
  45. $ret = array();
  46. // Change criteria settings from booleans to numbers
  47. if (variable_set('spambot_criteria_email', TRUE)) {
  48. variable_set('spambot_criteria_email', 1);
  49. }
  50. if (variable_set('spambot_criteria_username', FALSE)) {
  51. variable_set('spambot_criteria_username', 1);
  52. }
  53. if (variable_set('spambot_criteria_ip', FALSE)) {
  54. variable_set('spambot_criteria_ip', 1);
  55. }
  56. return $ret;
  57. }
  58. function spambot_update_7101() {
  59. $messages = array();
  60. variable_del('spambot_user_register_report');
  61. $messages[] = t('Deleted variable <em>spambot_user_register_report.</em>');
  62. $message = variable_get('spambot_blocked_message', FALSE);
  63. if ($message !== FALSE) {
  64. variable_set('spambot_blocked_message_email', $message);
  65. variable_set('spambot_blocked_message_username', $message);
  66. variable_set('spambot_blocked_message_ip', $message);
  67. variable_del('spambot_blocked_message');
  68. $messages[] = t('Transferred user registration blocked message to new format.');
  69. }
  70. // Create new table node_spambot
  71. if (!db_table_exists('node_spambot')) {
  72. $schema = array();
  73. $schema['node_spambot'] = array(
  74. 'description' => t('Node table to track author IP addresses. For use by spambot only.'),
  75. 'fields' => array(
  76. 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  77. 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  78. 'hostname' => array( 'type' => 'varchar', 'length' => 128, 'not null' => FALSE),
  79. ),
  80. 'primary key' => array('nid'),
  81. 'indexes' => array(
  82. 'uid' => array('uid'),
  83. ),
  84. );
  85. db_create_table('node_spambot', $schema['node_spambot']);
  86. $messages[] = t('Created new table <em>node_spambot</em>.');
  87. }
  88. return join('<br />', $messages);
  89. }