-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathController.php
82 lines (70 loc) · 2.11 KB
/
Controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Piwik\Plugins\PerformanceAudit;
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';
use Exception;
use Piwik\Plugin;
use Piwik\Plugin\Controller as BaseController;
use Piwik\Site;
class Controller extends BaseController
{
/**
* Get plugin information and render it.
*
* @return string
*/
public function version()
{
$plugin = new Plugin('PerformanceAudit');
return $this->renderTemplate('version', [
'pluginVersion' => $plugin->getVersion(),
'pluginName' => $plugin->getPluginName()
]);
}
/**
* Render plugin check page.
*
* @return string
* @throws Exception
*/
public function pluginCheck()
{
$installer = new NodeDependencyInstaller();
$error = '';
try {
Helper::checkDirectoriesWriteable(['Audits', 'node_modules']);
$installer->checkInternetAvailability();
$installer->checkNpm();
$installer->checkNpmDependencies();
} catch (Exception $exception) {
$error = $exception->getMessage();
}
return $this->renderTemplate('pluginCheck', [
'checkStartUrl' => (new Menu())->getUrlForAction('pluginCheckStart'),
'error' => $error
]);
}
/**
* Start plugin check.
*
* @return string
* @throws Exception
*/
public function pluginCheckStart()
{
$tasks = new Tasks();
foreach (Site::getSites() as $site) {
$tasks->auditSite((int) $site['idsite'], $debug = true);
}
$hasErrorInOutput = false;
$logOutput = array_map('trim', array_map('stripslashes', $tasks->getLogOutput()));
foreach ($logOutput as $logEntry) {
if (stristr($logEntry, '[error]') || stristr($logEntry, '[warning]')) {
$hasErrorInOutput = true;
}
}
return $this->renderTemplate('pluginChecked', [
'hasErrorInOutput' => $hasErrorInOutput,
'logOutput' => nl2br(implode("\n", $logOutput))
]);
}
}