Page MenuHomePhabricator

D10490.id25609.diff
No OneTemporary

D10490.id25609.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1380,6 +1380,7 @@
'PhabricatorConfigManagementDeleteWorkflow' => 'applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php',
'PhabricatorConfigManagementGetWorkflow' => 'applications/config/management/PhabricatorConfigManagementGetWorkflow.php',
'PhabricatorConfigManagementListWorkflow' => 'applications/config/management/PhabricatorConfigManagementListWorkflow.php',
+ 'PhabricatorConfigManagementMigrateWorkflow' => 'applications/config/management/PhabricatorConfigManagementMigrateWorkflow.php',
'PhabricatorConfigManagementSetWorkflow' => 'applications/config/management/PhabricatorConfigManagementSetWorkflow.php',
'PhabricatorConfigManagementWorkflow' => 'applications/config/management/PhabricatorConfigManagementWorkflow.php',
'PhabricatorConfigOption' => 'applications/config/option/PhabricatorConfigOption.php',
@@ -4339,6 +4340,7 @@
'PhabricatorConfigManagementDeleteWorkflow' => 'PhabricatorConfigManagementWorkflow',
'PhabricatorConfigManagementGetWorkflow' => 'PhabricatorConfigManagementWorkflow',
'PhabricatorConfigManagementListWorkflow' => 'PhabricatorConfigManagementWorkflow',
+ 'PhabricatorConfigManagementMigrateWorkflow' => 'PhabricatorConfigManagementWorkflow',
'PhabricatorConfigManagementSetWorkflow' => 'PhabricatorConfigManagementWorkflow',
'PhabricatorConfigManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorConfigOption' => array(
diff --git a/src/applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php b/src/applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php
--- a/src/applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php
+++ b/src/applications/config/management/PhabricatorConfigManagementDeleteWorkflow.php
@@ -7,10 +7,15 @@
$this
->setName('delete')
->setExamples('**delete** __key__')
- ->setSynopsis('Delete a local configuration value.')
+ ->setSynopsis(pht('Delete a local configuration value.'))
->setArguments(
array(
array(
+ 'name' => 'database',
+ 'help' => pht('Delete configuration in the database instead of '.
+ 'in local configuration.'),
+ ),
+ array(
'name' => 'args',
'wildcard' => true,
),
@@ -22,28 +27,38 @@
$argv = $args->getArg('args');
if (count($argv) == 0) {
- throw new PhutilArgumentUsageException(
- 'Specify a configuration key to delete.');
+ throw new PhutilArgumentUsageException(pht(
+ 'Specify a configuration key to delete.'));
}
$key = $argv[0];
if (count($argv) > 1) {
- throw new PhutilArgumentUsageException(
- 'Too many arguments: expected one key.');
+ throw new PhutilArgumentUsageException(pht(
+ 'Too many arguments: expected one key.'));
}
- $config = new PhabricatorConfigLocalSource();
+
+ $use_database = $args->getArg('database');
+ if ($use_database) {
+ $config = new PhabricatorConfigDatabaseSource('default');
+ $config_type = 'database';
+ } else {
+ $config = new PhabricatorConfigLocalSource();
+ $config_type = 'local';
+ }
$values = $config->getKeys(array($key));
if (!$values) {
- throw new PhutilArgumentUsageException(
- "Configuration key '{$key}' is not set in local configuration!");
+ throw new PhutilArgumentUsageException(pht(
+ "Configuration key '%s' is not set in %s configuration!",
+ $key,
+ $config_type));
}
$config->deleteKeys(array($key));
$console->writeOut(
- pht("Deleted '%s' from local configuration.", $key)."\n");
+ pht("Deleted '%s' from %s configuration.", $key, $config_type)."\n");
}
}
diff --git a/src/applications/config/management/PhabricatorConfigManagementMigrateWorkflow.php b/src/applications/config/management/PhabricatorConfigManagementMigrateWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/management/PhabricatorConfigManagementMigrateWorkflow.php
@@ -0,0 +1,72 @@
+<?php
+
+final class PhabricatorConfigManagementMigrateWorkflow
+ extends PhabricatorConfigManagementWorkflow {
+
+ protected function didConstruct() {
+ $this
+ ->setName('migrate')
+ ->setExamples('**migrate**')
+ ->setSynopsis(pht(
+ 'Migrate file-based configuration to more modern storage.'));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $console = PhutilConsole::getConsole();
+ $key_count = 0;
+
+ $options = PhabricatorApplicationConfigOptions::loadAllOptions();
+ $local_config = new PhabricatorConfigLocalSource();
+ $database_config = new PhabricatorConfigDatabaseSource('default');
+ $config_sources = PhabricatorEnv::getConfigSourceStack()->getStack();
+ $console->writeOut(
+ pht('Migrating file-based config to more modern config...')."\n");
+ foreach ($config_sources as $config_source) {
+ if (!($config_source instanceof PhabricatorConfigFileSource)) {
+ $console->writeOut(
+ pht('Skipping config of source type %s...',
+ get_class($config_source))."\n");
+ continue;
+ }
+ $console->writeOut(pht('Migrating file source...')."\n");
+ $all_keys = $config_source->getAllKeys();
+ foreach ($all_keys as $key => $value) {
+ $option = idx($options, $key);
+ if (!$option) {
+ $console->writeOut(pht('Skipping obsolete option: %s', $key)."\n");
+ continue;
+ }
+ $in_local = $local_config->getKeys(array($option->getKey()));
+ if ($in_local) {
+ $console->writeOut(pht(
+ 'Skipping option "%s"; already in local config.', $key)."\n");
+ continue;
+ }
+ $is_locked = $option->getLocked();
+ if ($is_locked) {
+ $local_config->setKeys(array($option->getKey() => $value));
+ $key_count++;
+ $console->writeOut(pht(
+ 'Migrated option "%s" from file to local config.', $key)."\n");
+ } else {
+ $in_database = $database_config->getKeys(array($option->getKey()));
+ if ($in_database) {
+ $console->writeOut(pht(
+ 'Skipping option "%s"; already in database config.', $key)."\n");
+ continue;
+ } else {
+ $database_config->setKeys(array($option->getKey() => $value));
+ $key_count++;
+ $console->writeOut(pht(
+ 'Migrated option "%s" from file to local config.', $key)."\n");
+ }
+ }
+ }
+ }
+
+ $console->writeOut(pht(
+ 'Done. Migrated %d keys.', $key_count)."\n");
+ return 0;
+ }
+
+}
diff --git a/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php b/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
--- a/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
+++ b/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
@@ -7,10 +7,15 @@
$this
->setName('set')
->setExamples('**set** __key__ __value__')
- ->setSynopsis('Set a local configuration value.')
+ ->setSynopsis(pht('Set a local configuration value.'))
->setArguments(
array(
array(
+ 'name' => 'database',
+ 'help' => pht('Update configuration in the database instead of '.
+ 'in local configuration.'),
+ ),
+ array(
'name' => 'args',
'wildcard' => true,
),
@@ -21,29 +26,31 @@
$console = PhutilConsole::getConsole();
$argv = $args->getArg('args');
if (count($argv) == 0) {
- throw new PhutilArgumentUsageException(
- 'Specify a configuration key and a value to set it to.');
+ throw new PhutilArgumentUsageException(pht(
+ 'Specify a configuration key and a value to set it to.'));
}
$key = $argv[0];
if (count($argv) == 1) {
- throw new PhutilArgumentUsageException(
- "Specify a value to set the key '{$key}' to.");
+ throw new PhutilArgumentUsageException(pht(
+ "Specify a value to set the key '%s' to.",
+ $key));
}
$value = $argv[1];
if (count($argv) > 2) {
- throw new PhutilArgumentUsageException(
- 'Too many arguments: expected one key and one value.');
+ throw new PhutilArgumentUsageException(pht(
+ 'Too many arguments: expected one key and one value.'));
}
$options = PhabricatorApplicationConfigOptions::loadAllOptions();
if (empty($options[$key])) {
- throw new PhutilArgumentUsageException(
- "No such configuration key '{$key}'! Use `config list` to list all ".
- "keys.");
+ throw new PhutilArgumentUsageException(pht(
+ "No such configuration key '%s'! Use `config list` to list all ".
+ "keys.",
+ $key));
}
$option = $options[$key];
@@ -57,8 +64,10 @@
break;
case 'int':
if (!ctype_digit($value)) {
- throw new PhutilArgumentUsageException(
- "Config key '{$key}' is of type '{$type}'. Specify an integer.");
+ throw new PhutilArgumentUsageException(pht(
+ "Config key '%s' is of type '%s'. Specify an integer.",
+ $key,
+ $type));
}
$value = (int)$value;
break;
@@ -68,19 +77,30 @@
} else if ($value == 'false') {
$value = false;
} else {
- throw new PhutilArgumentUsageException(
- "Config key '{$key}' is of type '{$type}'. ".
- "Specify 'true' or 'false'.");
+ throw new PhutilArgumentUsageException(pht(
+ "Config key '%s' is of type '%s'. ".
+ "Specify 'true' or 'false'.",
+ $key,
+ $type));
}
break;
default:
$value = json_decode($value, true);
if (!is_array($value)) {
- throw new PhutilArgumentUsageException(
- "Config key '{$key}' is of type '{$type}'. Specify it in JSON.");
+ throw new PhutilArgumentUsageException(pht(
+ "Config key '%s' is of type '%s'. Specify it in JSON.",
+ $key,
+ $type));
}
break;
}
+ $use_database = $args->getArg('database');
+ if ($option->getLocked() && $use_database) {
+ throw new PhutilArgumentUsageException(pht(
+ "Config key '%s' is locked and can only be set in local ".
+ 'configuration.',
+ $key));
+ }
try {
$option->getGroup()->validateOption($option, $value);
@@ -89,11 +109,18 @@
throw new PhutilArgumentUsageException($validation->getMessage());
}
- $config = new PhabricatorConfigLocalSource();
+ if ($use_database) {
+ $config = new PhabricatorConfigDatabaseSource('default');
+ $config_type = 'database';
+ } else {
+ $config = new PhabricatorConfigLocalSource();
+ $config_type = 'local';
+ }
+
$config->setKeys(array($key => $value));
$console->writeOut(
- pht("Set '%s' in local configuration.", $key)."\n");
+ pht("Set '%s' in %s configuration.", $key, $config_type)."\n");
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 11:24 AM (20 h, 14 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6763050
Default Alt Text
D10490.id25609.diff (11 KB)

Event Timeline