Remove product literal strings in "pht()", part 15
[phabricator.git] / src / applications / config / check / PhabricatorElasticsearchSetupCheck.php
blob8466c5a6c6497bc9f1ed808524f2abdcdc2dc2c9
1 <?php
3 final class PhabricatorElasticsearchSetupCheck extends PhabricatorSetupCheck {
5 public function getDefaultGroup() {
6 return self::GROUP_OTHER;
9 protected function executeChecks() {
10 // TODO: Avoid fataling if we don't have a master database configured
11 // but have the MySQL search index configured. See T12965.
12 if (PhabricatorEnv::isReadOnly()) {
13 return;
16 $services = PhabricatorSearchService::getAllServices();
18 foreach ($services as $service) {
19 try {
20 $host = $service->getAnyHostForRole('read');
21 } catch (PhabricatorClusterNoHostForRoleException $e) {
22 // ignore the error
23 continue;
25 if ($host instanceof PhabricatorElasticsearchHost) {
26 $index_exists = null;
27 $index_sane = null;
28 try {
29 $engine = $host->getEngine();
30 $index_exists = $engine->indexExists();
31 if ($index_exists) {
32 $index_sane = $engine->indexIsSane();
34 } catch (Exception $ex) {
35 $summary = pht('Elasticsearch is not reachable as configured.');
36 $message = pht(
37 'Elasticsearch is configured (with the %s setting) but an '.
38 'exception was encountered when trying to test the index.'.
39 "\n\n".
40 '%s',
41 phutil_tag('tt', array(), 'cluster.search'),
42 phutil_tag('pre', array(), $ex->getMessage()));
44 $this->newIssue('elastic.misconfigured')
45 ->setName(pht('Elasticsearch Misconfigured'))
46 ->setSummary($summary)
47 ->setMessage($message)
48 ->addRelatedPhabricatorConfig('cluster.search');
49 return;
52 if (!$index_exists) {
53 $summary = pht(
54 'You enabled Elasticsearch but the index does not exist.');
56 $message = pht(
57 'You likely enabled cluster.search without creating the '.
58 'index. Use the following command to create a new index.');
60 $this
61 ->newIssue('elastic.missing-index')
62 ->setName(pht('Elasticsearch Index Not Found'))
63 ->addCommand('./bin/search init')
64 ->setSummary($summary)
65 ->setMessage($message);
67 } else if (!$index_sane) {
68 $summary = pht(
69 'Elasticsearch index exists but needs correction.');
71 $message = pht(
72 'Either the schema for Elasticsearch has changed '.
73 'or Elasticsearch created the index automatically. '.
74 'Use the following command to rebuild the index.');
76 $this
77 ->newIssue('elastic.broken-index')
78 ->setName(pht('Elasticsearch Index Schema Mismatch'))
79 ->addCommand('./bin/search init')
80 ->setSummary($summary)
81 ->setMessage($message);