Added plugin:list, plugin:disable, & plugin:enable artisan commands (#4127)

Credit to @LucasZdv. Documented by https://github.com/octobercms/docs/pull/356
This commit is contained in:
LucasZdv 2019-02-22 15:50:01 -03:00 committed by Luke Towers
parent ecb2b3fe9e
commit 44cc080769
5 changed files with 204 additions and 0 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ nginx-ssl.access.log
nginx-ssl.error.log nginx-ssl.error.log
php-errors.log php-errors.log
sftp-config.json sftp-config.json
.ftpconfig
selenium.php selenium.php
composer.lock composer.lock

View File

@ -238,7 +238,10 @@ class ServiceProvider extends ModuleServiceProvider
$this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall');
$this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove'); $this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove');
$this->registerConsoleCommand('plugin.disable', 'System\Console\PluginDisable');
$this->registerConsoleCommand('plugin.enable', 'System\Console\PluginEnable');
$this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh'); $this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh');
$this->registerConsoleCommand('plugin.list', 'System\Console\PluginList');
$this->registerConsoleCommand('theme.install', 'System\Console\ThemeInstall'); $this->registerConsoleCommand('theme.install', 'System\Console\ThemeInstall');
$this->registerConsoleCommand('theme.remove', 'System\Console\ThemeRemove'); $this->registerConsoleCommand('theme.remove', 'System\Console\ThemeRemove');

View File

@ -0,0 +1,64 @@
<?php namespace System\Console;
use Illuminate\Console\Command;
use System\Classes\PluginManager;
use System\Models\PluginVersion;
use Symfony\Component\Console\Input\InputArgument;
/**
* Console command to disable a plugin.
*
* @package october\system
* @author Lucas Zamora
*/
class PluginDisable extends Command
{
/**
* The console command name.
* @var string
*/
protected $name = 'plugin:disable';
/**
* The console command description.
* @var string
*/
protected $description = 'Disable an existing plugin.';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$pluginManager = PluginManager::instance();
$pluginName = $this->argument('name');
$pluginName = $pluginManager->normalizeIdentifier($pluginName);
if (!$pluginManager->hasPlugin($pluginName)) {
return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName));
}
// Disable this plugin
$pluginManager->disablePlugin($pluginName);
$plugin = PluginVersion::where('code', $pluginName)->first();
$plugin->is_disabled = true;
$plugin->save();
$this->output->writeln(sprintf('<info>%s:</info> disabled.', $pluginName));
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'],
];
}
}

View File

@ -0,0 +1,64 @@
<?php namespace System\Console;
use Illuminate\Console\Command;
use System\Classes\PluginManager;
use System\Models\PluginVersion;
use Symfony\Component\Console\Input\InputArgument;
/**
* Console command to enable a plugin.
*
* @package october\system
* @author Lucas Zamora
*/
class PluginEnable extends Command
{
/**
* The console command name.
* @var string
*/
protected $name = 'plugin:enable';
/**
* The console command description.
* @var string
*/
protected $description = 'Enable an existing plugin.';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$pluginManager = PluginManager::instance();
$pluginName = $this->argument('name');
$pluginName = $pluginManager->normalizeIdentifier($pluginName);
if (!$pluginManager->hasPlugin($pluginName)) {
return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName));
}
// Disable this plugin
$pluginManager->enablePlugin($pluginName);
$plugin = PluginVersion::where('code', $pluginName)->first();
$plugin->is_disabled = false;
$plugin->save();
$this->output->writeln(sprintf('<info>%s:</info> enabled.', $pluginName));
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'],
];
}
}

View File

@ -0,0 +1,72 @@
<?php namespace System\Console;
use Illuminate\Console\Command;
use System\Models\PluginVersion;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
/**
* Console command to list existing plugins.
*
* @package october\system
* @author Lucas Zamora
*/
class PluginList extends Command
{
/**
* The console command name.
* @var string
*/
protected $name = 'plugin:list';
/**
* The console command description.
* @var string
*/
protected $description = 'List existing plugins.';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$allPlugins = PluginVersion::all();
$pluginsCount = count($allPlugins);
if ($pluginsCount <= 0 ) {
$this->info('No plugin found');
return;
}
// Create a new Table instance.
$table = new Table($this->output);
// Set the table headers.
$table->setHeaders([
'Plugin name', 'Version', 'Updates enabled', 'Plugin enabled'
]);
// Create a new TableSeparator instance.
$separator = new TableSeparator;
$pluginTable = [];
$row = 0;
foreach ($allPlugins as $plugin) {
$row++;
$pluginTable[] = [$plugin->code, $plugin->version, (!$plugin->is_frozen) ? 'Yes': 'No', (!$plugin->is_disabled) ? 'Yes': 'No'];
if ($row < $pluginsCount) {
$pluginTable[] = $separator;
}
}
// Set the contents of the table.
$table->setRows($pluginTable);
// Render the table to the output.
$table->render();
}
}