2013-01-22 00:27:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorConfigManagementGetWorkflow
|
|
|
|
extends PhabricatorConfigManagementWorkflow {
|
|
|
|
|
|
|
|
protected function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('get')
|
|
|
|
->setExamples('**get** __key__')
|
|
|
|
->setSynopsis('Get a local configuration value.')
|
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'args',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$argv = $args->getArg('args');
|
|
|
|
if (count($argv) == 0) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
2014-06-09 20:36:49 +02:00
|
|
|
'Specify a configuration key to get.');
|
2013-01-22 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$key = $argv[0];
|
|
|
|
|
|
|
|
if (count($argv) > 1) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
2014-06-09 20:36:49 +02:00
|
|
|
'Too many arguments: expected one key.');
|
2013-01-22 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$options = PhabricatorApplicationConfigOptions::loadAllOptions();
|
|
|
|
if (empty($options[$key])) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
"No such configuration key '{$key}'! Use `config list` to list all ".
|
|
|
|
"keys.");
|
|
|
|
}
|
|
|
|
|
2014-10-09 01:15:05 +02:00
|
|
|
$values = array();
|
2013-01-22 00:27:42 +01:00
|
|
|
$config = new PhabricatorConfigLocalSource();
|
2014-10-09 01:15:05 +02:00
|
|
|
$local_value = $config->getKeys(array($key));
|
|
|
|
if (empty($local_value)) {
|
|
|
|
$values['local'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => null,
|
|
|
|
'status' => 'unset',
|
|
|
|
'errorInfo' => null,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$values['local'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => reset($local_value),
|
|
|
|
'status' => 'set',
|
|
|
|
'errorInfo' => null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
Allow config get to work when db is not functional
Summary: Fixes T6554.
Test Plan:
Run `bin/config get mysql.host` when no db is functional. Should not get an exception, but should see:
```
lang=json
{
"config" : [
{
"key" : "mysql.host",
"source" : "local",
"value" : null,
"status" : "unset",
"errorInfo" : null
},
{
"key" : "mysql.host",
"source" : "database",
"value" : null,
"status" : "error",
"errorInfo" : "Database source is not configured properly"
}
]
}
```
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley
Maniphest Tasks: T6554
Differential Revision: https://secure.phabricator.com/D10851
2014-11-14 18:12:20 +01:00
|
|
|
$database_config = new PhabricatorConfigDatabaseSource('default');
|
2014-10-09 01:15:05 +02:00
|
|
|
$database_value = $database_config->getKeys(array($key));
|
|
|
|
if (empty($database_value)) {
|
|
|
|
$values['database'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => null,
|
|
|
|
'status' => 'unset',
|
|
|
|
'errorInfo' => null,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$values['database'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => reset($database_value),
|
|
|
|
'status' => 'set',
|
|
|
|
'errorInfo' => null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$values['database'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => null,
|
|
|
|
'status' => 'error',
|
|
|
|
'errorInfo' => pht('Database source is not configured properly'),
|
|
|
|
);
|
|
|
|
}
|
2013-01-22 00:27:42 +01:00
|
|
|
|
|
|
|
$result = array();
|
2014-10-09 01:15:05 +02:00
|
|
|
foreach ($values as $source => $value) {
|
2013-01-22 00:27:42 +01:00
|
|
|
$result[] = array(
|
2014-10-09 01:15:05 +02:00
|
|
|
'key' => $value['key'],
|
|
|
|
'source' => $source,
|
|
|
|
'value' => $value['value'],
|
|
|
|
'status' => $value['status'],
|
|
|
|
'errorInfo' => $value['errorInfo'],
|
2013-01-22 00:27:42 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$result = array(
|
|
|
|
'config' => $result,
|
|
|
|
);
|
|
|
|
|
|
|
|
$json = new PhutilJSON();
|
|
|
|
$console->writeOut($json->encodeFormatted($result));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|