From e7c76d92d546b2b331a3aa1b10fb182b4320f4f9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 28 Mar 2017 12:47:58 -0700 Subject: [PATCH] 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 --- ...habricatorSearchManagementInitWorkflow.php | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php index 1b5da49e66..c984b2ddbf 100644 --- a/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php +++ b/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php @@ -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.')); } }