-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnexteuropa_varnish.install
182 lines (160 loc) · 4.78 KB
/
nexteuropa_varnish.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* @file
* Contains install and update functions for nexteuropa_varnish.
*/
include_once 'nexteuropa_varnish.helper.inc';
/**
* Implements hook_schema().
*/
function nexteuropa_varnish_schema() {
/*
* Nept-2055: Drush error while uninstall and enable the module.
* Here it is needed to have the constant "NEXTEUROPA_VARNISH_CACHE_TABLE"
* available, which it is defined within ".module" file.
*/
module_load_include('module', 'nexteuropa_varnish');
$schema = array();
$schema['nexteuropa_varnish_cache_purge_rule'] = array(
'description' => 'Purge rules',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique purge rule ID.',
),
'content_type' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'The machine name of the content type a rule applies for.',
),
'paths' => array(
'type' => 'text',
'description' => 'Paths to purge, one per line.',
),
),
'primary key' => array('id'),
);
$schema[NEXTEUROPA_VARNISH_CACHE_TABLE] = drupal_get_schema_unprocessed('system', 'cache');
$schema[NEXTEUROPA_VARNISH_CACHE_TABLE]['description'] = 'Cache table for the nexteuropa_varnish purge rules.';
return $schema;
}
/**
* Implements hook_requirements().
*
* At installation and run time phase, All Varnish feature settings' parameters
* must be set.
* The control status returns which parameters are missing.
*/
function nexteuropa_varnish_requirements($phase) {
$requirements = array();
$t = get_t();
$control_phase = array(
'install',
'runtime',
);
if (in_array($phase, $control_phase)) {
$required_vars = _nexteuropa_varnish_get_settings_item_names();
$settings = _nexteuropa_varnish_get_varnish_settings(FALSE);
foreach ($required_vars as $param_name => $var_item) {
if (empty($settings[$var_item])) {
$t_var = array('@var' => $param_name);
$requirements[$var_item] = array(
'title' => $t('NextEuropa Varnish: "@var" is missing', $t_var),
'description' => $t('"@var" must be set. Please ask your support team to check the server configuration.', $t_var),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
return $requirements;
}
/**
* Implements hook_enable().
*/
function nexteuropa_varnish_enable() {
$administrator = user_role_load_by_name('administrator');
if ($administrator) {
user_role_grant_permissions(
$administrator->rid,
array(
'administer frontend cache purge rules',
)
);
}
}
/**
* Implements hook_install().
*/
function nexteuropa_varnish_install() {
// Set the weight to 2. Pathauto has weight 1 and we need to react after it.
db_update('system')
->fields(array('weight' => 2))
->condition('type', 'module')
->condition('name', 'nexteuropa_varnish')
->execute();
// Enabling the default purge rule.
variable_set('nexteuropa_varnish_default_purge_rule', TRUE);
}
/**
* Implements hook_uninstall().
*/
function nexteuropa_varnish_uninstall() {
$vars = array(
'nexteuropa_varnish_default_purge_rule',
'nexteuropa_varnish_http_targets',
'nexteuropa_varnish_tag',
'nexteuropa_varnish_request_method',
);
foreach ($vars as $var) {
variable_del($var);
}
}
/**
* Add the cache purge rules table.
*/
function nexteuropa_varnish_update_7100() {
db_create_table(
'nexteuropa_varnish_cache_purge_rule',
array(
'description' => 'Purge rules',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique purge rule ID.',
),
'content_type' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'The machine name of the content type a rule applies for.',
),
'paths' => array(
'type' => 'text',
'description' => 'Paths to purge, one per line.',
),
),
'primary key' => array('id'),
)
);
}
/**
* Alter the module weight so it comes after pathauto.
*/
function nexteuropa_varnish_update_7101() {
db_update('system')
->fields(array('weight' => 2))
->condition('type', 'module')
->condition('name', 'nexteuropa_varnish')
->execute();
}
/**
* NEPT-799: Add cache table for the purge rules.
*/
function nexteuropa_varnish_update_7102() {
$schema[NEXTEUROPA_VARNISH_CACHE_TABLE] = drupal_get_schema_unprocessed('system', 'cache');
$schema[NEXTEUROPA_VARNISH_CACHE_TABLE]['description'] = 'Cache table for the purge rules of nexteuropa_varnish.';
db_create_table(NEXTEUROPA_VARNISH_CACHE_TABLE, $schema[NEXTEUROPA_VARNISH_CACHE_TABLE]);
}