Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / config / management / PhabricatorConfigManagementDeleteWorkflow.php
blob24b0f48c263933301022379326a2b74d83c337c1
1 <?php
3 final class PhabricatorConfigManagementDeleteWorkflow
4 extends PhabricatorConfigManagementWorkflow {
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.'),
19 array(
20 'name' => 'args',
21 'wildcard' => true,
23 ));
26 public function execute(PhutilArgumentParser $args) {
27 $console = PhutilConsole::getConsole();
29 $argv = $args->getArg('args');
30 if (count($argv) == 0) {
31 throw new PhutilArgumentUsageException(
32 pht('Specify a configuration key to delete.'));
35 $key = $argv[0];
37 if (count($argv) > 1) {
38 throw new PhutilArgumentUsageException(
39 pht('Too many arguments: expected one key.'));
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';
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));
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));
68 $console->writeOut(
69 "%s\n",
70 pht("Deleted '%s' from %s configuration.", $key, $config_type));