@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorElasticsearchSetupCheck extends PhabricatorSetupCheck {
4
5 public function getDefaultGroup() {
6 return self::GROUP_OTHER;
7 }
8
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;
14 }
15
16 $services = PhabricatorSearchService::getAllServices();
17
18 foreach ($services as $service) {
19 try {
20 $host = $service->getAnyHostForRole('read');
21 } catch (PhabricatorClusterNoHostForRoleException $e) {
22 // ignore the error
23 continue;
24 }
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();
33 }
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()));
43
44 $this->newIssue('elastic.misconfigured')
45 ->setName(pht('Elasticsearch Misconfigured'))
46 ->setSummary($summary)
47 ->setMessage($message)
48 ->addRelatedPhabricatorConfig('cluster.search');
49 return;
50 }
51
52 if (!$index_exists) {
53 $summary = pht(
54 'You enabled Elasticsearch but the index does not exist.');
55
56 $message = pht(
57 'You likely enabled cluster.search without creating the '.
58 'index. Use the following command to create a new index.');
59
60 $this
61 ->newIssue('elastic.missing-index')
62 ->setName(pht('Elasticsearch Index Not Found'))
63 ->addCommand(
64 hsprintf(
65 '<samp>%s $</samp><kbd>./bin/search init</kbd>',
66 PlatformSymbols::getPlatformServerPath()))
67 ->setSummary($summary)
68 ->setMessage($message);
69
70 } else if (!$index_sane) {
71 $summary = pht(
72 'Elasticsearch index exists but needs correction.');
73
74 $message = pht(
75 'Either the schema for Elasticsearch has changed '.
76 'or Elasticsearch created the index automatically. '.
77 'Use the following command to rebuild the index.');
78
79 $this
80 ->newIssue('elastic.broken-index')
81 ->setName(pht('Elasticsearch Index Schema Mismatch'))
82 ->addCommand(
83 hsprintf(
84 '<samp>%s $</samp><kbd>./bin/search init</kbd>',
85 PlatformSymbols::getPlatformServerPath()))
86 ->setSummary($summary)
87 ->setMessage($message);
88 }
89 }
90 }
91 }
92
93
94}