1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-08 12:58:31 +01:00
phorge-phorge/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php
epriestley 5f939dcce0 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
2017-03-28 14:53:26 -07:00

71 lines
1.7 KiB
PHP

<?php
final class PhabricatorSearchManagementInitWorkflow
extends PhabricatorSearchManagementWorkflow {
protected function didConstruct() {
$this
->setName('init')
->setSynopsis(pht('Initialize or repair a search service.'))
->setExamples('**init**');
}
public function execute(PhutilArgumentParser $args) {
$this->validateClusterSearchConfig();
$work_done = false;
foreach (PhabricatorSearchService::getAllServices() as $service) {
echo tsprintf(
"%s\n",
pht(
'Initializing search service "%s".',
$service->getDisplayName()));
if (!$service->isWritable()) {
echo tsprintf(
"%s\n",
pht(
'Skipping service "%s" because it is not writable.',
$service->getDisplayName()));
continue;
}
$engine = $service->getEngine();
if (!$engine->indexExists()) {
echo tsprintf(
"%s\n",
pht('Service index does not exist, creating...'));
$engine->initIndex();
$work_done = true;
} else if (!$engine->indexIsSane()) {
echo tsprintf(
"%s\n",
pht('Service index is out of date, repairing...'));
$engine->initIndex();
$work_done = true;
} else {
echo tsprintf(
"%s\n",
pht('Service index is already up to date.'));
}
echo tsprintf(
"%s\n",
pht('Done.'));
}
if (!$work_done) {
echo tsprintf(
"%s\n",
pht('No services need initialization.'));
return 0;
}
echo tsprintf(
"%s\n",
pht('Service initialization complete.'));
}
}