Make console commands pluggable

This commit is contained in:
Frederic Guillot
2016-05-29 20:33:48 -04:00
parent b69eb5f993
commit fb642b76bb
8 changed files with 107 additions and 48 deletions

View File

@@ -4,6 +4,7 @@ namespace Kanboard\Console;
use Kanboard\Core\Plugin\Installer;
use Kanboard\Core\Plugin\PluginInstallerException;
use LogicException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,7 +22,7 @@ class PluginInstallCommand extends BaseCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!Installer::isConfigured()) {
$output->writeln('<error>Kanboard is not configured to install plugins itself</error>');
throw new LogicException('Kanboard is not configured to install plugins itself');
}
try {

View File

@@ -4,6 +4,7 @@ namespace Kanboard\Console;
use Kanboard\Core\Plugin\Installer;
use Kanboard\Core\Plugin\PluginInstallerException;
use LogicException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,7 +22,7 @@ class PluginUninstallCommand extends BaseCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!Installer::isConfigured()) {
$output->writeln('<error>Kanboard is not configured to remove plugins itself</error>');
throw new LogicException('Kanboard is not configured to install plugins itself');
}
try {

View File

@@ -5,6 +5,7 @@ namespace Kanboard\Console;
use Kanboard\Core\Plugin\Base as BasePlugin;
use Kanboard\Core\Plugin\Directory;
use Kanboard\Core\Plugin\Installer;
use LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,7 +22,7 @@ class PluginUpgradeCommand extends BaseCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!Installer::isConfigured()) {
$output->writeln('<error>Kanboard is not configured to upgrade plugins itself</error>');
throw new LogicException('Kanboard is not configured to install plugins itself');
}
$installer = new Installer($this->container);

View File

@@ -140,6 +140,7 @@ use Pimple\Container;
* @property \Psr\Log\LoggerInterface $logger
* @property \PicoDb\Database $db
* @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
* @property \Symfony\Component\Console\Application $cli
* @property \JsonRPC\Server $api
*/
abstract class Base

View File

@@ -0,0 +1,62 @@
<?php
namespace Kanboard\ServiceProvider;
use Kanboard\Console\CronjobCommand;
use Kanboard\Console\LocaleComparatorCommand;
use Kanboard\Console\LocaleSyncCommand;
use Kanboard\Console\PluginInstallCommand;
use Kanboard\Console\PluginUninstallCommand;
use Kanboard\Console\PluginUpgradeCommand;
use Kanboard\Console\ProjectDailyColumnStatsExportCommand;
use Kanboard\Console\ProjectDailyStatsCalculationCommand;
use Kanboard\Console\ResetPasswordCommand;
use Kanboard\Console\ResetTwoFactorCommand;
use Kanboard\Console\SubtaskExportCommand;
use Kanboard\Console\TaskExportCommand;
use Kanboard\Console\TaskOverdueNotificationCommand;
use Kanboard\Console\TaskTriggerCommand;
use Kanboard\Console\TransitionExportCommand;
use Kanboard\Console\WorkerCommand;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Console\Application;
/**
* Class CommandProvider
*
* @package Kanboard\ServiceProvider
* @author Frederic Guillot
*/
class CommandProvider implements ServiceProviderInterface
{
/**
* Registers services on the given container.
*
* @param Container $container
* @return Container
*/
public function register(Container $container)
{
$application = new Application('Kanboard', APP_VERSION);
$application->add(new TaskOverdueNotificationCommand($container));
$application->add(new SubtaskExportCommand($container));
$application->add(new TaskExportCommand($container));
$application->add(new ProjectDailyStatsCalculationCommand($container));
$application->add(new ProjectDailyColumnStatsExportCommand($container));
$application->add(new TransitionExportCommand($container));
$application->add(new LocaleSyncCommand($container));
$application->add(new LocaleComparatorCommand($container));
$application->add(new TaskTriggerCommand($container));
$application->add(new CronjobCommand($container));
$application->add(new WorkerCommand($container));
$application->add(new ResetPasswordCommand($container));
$application->add(new ResetTwoFactorCommand($container));
$application->add(new PluginUpgradeCommand($container));
$application->add(new PluginInstallCommand($container));
$application->add(new PluginUninstallCommand($container));
$container['cli'] = $application;
return $container;
}
}

View File

@@ -48,4 +48,5 @@ $container->register(new Kanboard\ServiceProvider\AvatarProvider());
$container->register(new Kanboard\ServiceProvider\FilterProvider());
$container->register(new Kanboard\ServiceProvider\QueueProvider());
$container->register(new Kanboard\ServiceProvider\ApiProvider());
$container->register(new Kanboard\ServiceProvider\CommandProvider());
$container->register(new Kanboard\ServiceProvider\PluginProvider());