1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Re-run config validation from bin/search

Summary:
Ref T12450. Normally, we validate config when:

  - You restart the webserver.
  - You edit it with `bin/config set ...`.
  - You edit it with the web UI.

However, you can also change config by editing `local.json`, `some_env.conf.php`, a `SiteConfig` class, etc. In these cases, you may miss config warnings.

Explicitly re-run search config checks from `bin/search`, similar to the additional database checks we run from `bin/storage`, to try to produce a better error message if the user has made a configuration error.

Test Plan:
```
$ ./bin/search init
Usage Exception: Setting "cluster.search" is misconfigured: Invalid search engine type: elastic. Valid types are: elasticsearch, mysql.
```

Reviewers: chad, 20after4

Reviewed By: 20after4

Maniphest Tasks: T12450

Differential Revision: https://secure.phabricator.com/D17574
This commit is contained in:
epriestley 2017-03-28 13:09:27 -07:00
parent 8879118b69
commit 5f939dcce0
4 changed files with 32 additions and 2 deletions

View file

@ -45,6 +45,8 @@ final class PhabricatorSearchManagementIndexWorkflow
}
public function execute(PhutilArgumentParser $args) {
$this->validateClusterSearchConfig();
$console = PhutilConsole::getConsole();
$is_all = $args->getArg('all');

View file

@ -11,6 +11,7 @@ final class PhabricatorSearchManagementInitWorkflow
}
public function execute(PhutilArgumentParser $args) {
$this->validateClusterSearchConfig();
$work_done = false;
foreach (PhabricatorSearchService::getAllServices() as $service) {

View file

@ -1,4 +1,26 @@
<?php
abstract class PhabricatorSearchManagementWorkflow
extends PhabricatorManagementWorkflow {}
extends PhabricatorManagementWorkflow {
protected function validateClusterSearchConfig() {
// Configuration is normally validated by setup self-checks on the web
// workflow, but users may reasonsably run `bin/search` commands after
// making manual edits to "local.json". Re-verify configuration here before
// continuing.
$config_key = 'cluster.search';
$config_value = PhabricatorEnv::getEnvConfig($config_key);
try {
PhabricatorClusterSearchConfigOptionType::validateValue($config_value);
} catch (Exception $ex) {
throw new PhutilArgumentUsageException(
pht(
'Setting "%s" is misconfigured: %s',
$config_key,
$ex->getMessage()));
}
}
}

View file

@ -4,6 +4,10 @@ final class PhabricatorClusterSearchConfigOptionType
extends PhabricatorConfigJSONOptionType {
public function validateOption(PhabricatorConfigOption $option, $value) {
self::validateClusterSearchConfigValue($value);
}
public static function validateValue($value) {
if (!is_array($value)) {
throw new Exception(
pht(
@ -46,7 +50,8 @@ final class PhabricatorClusterSearchConfigOptionType
if (!array_key_exists($spec['type'], $engines)) {
throw new Exception(
pht('Invalid search engine type: %s. Valid types include: %s',
pht(
'Invalid search engine type: %s. Valid types are: %s.',
$spec['type'],
implode(', ', array_keys($engines))));
}