From 742e2e36abfad83b8cc847671fd9c038774c7b98 Mon Sep 17 00:00:00 2001 From: DevDavido <997605+DevDavido@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:35:52 +0100 Subject: [PATCH] fix: Matomo 5 migration --- API.php | 4 ++-- Archiver.php | 7 ++++--- CHANGELOG.md | 5 +++++ Commands/ClearTaskRunningFlag.php | 22 +++++++++++----------- NodeDependencyInstaller.php | 5 +++-- PerformanceAudit.php | 7 ++++--- README.md | 6 +++--- Reports/GetPerformanceBase.php | 10 +++++----- Tasks.php | 11 ++++++----- plugin.json | 4 ++-- 10 files changed, 45 insertions(+), 36 deletions(-) diff --git a/API.php b/API.php index 208fe856..1322c13a 100644 --- a/API.php +++ b/API.php @@ -6,7 +6,6 @@ use Exception; use Piwik\Archive; -use Piwik\Common; use Piwik\DataTable; use Piwik\DataTable\Map; use Piwik\DataTable\Row; @@ -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; @@ -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 ])); diff --git a/Archiver.php b/Archiver.php index 2571f367..47c601c4 100644 --- a/Archiver.php +++ b/Archiver.php @@ -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; @@ -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; } @@ -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(); diff --git a/CHANGELOG.md b/CHANGELOG.md index 22d5af47..a1f303b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Commands/ClearTaskRunningFlag.php b/Commands/ClearTaskRunningFlag.php index cae85662..29cd3369 100644 --- a/Commands/ClearTaskRunningFlag.php +++ b/Commands/ClearTaskRunningFlag.php @@ -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 { @@ -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'); @@ -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('Performance Audit running task flag was cleared successfully.'); - return; + $this->getOutput()->writeln('Performance Audit running task flag was cleared successfully.'); + return self::SUCCESS; } - Log::debug('No task running flag available to clear now'); - $output->writeln('Performance Audit running task flag was not set, so nothing to clear now.'); + StaticContainer::get(Logger::class)->debug('No task running flag available to clear now'); + $this->getOutput()->writeln('Performance Audit running task flag was not set, so nothing to clear now.'); + return self::SUCCESS; } } diff --git a/NodeDependencyInstaller.php b/NodeDependencyInstaller.php index 881410ca..efcd9320 100644 --- a/NodeDependencyInstaller.php +++ b/NodeDependencyInstaller.php @@ -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; @@ -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()); } diff --git a/PerformanceAudit.php b/PerformanceAudit.php index 6ae3f60a..a7ff39f8 100644 --- a/PerformanceAudit.php +++ b/PerformanceAudit.php @@ -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; @@ -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()); @@ -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() diff --git a/README.md b/README.md index fcf8695c..18a1c735 100644 --- a/README.md +++ b/README.md @@ -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! @@ -45,9 +45,9 @@ 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. +- 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-headless-doesnt-launch-on-unix) ## Impact on server diff --git a/Reports/GetPerformanceBase.php b/Reports/GetPerformanceBase.php index e2f11f87..0a11d8f6 100644 --- a/Reports/GetPerformanceBase.php +++ b/Reports/GetPerformanceBase.php @@ -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; @@ -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; @@ -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(), @@ -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 diff --git a/Tasks.php b/Tasks.php index 261a89d8..b252dc81 100644 --- a/Tasks.php +++ b/Tasks.php @@ -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; @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } } diff --git a/plugin.json b/plugin.json index 33efbf00..41d6bdb9 100644 --- a/plugin.json +++ b/plugin.json @@ -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": [ {