Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/management/PhabricatorConfigManagementGetWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorConfigManagementGetWorkflow
4
extends PhabricatorConfigManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('get')
9
->setExamples('**get** __key__')
10
->setSynopsis(pht('Get a local configuration value.'))
11
->setArguments(
12
array(
13
array(
14
'name' => 'args',
15
'wildcard' => true,
16
),
17
));
18
}
19
20
public function execute(PhutilArgumentParser $args) {
21
$console = PhutilConsole::getConsole();
22
23
$argv = $args->getArg('args');
24
if (count($argv) == 0) {
25
throw new PhutilArgumentUsageException(
26
pht('Specify a configuration key to get.'));
27
}
28
29
$key = $argv[0];
30
31
if (count($argv) > 1) {
32
throw new PhutilArgumentUsageException(
33
pht('Too many arguments: expected one key.'));
34
}
35
36
$options = PhabricatorApplicationConfigOptions::loadAllOptions();
37
if (empty($options[$key])) {
38
throw new PhutilArgumentUsageException(
39
pht(
40
"No such configuration key '%s'! Use `%s` to list all keys.",
41
$key,
42
'config list'));
43
}
44
45
$values = array();
46
$config = new PhabricatorConfigLocalSource();
47
$local_value = $config->getKeys(array($key));
48
if (empty($local_value)) {
49
$values['local'] = array(
50
'key' => $key,
51
'value' => null,
52
'status' => 'unset',
53
'errorInfo' => null,
54
);
55
} else {
56
$values['local'] = array(
57
'key' => $key,
58
'value' => reset($local_value),
59
'status' => 'set',
60
'errorInfo' => null,
61
);
62
}
63
64
try {
65
$database_config = new PhabricatorConfigDatabaseSource('default');
66
$database_value = $database_config->getKeys(array($key));
67
if (empty($database_value)) {
68
$values['database'] = array(
69
'key' => $key,
70
'value' => null,
71
'status' => 'unset',
72
'errorInfo' => null,
73
);
74
} else {
75
$values['database'] = array(
76
'key' => $key,
77
'value' => reset($database_value),
78
'status' => 'set',
79
'errorInfo' => null,
80
);
81
}
82
} catch (Exception $e) {
83
$values['database'] = array(
84
'key' => $key,
85
'value' => null,
86
'status' => 'error',
87
'errorInfo' => pht('Database source is not configured properly'),
88
);
89
}
90
91
$result = array();
92
foreach ($values as $source => $value) {
93
$result[] = array(
94
'key' => $value['key'],
95
'source' => $source,
96
'value' => $value['value'],
97
'status' => $value['status'],
98
'errorInfo' => $value['errorInfo'],
99
);
100
}
101
$result = array(
102
'config' => $result,
103
);
104
105
$json = new PhutilJSON();
106
$console->writeOut($json->encodeFormatted($result));
107
}
108
109
}
110
111