Skip to content

Commit

Permalink
fix: Matomo 5 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
DevDavido committed Dec 20, 2023
1 parent ae4a582 commit 42d9588
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Exception;
use Piwik\Archive;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Map;
use Piwik\DataTable\Row;
Expand All @@ -20,6 +19,7 @@
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MedianSeconds;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MinPercent;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MinSeconds;
use Piwik\Request;
use Piwik\Site;
use Piwik\UrlHelper;

Expand Down Expand Up @@ -363,7 +363,7 @@ private function setMetricTooltips($dataTable, string $dataTableName)
*/
private function disableTotalsRow($dataTable)
{
if ($dataTable instanceof DataTable && Common::getRequestVar('keep_totals_row', false)) {
if ($dataTable instanceof DataTable && Request::getBoolParameter('keep_totals_row', false)) {
$dataTable->setTotalsRow(new Row([
'label' => DataTable::LABEL_TOTALS_ROW
]));
Expand Down
7 changes: 4 additions & 3 deletions Archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Exception;
use Piwik\Common;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Date;
use Piwik\Db;
use Piwik\Log;
use Piwik\Log\Logger;
use Piwik\Period;
use Piwik\Plugin\Archiver as BaseArchiver;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\Audit;
Expand Down Expand Up @@ -69,7 +70,7 @@ public function aggregateMultipleReports()
public static function shouldRunEvenWhenNoVisits()
{
$deletedDuplicateCount = self::deleteArchiveDuplicates();
Log::debug($deletedDuplicateCount . ' archive entries got deleted');
StaticContainer::get(Logger::class)->debug($deletedDuplicateCount . ' archive entries got deleted');

return true;
}
Expand All @@ -89,7 +90,7 @@ private function aggregateReport()
$emulatedDevices = EmulatedDevice::getList(EmulatedDevice::Both);

foreach ($idSites as $idSite) {
Log::info("Will process performance audit for website id = {$idSite}, period = {$period}");
StaticContainer::get(Logger::class)->info("Will process performance audit for website id = {$idSite}, period = {$period}");
foreach ($metrics as $metric) {
foreach ($emulatedDevices as $emulatedDevice) {
$table = new DataTable();
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## 3.0.0-Beta1
- Added: Support for Matomo 5 🎉
- Updated: Bumped the minimum Node version to 20.x LTS for this new major plugin version
- Improved: Migrated some deprecated Matomo Plugin code

## 2.1.0
- Added: Site setting to group URLs by anchor which removes auditing duplicates of URLs which only differ in their anchors
- Added: Support to find latest Node executable in Plesk environment
Expand Down
22 changes: 11 additions & 11 deletions Commands/ClearTaskRunningFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace Piwik\Plugins\PerformanceAudit\Commands;

use Piwik\Log;
use Piwik\Container\StaticContainer;
use Piwik\Log\Logger;
use Piwik\Option;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\PerformanceAudit\Tasks;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ClearTaskRunningFlag extends ConsoleCommand
{
Expand All @@ -16,7 +15,7 @@ class ClearTaskRunningFlag extends ConsoleCommand
*
* @return void
*/
protected function configure()
protected function doInitialize(): void
{
$this->setName('performanceaudit:clear-task-running-flag');
$this->setDescription('Clear flag for currently running performance audit task');
Expand All @@ -25,20 +24,21 @@ protected function configure()
/**
* Execute command.
*
* @return void
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function doExecute(): int
{
$hasRunningTask = !!Option::get(Tasks::hasTaskRunningKey());
if ($hasRunningTask) {
Log::debug('Cleared task running flag manually now');
StaticContainer::get(Logger::class)->debug('Cleared task running flag manually now');
Option::delete(Tasks::hasTaskRunningKey());

$output->writeln('<info>Performance Audit running task flag was cleared successfully.</info>');
return;
$this->getOutput()->writeln('<info>Performance Audit running task flag was cleared successfully.</info>');
return self::SUCCESS;
}

Log::debug('No task running flag available to clear now');
$output->writeln('<info>Performance Audit running task flag was not set, so nothing to clear now.</info>');
StaticContainer::get(Logger::class)->debug('No task running flag available to clear now');
$this->getOutput()->writeln('<info>Performance Audit running task flag was not set, so nothing to clear now.</info>');
return self::SUCCESS;
}
}
5 changes: 3 additions & 2 deletions NodeDependencyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';

use Exception;
use Piwik\Log;
use Piwik\Container\StaticContainer;
use Piwik\Log\Logger;
use Piwik\Plugins\PerformanceAudit\Exceptions\DependencyNpmMisconfigurationException;
use Piwik\Plugins\PerformanceAudit\Exceptions\DependencyOfChromeMissingException;
use Piwik\Plugins\PerformanceAudit\Exceptions\DependencyUnexpectedResultException;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function install()
$this->installNpmDependencies();
$this->checkNpmDependencies();
} catch (Exception $exception) {
Log::error('Unable to install Node dependencies.', ['exception' => $exception]);
StaticContainer::get(Logger::class)->error('Unable to install Node dependencies.', ['exception' => $exception]);

throw new InstallationFailedException('Node.js dependency installation failed due to the following error: ' . PHP_EOL . $exception->getMessage());
}
Expand Down
7 changes: 4 additions & 3 deletions PerformanceAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Exception;
use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Db;
use Piwik\Log;
use Piwik\Log\Logger;
use Piwik\Plugin;
use Piwik\Plugins\PerformanceAudit\Exceptions\InstallationFailedException;
use ReflectionClass;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function activate()
try {
(new NodeDependencyInstaller())->install();
} catch (Exception $exception) {
Log::error('Unable to activate plugin.', ['exception' => $exception]);
StaticContainer::get(Logger::class)->error('Unable to activate plugin.', ['exception' => $exception]);

// Throw new exception so the plugin doesn't get activated in Matomo
throw new InstallationFailedException('PerformanceAudit plugin activation failed due to the following error: ' . PHP_EOL . $exception->getMessage());
Expand Down Expand Up @@ -90,7 +91,7 @@ public function deactivate()
public function updated($componentName, $updatedVersion) {
// Only perform action if this plugin got updated
if ((new ReflectionClass($this))->getShortName() === $componentName) {
Log::info($componentName . ' plugin was updated to version: ' . $updatedVersion);
StaticContainer::get(Logger::class)->info($componentName . ' plugin was updated to version: ' . $updatedVersion);

// Since an plugin update removes all installed Node dependencies,
// we re-add them by running the dependencies installer via activate()
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Daily performance audits of all your sites in Matomo for the following metrics b

Continuously monitor those Web Vital metrics over time, allowing detection of underlying problems before they have an adverse effect for users or simply track changes made to the web application, allowing you to establish a baseline for comparison too.

**Note:** Requires minimum NPM v6.13 (part of Node.js 10.18 LTS) to be installed on your server, otherwise plugin cannot be activated.
**Note:** Requires minimum NPM v10.x (part of Node.js 20.x LTS) to be installed on your server, otherwise plugin cannot be activated.

## Support me
If you installed this plugin and it was useful for you or your business, please don't hesitate to make a donation, I would highly appreciate it. Thank you!
Expand Down Expand Up @@ -45,10 +45,10 @@ enable_plugin_upload = 1
If any errors occur during activation, please follow the instruction or information of the error message.

## Minimum requirements
- Matomo 4.0
- Matomo 5.0
- PHP 7.2.5
- NPM v6.13 (part of [Node.js](https://nodejs.org/en/download/) 10.18 LTS) to be installed on your server, otherwise plugin cannot be activated.
- If you use a UNIX based OS [these dependencies are required](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
- NPM v10.x (part of [Node.js](https://nodejs.org/en/download/) 20.x LTS) to be installed on your server, otherwise plugin cannot be activated.
- If you use a UNIX based OS [these dependencies are required](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-doesnt-launch-on-linux)

## Impact on server
Please keep in mind that Performance Audit uses Lighthouse internally in order to perform performance audits in the background for every Matomo tracked URL within the last 1 month.
Expand Down
10 changes: 5 additions & 5 deletions Reports/GetPerformanceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';

use Exception;
use Piwik\Common;
use Piwik\DataTable\Filter\Sort;
use Piwik\Piwik;
use Piwik\Plugin\Report;
Expand All @@ -17,6 +16,7 @@
use Piwik\Plugins\PerformanceAudit\EmulatedDevice;
use Piwik\Plugins\PerformanceAudit\MeasurableSettings;
use Piwik\Report\ReportWidgetFactory;
use Piwik\Request;
use Piwik\Widget\WidgetsList;
use ReflectionClass;

Expand All @@ -36,11 +36,11 @@ class GetPerformanceBase extends Report
*/
protected function init()
{
if (!Common::getRequestVar('idSite', false)) {
if (Request::getIntegerParameter('idSite', 0) == 0) {
return;
}

$siteSettings = new MeasurableSettings(Common::getRequestVar('idSite'));
$siteSettings = new MeasurableSettings(Request::getIntegerParameter('idSite'));
$defaultMetrics = [
new MinSeconds(),
new MedianSeconds(),
Expand Down Expand Up @@ -69,8 +69,8 @@ protected function init()
*/
public function isEnabled()
{
$idSite = Common::getRequestVar('idSite', false);
if (!$idSite) {
$idSite = Request::getIntegerParameter('idSite', -1);
if ($idSite < 0) {
return false;
}
// Disable report if initialised as instance of itself
Expand Down
11 changes: 6 additions & 5 deletions Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
use OutOfBoundsException;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\DataTable\Map;
use Piwik\Date;
use Piwik\Db;
use Piwik\Log;
use Piwik\Log\Logger;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugin\Tasks as BaseTasks;
Expand Down Expand Up @@ -783,7 +784,7 @@ private function logDebug(string $message)
if ($this->isInDebugMode()) {
$this->logOutput[] = '[debug] ' . $message;
}
Log::debug($message);
StaticContainer::get(Logger::class)->debug($message);
}

/**
Expand All @@ -797,7 +798,7 @@ private function logInfo(string $message)
if ($this->isInDebugMode()) {
$this->logOutput[] = '[info] ' . $message;
}
Log::info($message);
StaticContainer::get(Logger::class)->info($message);
}

/**
Expand All @@ -811,7 +812,7 @@ private function logWarning(string $message)
if ($this->isInDebugMode()) {
$this->logOutput[] = '[warning] ' . $message;
}
Log::warning($message);
StaticContainer::get(Logger::class)->warning($message);
}

/**
Expand All @@ -825,6 +826,6 @@ private function logError(string $message)
if ($this->isInDebugMode()) {
$this->logOutput[] = '[error] ' . $message;
}
Log::error($message);
StaticContainer::get(Logger::class)->error($message);
}
}
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Under `General Settings` > `Websites` > `Manage` click on the edit button of the

__The plugin cannot install because Chromium cannot be installed due to a missing library?__

Make sure [all necessary dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix) for Chromium are installed.
Make sure [all necessary dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-doesnt-launch-on-linux) for Chromium are installed.
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "PerformanceAudit",
"description": "Daily performance audits of all your sites in Matomo.",
"version": "2.1.0",
"version": "3.0.0-b1",
"theme": false,
"require": {
"php": ">=7.2.5",
"matomo": ">=4.0.0-b1,<5.0.0-b1"
"matomo": ">=5.0.0-b1,<6.0.0-b1"
},
"authors": [
{
Expand Down

0 comments on commit 42d9588

Please sign in to comment.