52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Leantime\Command;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Exception\RuntimeException;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
/**
|
|
* Class EnablePluginCommand
|
|
*
|
|
* This class represents a command that enables plugins.
|
|
*/
|
|
#[AsCommand(
|
|
name: 'plugin:enable',
|
|
description: 'Enable a plugin',
|
|
)]
|
|
class EnablePluginCommand extends AbstractPluginCommand
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function configure(): void
|
|
{
|
|
$this->addArgument('plugin', InputArgument::REQUIRED, 'The plugin name');
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function executeCommand(): int
|
|
{
|
|
$name = $this->input->getArgument('plugin');
|
|
$plugin = $this->getPlugin($name);
|
|
|
|
if (! isset($plugin->id)) {
|
|
throw new RuntimeException(sprintf('Plugin %s is not installed', $plugin->name));
|
|
}
|
|
|
|
if ($plugin->enabled) {
|
|
throw new RuntimeException(sprintf('Plugin %s is already enabled', $plugin->name));
|
|
}
|
|
|
|
if (! $this->confirm(sprintf('Enable plugin %s', $plugin->name))) {
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
return $this->plugins->enablePlugin($plugin->id) ? Command::SUCCESS : Command::FAILURE;
|
|
}
|
|
}
|