Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorConfigManagementDeleteWorkflow
4
extends PhabricatorConfigManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('delete')
9
->setExamples('**delete** __key__')
10
->setSynopsis(pht('Delete a local configuration value.'))
11
->setArguments(
12
array(
13
array(
14
'name' => 'database',
15
'help' => pht(
16
'Delete configuration in the database instead of '.
17
'in local configuration.'),
18
),
19
array(
20
'name' => 'args',
21
'wildcard' => true,
22
),
23
));
24
}
25
26
public function execute(PhutilArgumentParser $args) {
27
$console = PhutilConsole::getConsole();
28
29
$argv = $args->getArg('args');
30
if (count($argv) == 0) {
31
throw new PhutilArgumentUsageException(
32
pht('Specify a configuration key to delete.'));
33
}
34
35
$key = $argv[0];
36
37
if (count($argv) > 1) {
38
throw new PhutilArgumentUsageException(
39
pht('Too many arguments: expected one key.'));
40
}
41
42
43
$use_database = $args->getArg('database');
44
if ($use_database) {
45
$config = new PhabricatorConfigDatabaseSource('default');
46
$config_type = 'database';
47
} else {
48
$config = new PhabricatorConfigLocalSource();
49
$config_type = 'local';
50
}
51
$values = $config->getKeys(array($key));
52
if (!$values) {
53
throw new PhutilArgumentUsageException(
54
pht(
55
"Configuration key '%s' is not set in %s configuration!",
56
$key,
57
$config_type));
58
}
59
60
if ($use_database) {
61
$config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
62
$config_entry->setIsDeleted(1);
63
$config_entry->save();
64
} else {
65
$config->deleteKeys(array($key));
66
}
67
68
$console->writeOut(
69
"%s\n",
70
pht("Deleted '%s' from %s configuration.", $key, $config_type));
71
}
72
73
}
74
75