blob: e6a2d840135ef42020b28be82ce0a8df80b218fc (
plain)
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
|
<?php
/**
* Copyright (C) Piwik PRO - All rights reserved.
*
* Using this code requires that you first get a license from Piwik PRO.
* Unauthorized copying of this file, via any medium is strictly prohibited.
*
* @link http://piwik.pro
*/
namespace Piwik\Plugins\AutoLogImporter;
use Piwik\Common;
use Piwik\Settings\SystemSetting;
/**
* Defines Settings for AutoLogImporter.
*
* Usage like this:
* $settings = new Settings('AutoLogImporter');
* $settings->autoRefresh->getValue();
* $settings->metric->getValue();
*/
class Settings extends \Piwik\Plugin\Settings
{
/** @var SystemSetting */
public $enabled;
/** @var SystemSetting */
public $logFilesPath;
/** @var SystemSetting */
public $filePattern;
protected function init()
{
$this->createEnabledSetting();
$this->createLogFilesPathSetting();
$this->createFilePatternSetting();
}
private function createEnabledSetting()
{
$this->enabled = new SystemSetting('enabled', 'Enabled');
$this->enabled->type = static::TYPE_BOOL;
$this->enabled->uiControlType = static::CONTROL_CHECKBOX;
$this->enabled->defaultValue = false;
$this->addSetting($this->enabled);
}
private function createLogFilesPathSetting()
{
$this->logFilesPath = new SystemSetting('logFilesPath', 'Path to log files');
$this->logFilesPath->type = static::TYPE_STRING;
$this->logFilesPath->uiControlType = static::CONTROL_TEXT;
$self = $this;
$this->logFilesPath->validate = function ($value, $setting) use ($self) {
if (empty($value) && !$self->enabled->getValue()) {
// it is not enabled, an empty value is okay.
return;
}
if (empty($value)) {
throw new \Exception('A value must be specified');
}
if (!file_exists($value)) {
throw new \Exception('This path does not exist');
}
if (!is_dir($value)) {
throw new \Exception('Path is not a directory');
}
if (!is_readable($value)) {
throw new \Exception('This directory is not readable');
}
};
$this->logFilesPath->transform = function ($value) {
if (!empty($value) && Common::stringEndsWith($value, '/')) {
$value = substr($value, 0, -1);
}
return $value;
};
$this->logFilesPath->description = 'Defines the path to the log files.';
$this->addSetting($this->logFilesPath);
}
private function createFilePatternSetting()
{
$this->filePattern = new SystemSetting('filePattern', 'File Pattern');
$this->filePattern->type = static::TYPE_STRING;
$this->filePattern->uiControlType = static::CONTROL_TEXT;
$this->filePattern->defaultValue = '*.log';
$this->filePattern->description = 'If specified, only files matching this pattern will be imported.';
$this->filePattern->transform = function ($value) {
if (!empty($value)) {
return trim($value);
}
return '*';
};
$this->addSetting($this->filePattern);
}
}
|