Repository navigation
Expand file tree
/
Copy pathpendulum_arc.install
More file actions
106 lines (99 loc) · 2.57 KB
/
Copy pathpendulum_arc.install
File metadata and controls
106 lines (99 loc) · 2.57 KB
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
<?php
/**
* @file
* Install, update, and uninstall functions for Pendulum Arc.
*/
declare(strict_types=1);
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*/
function pendulum_arc_install(): void {
$role = Role::load('administrator');
if ($role && !$role->isAdmin() && !$role->hasPermission('administer pendulum arc')) {
$role->grantPermission('administer pendulum arc');
$role->save();
}
}
/**
* Implements hook_uninstall().
*/
function pendulum_arc_uninstall(): void {
\Drupal::state()->delete('pendulum_arc.connection');
\Drupal::state()->delete('pendulum_arc.consent');
\Drupal::keyValueExpirable('pendulum_arc')->deleteAll();
$schema = \Drupal::database()->schema();
if ($schema->tableExists('pendulum_arc_consent_log')) {
$schema->dropTable('pendulum_arc_consent_log');
}
}
/**
* Consent log. Settings live in state, not in this schema.
*/
function pendulum_arc_schema(): array {
return [
'pendulum_arc_consent_log' => [
'description' => 'Local cookie consent choices.',
'fields' => [
'id' => [
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'created_gmt' => [
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => '',
],
'consent_version' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'action' => [
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '',
],
'allowed' => [
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
],
'refused' => [
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
],
'ip' => [
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
'default' => '',
],
'user_agent' => [
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
'default' => '',
],
],
'primary key' => ['id'],
'indexes' => [
'created_gmt' => ['created_gmt'],
],
],
];
}
/**
* Creates the consent log table on installs that predate the banner.
*/
function pendulum_arc_update_8001(): void {
$schema = \Drupal::database()->schema();
if (!$schema->tableExists('pendulum_arc_consent_log')) {
$schema->createTable('pendulum_arc_consent_log', pendulum_arc_schema()['pendulum_arc_consent_log']);
}
}