-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16368 from owncloud/occ-config-commands
Add "occ config:*" to manage config values
- Loading branch information
Showing
20 changed files
with
2,203 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* @author Joas Schilling <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2015, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Core\Command\Config\App; | ||
|
||
use OC\Core\Command\Base; | ||
use OCP\IConfig; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DeleteConfig extends Base { | ||
/** * @var IConfig */ | ||
protected $config; | ||
|
||
/** | ||
* @param IConfig $config | ||
*/ | ||
public function __construct(IConfig $config) { | ||
parent::__construct(); | ||
$this->config = $config; | ||
} | ||
|
||
protected function configure() { | ||
parent::configure(); | ||
|
||
$this | ||
->setName('config:app:delete') | ||
->setDescription('Delete an app config value') | ||
->addArgument( | ||
'app', | ||
InputArgument::REQUIRED, | ||
'Name of the app' | ||
) | ||
->addArgument( | ||
'name', | ||
InputArgument::REQUIRED, | ||
'Name of the config to delete' | ||
) | ||
->addOption( | ||
'error-if-not-exists', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Checks whether the config exists before deleting it' | ||
) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$appName = $input->getArgument('app'); | ||
$configName = $input->getArgument('name'); | ||
|
||
if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) { | ||
$output->writeln('<error>Config ' . $configName . ' could not be deleted because it did not exist</error>'); | ||
return 1; | ||
} | ||
|
||
$this->config->deleteAppValue($appName, $configName); | ||
$output->writeln('<info>System config value ' . $configName . ' deleted</info>'); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* @author Joas Schilling <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2015, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Core\Command\Config\App; | ||
|
||
use OC\Core\Command\Base; | ||
use OCP\IConfig; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GetConfig extends Base { | ||
/** * @var IConfig */ | ||
protected $config; | ||
|
||
/** | ||
* @param IConfig $config | ||
*/ | ||
public function __construct(IConfig $config) { | ||
parent::__construct(); | ||
$this->config = $config; | ||
} | ||
|
||
protected function configure() { | ||
parent::configure(); | ||
|
||
$this | ||
->setName('config:app:get') | ||
->setDescription('Get an app config value') | ||
->addArgument( | ||
'app', | ||
InputArgument::REQUIRED, | ||
'Name of the app' | ||
) | ||
->addArgument( | ||
'name', | ||
InputArgument::REQUIRED, | ||
'Name of the config to get' | ||
) | ||
->addOption( | ||
'default-value', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
'If no default value is set and the config does not exist, the command will exit with 1' | ||
) | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* @return null|int null or 0 if everything went fine, or an error code | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$appName = $input->getArgument('app'); | ||
$configName = $input->getArgument('name'); | ||
$defaultValue = $input->getOption('default-value'); | ||
|
||
if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) { | ||
return 1; | ||
} | ||
|
||
if (!in_array($configName, $this->config->getAppKeys($appName))) { | ||
$configValue = $defaultValue; | ||
} else { | ||
$configValue = $this->config->getAppValue($appName, $configName); | ||
} | ||
|
||
$this->writeMixedInOutputFormat($input, $output, $configValue); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* @author Joas Schilling <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2015, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Core\Command\Config\App; | ||
|
||
use OC\Core\Command\Base; | ||
use OCP\IConfig; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SetConfig extends Base { | ||
/** * @var IConfig */ | ||
protected $config; | ||
|
||
/** | ||
* @param IConfig $config | ||
*/ | ||
public function __construct(IConfig $config) { | ||
parent::__construct(); | ||
$this->config = $config; | ||
} | ||
|
||
protected function configure() { | ||
parent::configure(); | ||
|
||
$this | ||
->setName('config:app:set') | ||
->setDescription('Set an app config value') | ||
->addArgument( | ||
'app', | ||
InputArgument::REQUIRED, | ||
'Name of the app' | ||
) | ||
->addArgument( | ||
'name', | ||
InputArgument::REQUIRED, | ||
'Name of the config to set' | ||
) | ||
->addOption( | ||
'value', | ||
null, | ||
InputOption::VALUE_REQUIRED, | ||
'The new value of the config' | ||
) | ||
->addOption( | ||
'update-only', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Only updates the value, if it is not set before, it is not being added' | ||
) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$appName = $input->getArgument('app'); | ||
$configName = $input->getArgument('name'); | ||
|
||
if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) { | ||
$output->writeln('<comment>Value not updated, as it has not been set before.</comment>'); | ||
return 1; | ||
} | ||
|
||
$configValue = $input->getOption('value'); | ||
$this->config->setAppValue($appName, $configName, $configValue); | ||
|
||
$output->writeln('<info>Config value ' . $configName . ' for app ' . $appName . ' set to ' . $configValue . '</info>'); | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.