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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CorePluginsAdmin\Commands;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugin\Manager;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* plugin:list console command.
*/
class ListPlugins extends ConsoleCommand
{
protected function configure()
{
$this->setName('plugin:list');
$this->setDescription('List installed plugins.');
$this->addOption('filter-plugin', null, InputOption::VALUE_OPTIONAL, 'If given, prints only plugins that contain this term.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginManager = Manager::getInstance();
$plugins = $pluginManager->getInstalledPluginsName();
$pluginFilter = $input->getOption('filter-plugin');
if (!empty($pluginFilter)) {
$plugins = array_filter($plugins, function ($pluginName) use ($pluginFilter) {
return strpos($pluginName, $pluginFilter) !== false;
});
}
$plugins = array_map(function ($plugin) use ($pluginManager) {
return array(
'<info>' . $plugin . '</info>',
$pluginManager->isPluginBundledWithCore($plugin) ? 'Core' : 'Optional',
$pluginManager->isPluginActivated($plugin) ? 'Activated' : '<comment>Not activated</comment>',
);
}, $plugins);
// Sort Core plugins first
usort($plugins, function ($a, $b) {
return strcmp($a[1], $b[1]);
});
$table = new Table($output);
$table
->setHeaders(array('Plugin', 'Core or optional?', 'Status'))
->setRows($plugins)
;
$table->render();
}
}
|