From 44cc080769add75c15bdb7bd06d66fe5510c8283 Mon Sep 17 00:00:00 2001 From: LucasZdv Date: Fri, 22 Feb 2019 15:50:01 -0300 Subject: [PATCH] Added plugin:list, plugin:disable, & plugin:enable artisan commands (#4127) Credit to @LucasZdv. Documented by https://github.com/octobercms/docs/pull/356 --- .gitignore | 1 + modules/system/ServiceProvider.php | 3 + modules/system/console/PluginDisable.php | 64 +++++++++++++++++++++ modules/system/console/PluginEnable.php | 64 +++++++++++++++++++++ modules/system/console/PluginList.php | 72 ++++++++++++++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 modules/system/console/PluginDisable.php create mode 100644 modules/system/console/PluginEnable.php create mode 100644 modules/system/console/PluginList.php diff --git a/.gitignore b/.gitignore index 08650878e..c5ebf3e67 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ nginx-ssl.access.log nginx-ssl.error.log php-errors.log sftp-config.json +.ftpconfig selenium.php composer.lock diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 4ab6cf40a..4711de05d 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -238,7 +238,10 @@ class ServiceProvider extends ModuleServiceProvider $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $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.list', 'System\Console\PluginList'); $this->registerConsoleCommand('theme.install', 'System\Console\ThemeInstall'); $this->registerConsoleCommand('theme.remove', 'System\Console\ThemeRemove'); diff --git a/modules/system/console/PluginDisable.php b/modules/system/console/PluginDisable.php new file mode 100644 index 000000000..cda25b53e --- /dev/null +++ b/modules/system/console/PluginDisable.php @@ -0,0 +1,64 @@ +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('%s: disabled.', $pluginName)); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'], + ]; + } +} diff --git a/modules/system/console/PluginEnable.php b/modules/system/console/PluginEnable.php new file mode 100644 index 000000000..4c2db5ac6 --- /dev/null +++ b/modules/system/console/PluginEnable.php @@ -0,0 +1,64 @@ +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('%s: enabled.', $pluginName)); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'], + ]; + } +} diff --git a/modules/system/console/PluginList.php b/modules/system/console/PluginList.php new file mode 100644 index 000000000..e0bf4072c --- /dev/null +++ b/modules/system/console/PluginList.php @@ -0,0 +1,72 @@ +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(); + } +}