Skip to content

Commit 5370737

Browse files
authored
Merge pull request #27 from DevDavido/development
Bump to v1.1.2
2 parents 61c5e72 + b358f8f commit 5370737

14 files changed

+59
-10
lines changed

Archiver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function aggregateReport()
9696
$emulatedDevices = EmulatedDevice::getList(EmulatedDevice::Both);
9797

9898
foreach ($idSites as $idSite) {
99-
Log::info("Will process performance for website id = {$idSite}, period = {$period}");
99+
Log::info("Will process performance audit for website id = {$idSite}, period = {$period}");
100100
foreach ($metrics as $metric) {
101101
foreach ($emulatedDevices as $emulatedDevice) {
102102
$table = new DataTable();

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
- Added: Support for Matomo 4 🎉
44
- Updated: Bumped the minimum PHP version to 7.2.5 for this new major plugin version, just as Matomo 4 itself
55

6+
## 1.1.2
7+
- Added: Possibility to enable or disable audit for each site
8+
- Improved: Set timeout for installation process to 5 minutes
9+
610
## 1.1.1
711
- Added: Scheduled weekly clearing of task running flag (in case of unexpected audit cancellation)
812
- Added: Console command to clear task running flag

MeasurableSettings.php

+40-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
class MeasurableSettings extends BaseMeasurableSettings
2222
{
23+
/** @var Setting */
24+
public $isEnabled;
25+
26+
/** @var Setting */
27+
public $runCount;
28+
2329
/** @var Setting */
2430
public $emulatedDevice;
2531

@@ -35,9 +41,6 @@ class MeasurableSettings extends BaseMeasurableSettings
3541
/** @var Setting */
3642
public $extraHttpHeaderValue;
3743

38-
/** @var Setting */
39-
public $runCount;
40-
4144
/**
4245
* Initialise plugin settings.
4346
*
@@ -48,6 +51,7 @@ protected function init()
4851
{
4952
Piwik::checkUserHasSomeViewAccess();
5053

54+
$this->isEnabled = $this->makeIsEnabledSetting();
5155
$this->runCount = $this->makeRunCountSetting();
5256
$this->emulatedDevice = $this->makeEmulatedDeviceSetting();
5357
$this->hasGroupedUrls = $this->makeHasGroupedUrlsSetting();
@@ -56,6 +60,21 @@ protected function init()
5660
$this->extraHttpHeaderValue = $this->makeExtraHttpHeaderValueSetting();
5761
}
5862

63+
/**
64+
* Create is enabled setting.
65+
*
66+
* @return MeasurableSetting
67+
* @throws ValidatorException|Exception
68+
*/
69+
private function makeIsEnabledSetting()
70+
{
71+
return $this->makeSetting('is_enabled', true, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
72+
$field->title = Piwik::translate('PerformanceAudit_Settings_IsEnabled_Title');
73+
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_IsEnabled_Help');
74+
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
75+
});
76+
}
77+
5978
/**
6079
* Create run count setting.
6180
*
@@ -67,6 +86,7 @@ private function makeRunCountSetting()
6786
return $this->makeSetting('run_count', 3, FieldConfig::TYPE_INT, function (FieldConfig $field) {
6887
$field->title = Piwik::translate('PerformanceAudit_Settings_RunCount_Title');
6988
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_RunCount_Help');
89+
$field->condition = 'is_enabled';
7090
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
7191
$field->validate = function ($value) {
7292
if (empty($value) && $value != 0) {
@@ -90,6 +110,7 @@ private function makeEmulatedDeviceSetting()
90110
return $this->makeSetting('emulated_device', EmulatedDevice::__default, FieldConfig::TYPE_STRING, function (FieldConfig $field) {
91111
$field->title = Piwik::translate('PerformanceAudit_Settings_EmulatedDevice_Title');
92112
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_EmulatedDevice_Help');
113+
$field->condition = 'is_enabled';
93114
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
94115
$field->availableValues = [
95116
EmulatedDevice::Desktop => ucfirst(Piwik::translate('PerformanceAudit_EnvironmentDesktop')),
@@ -118,6 +139,7 @@ private function makeHasGroupedUrlsSetting()
118139
return $this->makeSetting('has_grouped_urls', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
119140
$field->title = Piwik::translate('PerformanceAudit_Settings_HasGroupedUrls_Title');
120141
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_HasGroupedUrls_Help');
142+
$field->condition = 'is_enabled';
121143
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
122144
});
123145
}
@@ -133,6 +155,7 @@ private function makeHasExtraHttpHeaderSetting()
133155
return $this->makeSetting('has_extra_http_header', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
134156
$field->title = Piwik::translate('PerformanceAudit_Settings_HasExtraHttpHeader_Title');
135157
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_HasExtraHttpHeader_Help');
158+
$field->condition = 'is_enabled';
136159
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
137160
});
138161
}
@@ -150,14 +173,14 @@ private function makeExtraHttpHeaderKeySetting()
150173
return $this->makeSetting('extra_http_header_key', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($self) {
151174
$field->title = Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderKey_Title');
152175
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderKey_Help');
153-
$field->condition = 'has_extra_http_header';
176+
$field->condition = 'is_enabled && has_extra_http_header';
154177
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
155178
$field->availableValues = [
156179
'Authorization' => Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderKey_Authorization'),
157180
'Cookie' => Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderKey_Cookie'),
158181
];
159182
$field->validate = function ($value) use ($self, $field) {
160-
if ($self->getSetting($field->condition)->getValue()) {
183+
if ($self->getSetting('has_extra_http_header')->getValue()) {
161184
if (empty($value)) {
162185
throw new ValidatorException(Piwik::translate('General_ValidatorErrorEmptyValue'));
163186
}
@@ -182,10 +205,10 @@ private function makeExtraHttpHeaderValueSetting()
182205
return $this->makeSetting('extra_http_header_value', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($self) {
183206
$field->title = Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderValue_Title');
184207
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_ExtraHttpHeaderValue_Help');
185-
$field->condition = 'has_extra_http_header';
208+
$field->condition = 'is_enabled && has_extra_http_header';
186209
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
187210
$field->validate = function ($value) use ($self, $field) {
188-
if ($self->getSetting($field->condition)->getValue()) {
211+
if ($self->getSetting('has_extra_http_header')->getValue()) {
189212
if (empty($value)) {
190213
throw new ValidatorException(Piwik::translate('General_ValidatorErrorEmptyValue'));
191214
}
@@ -217,6 +240,16 @@ public function getEmulatedDevicesList()
217240
return EmulatedDevice::getList($this->getSetting('emulated_device')->getValue());
218241
}
219242

243+
/**
244+
* Returns if site has audits enabled or not.
245+
*
246+
* @return bool
247+
*/
248+
public function isAuditEnabled()
249+
{
250+
return $this->getSetting('is_enabled')->getValue();
251+
}
252+
220253
/**
221254
* Returns if site has grouped URLs for site.
222255
*

NodeDependencyInstaller.php

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private function installNpmDependencies()
145145
$npmPath = ExecutableFinder::search('npm');
146146
// Puppeteer + Lighthouse
147147
$process = new Process([$npmPath, 'install', '--quiet', '--no-progress', '--no-audit', '--force', '--only=production', '--prefix=' . __DIR__, 'puppeteer@^3.0', 'lighthouse@^6.0']);
148+
$process->setTimeout(300);
148149
$process->run();
149150

150151
if (!$process->isSuccessful()) {

Reports/GetPerformanceBase.php

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ protected function init()
4747
}
4848

4949
$siteSettings = new MeasurableSettings(Common::getRequestVar('idSite'));
50+
if (!$siteSettings->isAuditEnabled()) {
51+
return;
52+
}
5053
$defaultMetrics = [
5154
new MinSeconds(),
5255
new MedianSeconds(),

Tasks.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ public function auditSite(int $idSite, bool $debug = false)
119119
$this->logInfo('Performance Audit task for site ' . $idSite . ' has been already started today');
120120
return;
121121
}
122+
123+
$siteSettings = new MeasurableSettings($idSite);
124+
if (!$siteSettings->isAuditEnabled() && !$this->isInDebugMode()) {
125+
$this->logInfo('Performance Audit task for site ' . $idSite . ' will be skipped due to setting which disables it for this site');
126+
return;
127+
}
128+
122129
$urls = $this->getPageUrls($idSite, 'last30');
123130
if (empty($urls)) {
124131
$this->logWarning('Performance Audit task for site ' . $idSite . ' has no URLs to check');
@@ -134,7 +141,6 @@ public function auditSite(int $idSite, bool $debug = false)
134141
$this->markTaskAsRunning();
135142
$this->markTaskAsStartedToday($idSite);
136143
}
137-
$siteSettings = new MeasurableSettings($idSite);
138144

139145
$runs = $siteSettings->getRuns();
140146
$emulatedDevices = $siteSettings->getEmulatedDevicesList();

lang/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"Metrics_Max_Seconds_Documentation": "The upper boundary in seconds the page took in this performance category.",
6464
"Metrics_Tooltip": "%1$s%2$s is classified as %3$s! \n Values between %4$s%2$s – %5$s%2$s are in this classification group.",
6565
"Metrics_Tooltip_OutOfRange": "%s%s is out of range of all classification groups.",
66+
"Settings_IsEnabled_Title": "Perform performance audit for this site",
67+
"Settings_IsEnabled_Help": "You can decide on a per-website basis if website performance audits are performed after all.",
6668
"Settings_RunCount_Title": "Number of performance audit iterations",
6769
"Settings_RunCount_Help": "Set how many times the audit should be performed on each page for stable results. Any number between 1 and 5 is possible. 5 iterations are twice as stable, but prolongs the processing time the most. Just use such high values like 5 iterations only if enough server resources are generally available. 3 iterations are usually the best balance between reproducibility and resource consumption.",
6870
"Settings_EmulatedDevice_Title": "Performance simulation environment",

plugin.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "PerformanceAudit",
33
"description": "Daily performance audits of all your sites in Matomo.",
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"theme": false,
66
"require": {
77
"php": ">=7.1.3",

screenshots/Dashboard.png

-148 KB
Loading

screenshots/FirstContentfulPaint.png

-141 KB
Loading

screenshots/OverallScores.png

-139 KB
Loading
-50.9 KB
Loading
-216 KB
Loading

screenshots/WebsiteSettings.png

-108 KB
Loading

0 commit comments

Comments
 (0)