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("%s\n", pht('Migrating file-based config to more modern config...')); foreach ($config_sources as $config_source) { if (!$config_source instanceof PhabricatorConfigFileSource) { $console->writeOut("%s\n", pht('Skipping config of source type %s...', get_class($config_source))); continue; } $console->writeOut("%s\n", pht('Migrating file source...')); $all_keys = $config_source->getAllKeys(); foreach ($all_keys as $key => $value) { $option = idx($options, $key); if (!$option) { $console->writeOut("%s\n", pht('Skipping obsolete option: %s', $key)); continue; } $in_local = $local_config->getKeys(array($option->getKey())); if ($in_local) { $console->writeOut("%s\n", pht('Skipping option "%s"; already in local config.', $key)); continue; } $is_locked = $option->getLocked(); if ($is_locked) { $local_config->setKeys(array($option->getKey() => $value)); $key_count++; $console->writeOut("%s\n", pht('Migrated option "%s" from file to local config.', $key)); } else { $in_database = $database_config->getKeys(array($option->getKey())); if ($in_database) { $console->writeOut("%s\n", pht('Skipping option "%s"; already in database config.', $key)); continue; } else { $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); $config_entry->setValue($value); $config_entry->save(); $key_count++; $console->writeOut("%s\n", pht('Migrated option "%s" from file to database config.', $key)); } } } } $console->writeOut("%s\n", pht('Done. Migrated %d keys.', $key_count)); return 0; }
public function execute(PhutilArgumentParser $args) { $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.'); } $key = $argv[0]; if (count($argv) == 1) { throw new PhutilArgumentUsageException("Specify a value to set the key '{$key}' to."); } $value = $argv[1]; if (count($argv) > 2) { throw new PhutilArgumentUsageException('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."); } $option = $options[$key]; $type = $option->getType(); switch ($type) { case 'string': case 'class': case 'enum': $value = (string) $value; break; case 'int': if (!ctype_digit($value)) { throw new PhutilArgumentUsageException("Config key '{$key}' is of type '{$type}'. Specify an integer."); } $value = (int) $value; break; case 'bool': if ($value == 'true') { $value = true; } else { if ($value == 'false') { $value = false; } else { throw new PhutilArgumentUsageException("Config key '{$key}' is of type '{$type}'. " . "Specify 'true' or 'false'."); } } 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."); } break; } try { $option->getGroup()->validateOption($option, $value); } catch (PhabricatorConfigValidationException $validation) { // Convert this into a usage exception so we don't dump a stack trace. throw new PhutilArgumentUsageException($validation->getMessage()); } $config = new PhabricatorConfigLocalSource(); $config->setKeys(array($key => $value)); $console->writeOut(pht("Set '%s' in local configuration.", $key) . "\n"); }