Elgg  Version 6.1
PluginsListCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
8 
12 class PluginsListCommand extends Command {
13 
17  protected function configure() {
18  $this->setName('plugins:list')
19  ->setDescription(elgg_echo('cli:plugins:list:description'))
20  ->addOption('status', 's', InputOption::VALUE_OPTIONAL,
21  elgg_echo('cli:plugins:list:option:status', ['all | active | inactive']),
22  'all'
23  )
24  ->addOption('refresh', 'r', InputOption::VALUE_NONE,
25  elgg_echo('cli:plugins:list:option:refresh')
26  );
27  }
28 
32  protected function command() {
33 
34  $status = $this->option('status');
35  if (!in_array($status, ['all', 'active', 'inactive'])) {
36  $this->error(elgg_echo('cli:plugins:list:error:status', [$status, 'all | active | inactive']));
37  return self::FAILURE;
38  }
39 
40  if ($this->option('refresh') !== false) {
41  _elgg_services()->plugins->generateEntities();
42  }
43 
44  $table = new Table($this->output);
45  $table->setHeaders([
46  'GUID',
47  elgg_echo('admin:plugins:label:id'),
48  elgg_echo('admin:plugins:label:version'),
49  elgg_echo('status'),
50  elgg_echo('admin:plugins:label:priority'),
51  ]);
52 
53  try {
54  $plugins = elgg_get_plugins($status);
55 
56  foreach ($plugins as $plugin) {
57  $table->addRow([
58  $plugin->guid,
59  $plugin->getID(),
60  $plugin->getVersion(),
61  $plugin->isActive() ? elgg_echo('status:active') : elgg_echo('status:inactive'),
62  $plugin->getPriority(),
63  ]);
64  }
65 
66  $table->render();
67  } catch (PluginException $ex) {
68  return self::INVALID;
69  }
70 
71  return self::SUCCESS;
72  }
73 }
elgg_get_plugins(string $status= 'active')
Returns an ordered list of plugins.
Definition: plugins.php:39
$plugin
elgg-cli plugins:list [–status]
error($message)
Print an error.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$table
Definition: user.php:37
Abstract command with some utility methods.
Definition: Command.php:12
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
option($name)
Returns option value.