mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-28 18:40:39 +00:00
102 lines
3.9 KiB
PHP
102 lines
3.9 KiB
PHP
<?php
|
|
namespace Seeddms\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
|
|
|
|
|
use Seeddms\Seeddms\Settings;
|
|
use Seeddms\Seeddms\Translator;
|
|
use SeedDMS_Core_File;
|
|
use SeedDMS_View_Common;
|
|
use SeedDMS_Extension_Mgr;
|
|
use Log_file;
|
|
|
|
class ConfigureextensionCommand extends Command
|
|
{
|
|
protected $settings;
|
|
|
|
protected $logger;
|
|
|
|
protected $translator;
|
|
|
|
protected $extmgr;
|
|
|
|
public function __construct(Settings $settings, Log_file $logger, Translator $translator, SeedDMS_Extension_Mgr $extmgr)
|
|
{
|
|
$this->settings = $settings;
|
|
$this->logger = $logger;
|
|
$this->translator = $translator;
|
|
$this->extmgr = $extmgr;
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('ext:configure')
|
|
->setDescription('Configure extension')
|
|
->setHelp('Enables and disables an extensions.')
|
|
->addOption('name', '', InputOption::VALUE_REQUIRED, 'Name of extension.', null)
|
|
->addOption('enable', '', InputOption::VALUE_NONE, 'Enable extension.')
|
|
->addOption('disable', '', InputOption::VALUE_NONE, 'Disable extension.')
|
|
;
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) : int
|
|
{
|
|
$settings = $this->settings;
|
|
$logger = $this->logger;
|
|
$translator = $this->translator;
|
|
$extmgr = $this->extmgr;
|
|
|
|
$output->writeln("<comment>Using configuration from '".$settings->_configFilePath."'.</comment>", OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
if (($input->getOption('enable') || $input->getOption('disable')) && !is_writable($settings->_configFilePath)) {
|
|
$output->writeln(sprintf("<error>The configuration file '%s' is not writable by the system user running this script.</error>", $settings->_configFilePath));
|
|
return Command::FAILURE;
|
|
}
|
|
$extconf = $extmgr->getExtensionConfiguration();
|
|
$extname = $input->getOption('name');
|
|
if (!isset($extconf[$extname])) {
|
|
$output->writeln(sprintf("<error>No such extension '%s'</error>", $extname));
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
if ($input->getOption('enable')) {
|
|
if ($settings->extensionIsDisabled($extname)) {
|
|
$settings->enableExtension($extname);
|
|
if (false === $settings->save()) {
|
|
$output->writeln(sprintf("<error>Could not write configuration.</error>", $extname));
|
|
return Command::FAILURE;
|
|
} else {
|
|
$output->writeln(sprintf("Extension is %s.", $settings->extensionIsDisabled($extname) ? 'disabled' : 'enabled'));
|
|
}
|
|
} else {
|
|
$output->writeln(sprintf("Extension already enabled."));
|
|
}
|
|
} elseif ($input->getOption('disable')) {
|
|
if (!$settings->extensionIsDisabled($extname)) {
|
|
$settings->disableExtension($extname);
|
|
if (false === $settings->save()) {
|
|
$output->writeln(sprintf("<error>Could not write configuration.</error>", $extname));
|
|
return Command::FAILURE;
|
|
} else {
|
|
$output->writeln(sprintf("Extension is %s.", $settings->extensionIsDisabled($extname) ? 'disabled' : 'enabled'));
|
|
}
|
|
} else {
|
|
$output->writeln(sprintf("Extension already disabled."));
|
|
}
|
|
} else {
|
|
$output->writeln(sprintf("Extension is %s.", $settings->extensionIsDisabled($extname) ? 'disabled' : 'enabled'));
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|
|
|
|
// vim: ts=4 sw=4 expandtab
|