-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhoneypot.install
74 lines (68 loc) · 1.9 KB
/
honeypot.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* @file
* Contains install and update functions for Honeypot.
*/
use Drupal\Core\Url;
/**
* Implements hook_schema().
*/
function honeypot_schema() {
$schema['honeypot_user'] = [
'description' => 'Table that stores failed attempts to submit a form.',
'fields' => [
'uid' => [
'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'hostname' => [
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'Hostname of user that that triggered honeypot.',
],
'timestamp' => [
'description' => 'Date/time when the form submission failed, as Unix timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
'indexes' => [
'uid' => ['uid'],
'timestamp' => ['timestamp'],
],
];
return $schema;
}
/**
* Implements hook_install().
*/
function honeypot_install() {
if (PHP_SAPI !== 'cli') {
$config_url = Url::fromUri('base://admin/config/content/honeypot');
\Drupal::messenger()->addMessage(t(
'Honeypot installed successfully. Please <a href=":url">configure Honeypot</a> to protect your forms from spam bots.',
[':url' => $config_url->toString()]
));
}
}
/**
* Implements hook_uninstall().
*/
function honeypot_uninstall() {
// Clear the bootstrap cache.
\Drupal::cache('bootstrap')->deleteAll();
\Drupal::configFactory()->getEditable('honeypot.settings.yml')->delete();
}
/**
* Adds the 'hostname' column to the {honeypot_user} table.
*/
function honeypot_update_8100() {
$schema = honeypot_schema();
$spec = $schema['honeypot_user']['fields']['hostname'];
$spec['initial'] = '';
\Drupal::database()->schema()->addField('honeypot_user', 'hostname', $spec);
}