1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Make bin/search init messaging a little more consistent

Summary:
Ref T12450. This mostly just smooths out the text a little to improve consistency. Also:

  - Use `isWritable()`.
  - Make the "skipping because not writable" message more clear and tailored.
  - Try not to use the word "index" too much to avoid confusion with `bin/search index` -- instead, talk about "initialize a service".

Test Plan: Ran `bin/search init` with a couple of different (writable / not writable) configs, saw slightly clearer messaging.

Reviewers: chad, 20after4

Reviewed By: 20after4

Maniphest Tasks: T12450

Differential Revision: https://secure.phabricator.com/D17572
This commit is contained in:
epriestley 2017-03-28 12:47:58 -07:00
parent 699228c73b
commit e7c76d92d5

View file

@ -6,60 +6,65 @@ final class PhabricatorSearchManagementInitWorkflow
protected function didConstruct() {
$this
->setName('init')
->setSynopsis(pht('Initialize or repair an index.'))
->setSynopsis(pht('Initialize or repair a search service.'))
->setExamples('**init**');
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$work_done = false;
foreach (PhabricatorSearchService::getAllServices() as $service) {
$console->writeOut(
echo tsprintf(
"%s\n",
pht('Initializing search service "%s"', $service->getDisplayName()));
pht(
'Initializing search service "%s".',
$service->getDisplayName()));
try {
$host = $service->getAnyHostForRole('write');
} catch (PhabricatorClusterNoHostForRoleException $e) {
// If there are no writable hosts for a given cluster, skip it
$console->writeOut("%s\n", $e->getMessage());
if (!$service->isWritable()) {
echo tsprintf(
"%s\n",
pht(
'Skipping service "%s" because it is not writable.',
$service->getDisplayName()));
continue;
}
$engine = $host->getEngine();
$engine = $service->getEngine();
if (!$engine->indexExists()) {
$console->writeOut(
'%s',
pht('Index does not exist, creating...'));
$engine->initIndex();
$console->writeOut(
echo tsprintf(
"%s\n",
pht('done.'));
pht('Service index does not exist, creating...'));
$engine->initIndex();
$work_done = true;
} else if (!$engine->indexIsSane()) {
$console->writeOut(
'%s',
pht('Index exists but is incorrect, fixing...'));
$engine->initIndex();
$console->writeOut(
echo tsprintf(
"%s\n",
pht('done.'));
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) {
$console->writeOut(
if (!$work_done) {
echo tsprintf(
"%s\n",
pht(
'Index maintenance complete. Run `%s` to reindex documents',
'./bin/search index'));
} else {
$console->writeOut(
"%s\n",
pht('Nothing to do.'));
pht('No services need initialization.'));
return 0;
}
echo tsprintf(
"%s\n",
pht('Service initialization complete.'));
}
}