-
Notifications
You must be signed in to change notification settings - Fork 34
/
Configuration.php
102 lines (84 loc) · 2.71 KB
/
Configuration.php
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\QueuedTracking;
use Piwik\Config;
class Configuration
{
public static $DEFAULT_NOTIFY_EMAILS = [];
public const DEFAULT_NOTIFY_THRESHOLD = 250000;
public const KEY_NOTIFY_EMAILS = 'notify_queue_threshold_emails';
public const KEY_NOTIFY_THRESHOLD = 'notify_queue_threshold_single_queue';
public const LOG_FAILED_TRACKING_REQUESTS = 'log_failed_tracking_request_body';
public const LOG_FAILED_TRACKING_REQUESTS_DEFAULT = 0;
public function install()
{
$config = $this->getConfig();
if (empty($config->QueuedTracking)) {
$config->QueuedTracking = array();
}
$reports = $config->QueuedTracking;
// we make sure to set a value only if none has been configured yet, eg in common config.
if (empty($reports[self::KEY_NOTIFY_THRESHOLD])) {
$reports[self::KEY_NOTIFY_THRESHOLD] = self::DEFAULT_NOTIFY_THRESHOLD;
}
if (empty($reports[self::KEY_NOTIFY_EMAILS])) {
$reports[self::KEY_NOTIFY_EMAILS] = self::$DEFAULT_NOTIFY_EMAILS;
}
$config->QueuedTracking = $reports;
$config->forceSave();
}
public function uninstall()
{
$config = $this->getConfig();
$config->QueuedTracking = array();
$config->forceSave();
}
/**
* @return int
*/
public function getNotifyThreshold()
{
$value = $this->getConfigValue(self::KEY_NOTIFY_THRESHOLD, self::DEFAULT_NOTIFY_THRESHOLD);
if ($value === false || $value === '' || $value === null) {
$value = self::DEFAULT_NOTIFY_THRESHOLD;
}
return (int) $value;
}
/**
* @return array
*/
public function getNotifyEmails()
{
$value = $this->getConfigValue(self::KEY_NOTIFY_EMAILS, self::$DEFAULT_NOTIFY_EMAILS);
if (empty($value)) {
$value = self::$DEFAULT_NOTIFY_EMAILS;
}
if (!is_array($value)) {
$value = array($value);
}
return $value;
}
public function shouldLogFailedTrackingRequestsBody(): bool
{
return (bool) $this->getConfigValue(self::LOG_FAILED_TRACKING_REQUESTS, self::LOG_FAILED_TRACKING_REQUESTS_DEFAULT);
}
private function getConfig()
{
return Config::getInstance();
}
private function getConfigValue($name, $default)
{
$config = $this->getConfig();
$attribution = $config->QueuedTracking;
if (isset($attribution[$name])) {
return $attribution[$name];
}
return $default;
}
}