Projet

Général

Profil

Paste
Télécharger (3,47 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / honeypot / honeypot.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the Honeypot module.
6
 */
7

    
8
/**
9
 * Implements of hook_schema().
10
 */
11
function honeypot_schema() {
12
  $schema['honeypot_user'] = array(
13
    'description' => 'Table that stores failed attempts to submit a form.',
14
    'fields' => array(
15
      'uid' => array(
16
        'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
17
        'type' => 'int',
18
        'unsigned' => TRUE,
19
        'not null' => TRUE,
20
      ),
21
      'timestamp' => array(
22
        'description' => 'Date/time when the form submission failed, as Unix timestamp.',
23
        'type' => 'int',
24
        'unsigned' => TRUE,
25
        'not null' => TRUE,
26
      ),
27
    ),
28
    'indexes' => array(
29
      'uid' => array('uid'),
30
      'timestamp' => array('timestamp'),
31
    ),
32
  );
33
  return $schema;
34
}
35

    
36
/**
37
 * Implements hook_install().
38
 */
39
function honeypot_install() {
40
  $t = get_t();
41
  drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
42
    '!link' => l($t('configure Honeypot'), 'admin/config/content/honeypot'),
43
  )));
44
}
45

    
46
/**
47
 * Implements hook_uninstall().
48
 */
49
function honeypot_uninstall() {
50
  db_delete('variable')
51
    ->condition('name', db_like('honeypot_') . '%', 'LIKE')
52
    ->execute();
53
  $cache_tables = array('variables', 'cache_bootstrap');
54
  foreach ($cache_tables as $table) {
55
    if (db_table_exists($table)) {
56
      cache_clear_all($table, 'cache');
57
    }
58
  }
59
}
60

    
61
/**
62
 * Implements hook_update_N().
63
 */
64
function honeypot_update_7001() {
65
  $ret = array();
66

    
67
  // Leaving this in because I had it in version 1.3. Silly me.
68
  return $ret;
69
}
70

    
71
/**
72
 * Update form names after upgrade from 6.x version.
73
 */
74
function honeypot_update_7002() {
75
  $map = array(
76
    'user_register' => 'user_register_form',
77
    'contact_mail_page' => 'contact_site_form',
78
    'contact_mail_user' => 'contact_personal_form',
79
  );
80
  foreach ($map as $d6_name => $d7_name) {
81
    $value = variable_get('honeypot_form_' . $d6_name, 0);
82
    if ($value) {
83
      variable_set('honeypot_form_' . $d7_name, $value);
84
    }
85
    variable_del('honeypot_form_' . $d6_name);
86
  }
87

    
88
  $comment_form_value = variable_get('honeypot_form_comment_form', 0);
89
  if ($comment_form_value) {
90
    $types = node_type_get_types();
91
    if (!empty($types)) {
92
      foreach ($types as $type) {
93
        $d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
94
        variable_set($d7_name, $comment_form_value);
95
      }
96
    }
97
  }
98
  variable_del('honeypot_form_comment_form');
99
}
100

    
101
/**
102
 * Add {honeypot_users} database table if it doesn't exist.
103
 */
104
function honeypot_update_7003() {
105
  // Make sure the {honeypot_users} table doesn't already exist.
106
  if (!db_table_exists('honeypot_user')) {
107
    $table = array(
108
      'description' => 'Table that stores failed attempts to submit a form.',
109
      'fields' => array(
110
        'uid' => array(
111
          'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
112
          'type' => 'int',
113
          'unsigned' => TRUE,
114
          'not null' => TRUE,
115
        ),
116
        'timestamp' => array(
117
          'description' => 'Date/time when the form submission failed, as Unix timestamp.',
118
          'type' => 'int',
119
          'unsigned' => TRUE,
120
          'not null' => TRUE,
121
        ),
122
      ),
123
      'indexes' => array(
124
        'uid' => array('uid'),
125
        'timestamp' => array('timestamp'),
126
      ),
127
    );
128

    
129
    db_create_table('honeypot_user', $table);
130
  }
131
}