public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $argv = $args->getArg('args'); if (count($argv) == 0) { throw new PhutilArgumentUsageException(pht('Specify a configuration key to delete.')); } $key = $argv[0]; if (count($argv) > 1) { throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key.')); } $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(pht("Configuration key '%s' is not set in %s configuration!", $key, $config_type)); } if ($use_database) { $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); $config_entry->setIsDeleted(1); $config_entry->save(); } else { $config->deleteKeys(array($key)); } $console->writeOut("%s\n", pht("Deleted '%s' from %s configuration.", $key, $config_type)); }
public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $argv = $args->getArg('args'); if (count($argv) == 0) { throw new PhutilArgumentUsageException('Specify a configuration key to get.'); } $key = $argv[0]; if (count($argv) > 1) { throw new PhutilArgumentUsageException('Too many arguments: expected one key.'); } $options = PhabricatorApplicationConfigOptions::loadAllOptions(); if (empty($options[$key])) { throw new PhutilArgumentUsageException("No such configuration key '{$key}'! Use `config list` to list all " . "keys."); } $config = new PhabricatorConfigLocalSource(); $values = $config->getKeys(array($key)); $result = array(); foreach ($values as $key => $value) { $result[] = array('key' => $key, 'source' => 'local', 'value' => $value); } $result = array('config' => $result); $json = new PhutilJSON(); $console->writeOut($json->encodeFormatted($result)); }
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 to delete.'); } $key = $argv[0]; if (count($argv) > 1) { throw new PhutilArgumentUsageException('Too many arguments: expected one key.'); } $config = new PhabricatorConfigLocalSource(); $values = $config->getKeys(array($key)); if (!$values) { throw new PhutilArgumentUsageException("Configuration key '{$key}' is not set in local configuration!"); } $config->deleteKeys(array($key)); $console->writeOut(pht("Deleted '%s' from local configuration.", $key) . "\n"); }
public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $argv = $args->getArg('args'); if (count($argv) == 0) { throw new PhutilArgumentUsageException(pht('Specify a configuration key to get.')); } $key = $argv[0]; if (count($argv) > 1) { throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key.')); } $options = PhabricatorApplicationConfigOptions::loadAllOptions(); if (empty($options[$key])) { throw new PhutilArgumentUsageException(pht("No such configuration key '%s'! Use `%s` to list all keys.", $key, 'config list')); } $values = array(); $config = new PhabricatorConfigLocalSource(); $local_value = $config->getKeys(array($key)); if (empty($local_value)) { $values['local'] = array('key' => $key, 'value' => null, 'status' => 'unset', 'errorInfo' => null); } else { $values['local'] = array('key' => $key, 'value' => reset($local_value), 'status' => 'set', 'errorInfo' => null); } try { $database_config = new PhabricatorConfigDatabaseSource('default'); $database_value = $database_config->getKeys(array($key)); if (empty($database_value)) { $values['database'] = array('key' => $key, 'value' => null, 'status' => 'unset', 'errorInfo' => null); } else { $values['database'] = array('key' => $key, 'value' => reset($database_value), 'status' => 'set', 'errorInfo' => null); } } catch (Exception $e) { $values['database'] = array('key' => $key, 'value' => null, 'status' => 'error', 'errorInfo' => pht('Database source is not configured properly')); } $result = array(); foreach ($values as $source => $value) { $result[] = array('key' => $value['key'], 'source' => $source, 'value' => $value['value'], 'status' => $value['status'], 'errorInfo' => $value['errorInfo']); } $result = array('config' => $result); $json = new PhutilJSON(); $console->writeOut($json->encodeFormatted($result)); }
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"); }