Skip to content

Commit 05b8014

Browse files
authored
Merge pull request #13 from DevDavido/development
Bump to v1.0.7
2 parents be94434 + 2c64162 commit 05b8014

File tree

13 files changed

+170
-34
lines changed

13 files changed

+170
-34
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Changelog
22

3+
## 1.0.7
4+
- Improved: Plugin check is now also running pre-checks first
5+
- Improved: Plugin check is now independent of regular audit flow
6+
- Improved: Wording in README text regarding tests
7+
- Fixed: Updates could remove Node dependencies which now get reinstalled
8+
39
## 1.0.6
4-
- Bugfix: Fixes file require bug from previous release
10+
- Fixed: Correct file require bug from previous release
511

612
## 1.0.5
713
- Added: Possibility to check plugin audit functionality

Controller.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ public function version()
4040
*/
4141
public function pluginCheck()
4242
{
43+
$plugin = new PerformanceAudit();
44+
45+
$error = '';
46+
try {
47+
$plugin->checkInternetAvailability();
48+
$plugin->checkDirectoriesWriteable();
49+
$plugin->checkNpm();
50+
$plugin->checkNpmDependencies();
51+
} catch (Exception $exception) {
52+
$error = $exception->getMessage();
53+
}
54+
4355
return $this->renderTemplate('pluginCheck', [
44-
'checkStartUrl' => (new Menu())->getUrlForAction('pluginCheckStart')
56+
'checkStartUrl' => (new Menu())->getUrlForAction('pluginCheckStart'),
57+
'error' => $error
4558
]);
4659
}
4760

PerformanceAudit.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function deactivate()
120120
* @return void
121121
* @throws DirectoryNotWriteableException
122122
*/
123-
private function checkDirectoriesWriteable()
123+
public function checkDirectoriesWriteable()
124124
{
125125
$directories = ['Audits', 'node_modules'];
126126
clearstatcache();
@@ -138,14 +138,29 @@ private function checkDirectoriesWriteable()
138138
* @return void
139139
* @throws DependencyUnexpectedResultException
140140
*/
141-
private function checkNpm()
141+
public function checkNpm()
142142
{
143143
$npmVersion = $this->checkDependency('npm', ['-v']);
144144
if ($npmVersion < self::MINIMUM_NPM_VERSION) {
145145
throw new DependencyUnexpectedResultException('npm needs to be at least v' . self::MINIMUM_NPM_VERSION . ' but v' . $npmVersion . ' is installed instead.');
146146
}
147147
}
148148

149+
/**
150+
* Check if Chrome is properly installed.
151+
*
152+
* @return void
153+
* @throws DependencyUnexpectedResultException
154+
*/
155+
public function checkNpmDependencies()
156+
{
157+
$lighthouse = new Lighthouse();
158+
$chromeVersion = $this->checkDependency($lighthouse->getChromePath(), ['--version']);
159+
if ($chromeVersion < self::MINIMUM_CHROME_VERSION) {
160+
throw new DependencyUnexpectedResultException('Chrome needs to be at least v' . self::MINIMUM_CHROME_VERSION . ' but v' . $chromeVersion . ' is installed instead.');
161+
}
162+
}
163+
149164
/**
150165
* Check if dependency is installed.
151166
*
@@ -190,21 +205,6 @@ private function installNpmDependencies()
190205
return trim($process->getOutput());
191206
}
192207

193-
/**
194-
* Check if Chrome is properly installed.
195-
*
196-
* @return void
197-
* @throws DependencyUnexpectedResultException
198-
*/
199-
private function checkNpmDependencies()
200-
{
201-
$lighthouse = new Lighthouse();
202-
$chromeVersion = $this->checkDependency($lighthouse->getChromePath(), ['--version']);
203-
if ($chromeVersion < self::MINIMUM_CHROME_VERSION) {
204-
throw new DependencyUnexpectedResultException('Chrome needs to be at least v' . self::MINIMUM_CHROME_VERSION . ' but v' . $chromeVersion . ' is installed instead.');
205-
}
206-
}
207-
208208
/**
209209
* Create log database table.
210210
*
@@ -282,7 +282,7 @@ public function requiresInternetConnection() {
282282
* @return void
283283
* @throws InternetUnavailableException
284284
*/
285-
private function checkInternetAvailability()
285+
public function checkInternetAvailability()
286286
{
287287
if ($this->requiresInternetConnection() && !SettingsPiwik::isInternetEnabled()) {
288288
throw new InternetUnavailableException('Internet needs to be enabled in order to use this plugin.');

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ If any errors occur during activation, please follow the instruction or informat
6363
For more screenshots, check out the [screenshot overview](/screenshots/OVERVIEW.md).
6464

6565
## Testing
66-
Run the tests with:
66+
Run the integration and unit tests with:
6767

6868
```shell
6969
./console tests:run PerformanceAudit

Tasks.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function auditSite(int $idSite, bool $debug = false)
8787
$this->logDebug('Debug mode enabled');
8888
}
8989

90-
if ($this->hasAnyTaskRunning()) {
90+
if ($this->hasAnyTaskRunning() && !$this->isInDebugMode()) {
9191
$this->logInfo('A Performance Audit task is currently already running');
9292
return;
9393
}
@@ -103,8 +103,10 @@ public function auditSite(int $idSite, bool $debug = false)
103103

104104
$this->logInfo('Performance Audit task for site ' . $idSite . ' will be started now');
105105
try {
106-
$this->markTaskAsRunning();
107-
$this->markTaskAsStartedToday($idSite);
106+
if (!$this->isInDebugMode()) {
107+
$this->markTaskAsRunning();
108+
$this->markTaskAsStartedToday($idSite);
109+
}
108110
$siteSettings = new MeasurableSettings($idSite);
109111

110112
$runs = range(1, (int) $siteSettings->getSetting('run_count')->getValue());
@@ -125,7 +127,9 @@ public function auditSite(int $idSite, bool $debug = false)
125127
} catch (Exception $exception) {
126128
$this->logError($exception->getMessage());
127129
} finally {
128-
$this->markTaskAsFinished();
130+
if (!$this->isInDebugMode()) {
131+
$this->markTaskAsFinished();
132+
}
129133
}
130134
$this->logInfo('Performance Audit task for site ' . $idSite . ' has finished');
131135
}
@@ -309,12 +313,13 @@ private function performAudits(int $idSite, array $urls, array $emulatedDevices,
309313

310314
self::getLighthouse($idSite)
311315
->setOutput(sprintf(
312-
'%s%s%d-%s-%s-%d.json',
316+
'%s%s%d-%s-%s-%s%d.json',
313317
__DIR__ . DIRECTORY_SEPARATOR,
314318
self::AUDIT_FOLDER . DIRECTORY_SEPARATOR,
315319
$idSite,
316320
$emulatedDevice,
317321
sha1($this->getUrlWithoutProtocolAndSubdomain($url, 'www')),
322+
($this->isInDebugMode()) ? 'debug-' : '',
318323
$run
319324
))
320325
->setEmulatedDevice($emulatedDevice)
@@ -344,7 +349,11 @@ private function getAuditFiles(int $idSite)
344349
),
345350
function ($file) use ($idSite) {
346351
$idSiteFile = intval(current(explode('-', $file->getFilename(), 2)));
347-
return $file->getExtension() === 'json' && $idSiteFile === $idSite;
352+
$isDebugFile = !!strstr($file->getFilename(), '-debug-');
353+
// Match if both booleans are logical equal
354+
$isInMatchingMode = !($this->isInDebugMode() XOR $isDebugFile);
355+
356+
return $file->getExtension() === 'json' && $idSiteFile === $idSite && $isInMatchingMode;
348357
}
349358
);
350359
}

Updates/1.0.7.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*/
8+
9+
namespace Piwik\Plugins\PerformanceAudit;
10+
11+
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';
12+
13+
use Piwik\Updater;
14+
15+
/**
16+
* Update for version 1.0.7.
17+
*/
18+
class Updates_1_0_7 extends BaseUpdate
19+
{
20+
/**
21+
* Perform the incremental version update.
22+
*
23+
* @param Updater $updater
24+
*/
25+
public function doUpdate(Updater $updater)
26+
{
27+
parent::doBaseUpdate($updater);
28+
}
29+
}

Updates/BaseUpdate.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*/
8+
9+
namespace Piwik\Plugins\PerformanceAudit;
10+
11+
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';
12+
13+
use Piwik\Plugin\Manager;
14+
use Piwik\Updater;
15+
use Piwik\Updates as PiwikUpdates;
16+
use Piwik\Updater\Migration;
17+
use Piwik\Updater\Migration\Factory as MigrationFactory;
18+
19+
/**
20+
* Base update.
21+
*/
22+
class BaseUpdate extends PiwikUpdates
23+
{
24+
/**
25+
* @var MigrationFactory
26+
*/
27+
private $migration;
28+
29+
public function __construct(MigrationFactory $factory)
30+
{
31+
$this->migration = $factory;
32+
}
33+
34+
/**
35+
* Return database migrations to be executed in this update.
36+
*
37+
* @param Updater $updater
38+
* @return Migration\Db[]
39+
*/
40+
public function getMigrations(Updater $updater)
41+
{
42+
return [];
43+
}
44+
45+
/**
46+
* Perform the base version update.
47+
*
48+
* @param Updater $updater
49+
*/
50+
public function doBaseUpdate(Updater $updater)
51+
{
52+
// Activation needed as node_modules are removed during update
53+
Manager::getInstance()->activatePlugin('PerformanceAudit');
54+
}
55+
}

lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"Report_TotalBlockingTime_Documentation_Information": "total blocking time",
3333
"Report_CumulativeLayoutShift_Documentation_Information": "cumulative layout shift",
3434
"PluginCheck": "Plugin Check",
35+
"PluginCheckAlertSystemIssue": "There is an issue with your system. The following error occurred:",
36+
"PluginCheckAlertNoSystemIssues": "All plugin pre-checks were successful, no errors occurred. You can now start the actual plugin check with a click on the following button:",
3537
"PluginCheckStartButton": "Start plugin check",
3638
"PluginCheckStartButtonClicked": "Plugin check started, please wait up to 5 minutes...",
3739
"PluginCheckLogOutput": "Log Output",

plugin.json

Lines changed: 1 addition & 1 deletion
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.0.6",
4+
"version": "1.0.7",
55
"theme": false,
66
"require": {
77
"php": ">=7.1.3",

stylesheets/pluginCheck.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
margin-top: 0;
99
}
1010

11+
.pluginsManagement .card-content .alert.no-margin-bottom {
12+
margin-bottom: 0;
13+
}
14+
1115
.pluginsManagement .performance-audit-log-output {
1216
overflow-y: auto;
1317
max-height: 336px;

0 commit comments

Comments
 (0)