Skip to content

Commit d747c1b

Browse files
authored
Merge pull request #9 from DevDavido/development
Bump to v1.0.5
2 parents 996d728 + 04ee165 commit d747c1b

18 files changed

+556
-280
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.0.5
4+
- Added: Possibility to check plugin audit functionality
5+
36
## 1.0.4
47
- Fixed: Switched to require `piwik` instead `matomo` in `plugin.json` for Matomo 3.x compatibility
58
- Improved: `plugin.json` plugin description

Controller.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';
1212

13+
use Exception;
1314
use Piwik\Plugin;
1415
use Piwik\Plugin\Controller as BaseController;
16+
use Piwik\Site;
1517

1618
class Controller extends BaseController
1719
{
@@ -29,4 +31,44 @@ public function version()
2931
'pluginName' => $plugin->getPluginName()
3032
]);
3133
}
34+
35+
/**
36+
* Render plugin check page.
37+
*
38+
* @return string
39+
* @throws Exception
40+
*/
41+
public function pluginCheck()
42+
{
43+
return $this->renderTemplate('pluginCheck', [
44+
'checkStartUrl' => (new Menu())->getUrlForAction('pluginCheckStart')
45+
]);
46+
}
47+
48+
/**
49+
* Start plugin check.
50+
*
51+
* @return string
52+
* @throws Exception
53+
*/
54+
public function pluginCheckStart()
55+
{
56+
$tasks = new Tasks();
57+
foreach (Site::getSites() as $site) {
58+
$tasks->auditSite((int) $site['idsite'], $debug = true);
59+
}
60+
61+
$hasErrorInOutput = false;
62+
$logOutput = array_map('trim', array_map('stripslashes', $tasks->getLogOutput()));
63+
foreach ($logOutput as $logEntry) {
64+
if (stristr($logEntry, '[error]') || stristr($logEntry, '[warning]')) {
65+
$hasErrorInOutput = true;
66+
}
67+
}
68+
69+
return $this->renderTemplate('pluginChecked', [
70+
'hasErrorInOutput' => $hasErrorInOutput,
71+
'logOutput' => nl2br(implode("\n", $logOutput))
72+
]);
73+
}
3274
}

Menu.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ class Menu extends BaseMenu
2626
*/
2727
public function configureAdminMenu(MenuAdmin $menu)
2828
{
29-
$menu->addItem('PerformanceAudit_CoreAdminHome_MenuPerformance', 'PerformanceAudit_Version', $this->urlForAction('version'), $orderId = 4);
29+
$menu->addItem('PerformanceAudit_CoreAdminHome_MenuPerformance', 'PerformanceAudit_PluginCheck', $this->urlForAction('pluginCheck'), $orderId = 4);
30+
$menu->addItem('PerformanceAudit_CoreAdminHome_MenuPerformance', 'PerformanceAudit_Version', $this->urlForAction('version'), $orderId = 5);
31+
}
32+
33+
/**
34+
* Returns URL for action.
35+
*
36+
* @param string $name
37+
* @return string
38+
*/
39+
public function getUrlForAction(string $name)
40+
{
41+
return http_build_query($this->urlForActionWithDefaultUserParams($name));
3042
}
3143
}

PerformanceAudit.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class PerformanceAudit extends Plugin
3737
public function registerEvents()
3838
{
3939
return [
40-
'Db.getTablesInstalled' => 'getTablesInstalled'
40+
'Db.getTablesInstalled' => 'getTablesInstalled',
41+
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles'
4142
];
4243
}
4344

@@ -248,12 +249,24 @@ private function deleteDatabaseTable()
248249
* Register the new tables.
249250
*
250251
* @param array $tablesInstalled
252+
* @retrun void
251253
*/
252254
public function getTablesInstalled(&$tablesInstalled)
253255
{
254256
$tablesInstalled[] = Common::prefixTable('log_performance');
255257
}
256258

259+
/**
260+
* Sets array of required CSS files.
261+
*
262+
* @param array $cssFiles
263+
* @retrun void
264+
*/
265+
public function getStylesheetFiles(&$cssFiles)
266+
{
267+
$cssFiles[] = 'plugins/PerformanceAudit/stylesheets/pluginCheck.css';
268+
}
269+
257270
/**
258271
* Return if internet connection is required.
259272
*

0 commit comments

Comments
 (0)