Skip to content

Commit 9250d6b

Browse files
authored
Issue #39: change last_cache to state variable (#40)
1 parent 68141f0 commit 9250d6b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

config/matomo.settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"page_title_hierarchy_exclude_home": true,
2121
"custom_var": [],
2222
"cache": 0,
23-
"last_cache": 0,
2423
"translation_set": 0,
2524
"noscript": 0,
2625
"codesnippet_before": "",

matomo.install

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,15 @@ function matomo_update_1001() {
110110
$config->save();
111111
}
112112
}
113+
114+
/**
115+
* Change last_cache setting to state.
116+
*/
117+
function matomo_update_1002() {
118+
$config = config('matomo.settings');
119+
$last_cache = $config->get('last_cache');
120+
$config->clear('last_cache');
121+
$config->save();
122+
123+
state_set('matomo_last_cache', $last_cache);
124+
}

matomo.module

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,9 @@ function matomo_user_presave($account) {
468468
function matomo_cron() {
469469
$config = config('matomo.settings');
470470
// Regenerate the matomo.js every day.
471-
if (REQUEST_TIME - $config->get('last_cache') >= 86400 && $config->get('cache')) {
471+
if (REQUEST_TIME - state_get('matomo_last_cache', 0) >= 86400 && $config->get('cache')) {
472472
_matomo_cache($config->get('url_http') . 'matomo.js', TRUE);
473-
$config->set('last_cache', REQUEST_TIME);
474-
$config->save();
473+
state_set('matomo_last_cache', REQUEST_TIME);
475474
}
476475
}
477476

0 commit comments

Comments
 (0)