-
Notifications
You must be signed in to change notification settings - Fork 5
/
matomo.install
124 lines (110 loc) · 3.27 KB
/
matomo.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
<?php
/**
* @file
* Installation file for Matomo Analytics module.
*/
function matomo_install() {
// Make the default install more user and GDPR friendly.
user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, array('opt-in or out of matomo tracking'));
backdrop_set_message(t('Module %module granted %permission permission to authenticated users.', array('%module' => 'Matomo Analytics', '%permission' => t('Opt-in or out of tracking'))), 'status');
}
function matomo_uninstall() {
$config = config('matomo.settings');
$config->delete();
}
/**
* Remove cache directory if module is disabled (or uninstalled).
*/
function matomo_disable() {
matomo_clear_js_cache();
}
/**
* Implementation of hook_requirements().
*/
function matomo_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'runtime':
// Module cannot validate matomo URL without external HTTP requests.
if (!_matomo_check_http_request()) {
$requirements['matomo_http_requests'] = array(
'title' => $t('HTTP request status'),
'value' => $t('Fails'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Your system or network configuration does not allow Backdrop to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP.'),
);
}
// Raise warning if Matomo user account has not been set yet.
if (empty(config_get('matomo.settings', 'site_id'))) {
$requirements['matomo'] = array(
'title' => $t('Matomo module'),
'description' => $t('Matomo module has not been configured yet. Please configure its settings from the <a href="@url">Matomo settings page</a>.', array('@url' => url('admin/config/system/matomo'))),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Not configured'),
);
}
break;
}
return $requirements;
}
/**
* Move Matomo settings from variables to config.
*/
function matomo_update_1000() {
$config = config('matomo.settings');
$settings = array(
'site_id',
'url_http',
'url_https',
'domain_mode',
'visibility_pages',
'visibility_roles',
'roles',
'custom',
'trackuserid',
'trackmailto',
'track',
'trackfiles_extensions',
'trackcolorbox',
'trackmessages',
'site_search',
'privacy_donottrack',
'page_title_hierarchy',
'page_title_hierarchy_exclude_home',
'custom_var',
'cache',
'last_cache',
'translation_set',
'codesnippet_before',
'codesnippet_after',
'js_scope',
'pages',
);
foreach ($settings as $setting_name) {
$config->set($setting_name, update_variable_get('matomo_' . $setting_name));
update_variable_del('matomo_' . $setting_name);
}
$config->save();
}
/**
* Add the noscript setting.
*/
function matomo_update_1001() {
$config = config('matomo.settings');
$noscript = $config->get('noscript');
if (!isset($noscript)) {
$config->set('noscript', 0);
$config->save();
}
}
/**
* Change last_cache setting to state.
*/
function matomo_update_1002() {
$config = config('matomo.settings');
$last_cache = $config->get('last_cache');
$config->clear('last_cache');
$config->save();
state_set('matomo_last_cache', $last_cache);
}