-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_metrics.install
136 lines (128 loc) · 2.88 KB
/
entity_metrics.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @file
* Install file for the Entity Metrics.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_install().
*/
function entity_metrics_install() {
$schema = [
'fields' => [
'id' => [
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'entity_type' => [
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'entity_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'timestamp' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'session_id' => [
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'ip_address' => [
'type' => 'varchar',
'length' => 45,
],
'region_id' => [
'type' => 'int',
'unsigned' => TRUE,
],
'cookie_set' => [
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['id'],
'indexes' => [
'entity' => ['entity_type', 'entity_id'],
'timestamp' => ['timestamp'],
],
'foreign keys' => [
'region_id' => [
'table' => 'entity_metrics_regions',
'columns' => ['region_id'],
'references' => ['id'],
],
],
];
Database::getConnection()->schema()->createTable('entity_metrics_data', $schema);
$schema = [
'fields' => [
'id' => [
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'country' => [
'type' => 'varchar',
'length' => 255,
],
'region' => [
'type' => 'varchar',
'length' => 255,
],
'city' => [
'type' => 'varchar',
'length' => 255,
],
'latitude' => [
'type' => 'numeric',
'precision' => 10,
'scale' => 8,
],
'longitude' => [
'type' => 'numeric',
'precision' => 11,
'scale' => 8,
],
],
'primary key' => ['id'],
'indexes' => [
'country' => ['country'],
],
];
Database::getConnection()->schema()->createTable('entity_metrics_regions', $schema);
}
/**
* Implements hook_uninstall().
*/
function entity_metrics_uninstall() {
Database::getConnection()->schema()->dropTable('entity_metrics_data');
Database::getConnection()->schema()->dropTable('entity_metrics_regions');
}
/**
* Add cookie_set field.
*/
function entity_metrics_update_10001() {
$schema = \Drupal::database()->schema();
if (!$schema->tableExists('entity_metrics_data')) {
return;
}
if ($schema->fieldExists('entity_metrics_data', 'cookie_set')) {
return;
}
$schema->addField('entity_metrics_data', 'cookie_set', [
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
]);
}