diff options
| author | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-23 13:44:01 +0300 |
|---|---|---|
| committer | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-23 13:44:01 +0300 |
| commit | f945e302f79086c6ea99bd45d414fe6bccefb9d4 (patch) | |
| tree | 8d7d90a03b09cc21f0d80f7038cc1da88779dbb9 /src | |
| parent | de83584f8b782bde516d6b39f9f1bc4214585058 (diff) | |
| download | phorge-elasticsearch-modern-f945e302f79086c6ea99bd45d414fe6bccefb9d4.tar.gz phorge-elasticsearch-modern-f945e302f79086c6ea99bd45d414fe6bccefb9d4.zip | |
E6 fixup: use trim() + empty-string guard in setService(); use newEngine() in tests
- str_replace('/', '', \$index) → trim(\$index, '/') to preserve internal
slashes in multi-segment index paths (e.g. 'phabricator/prod' must
stay intact; only leading/trailing slashes are stripped).
- Add empty-string guard: after trim, throw a clear exception if the
result is '' so misconfigured paths fail loudly at setService() rather
than silently at query time with a confusing endpoint URL.
- Replace direct new VyOSElasticModernFulltextStorageEngine() in the
four new test methods with \$this->newEngine() to avoid PHP fatal on
abstract class instantiation.
🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src')
| -rw-r--r-- | src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php | 21 | ||||
| -rw-r--r-- | src/engine/VyOSElasticModernFulltextStorageEngine.php | 40 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php index e3daab4..9f08f8c 100644 --- a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php +++ b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php @@ -236,4 +236,25 @@ final class VyOSElasticModernFulltextStorageEngineTestCase $this->assertEqual('date', $mappings['properties']['lastModified']['type']); } + public function testEngineIdentifier() { + $engine = $this->newEngine(); + $this->assertEqual('elasticsearch-modern', $engine->getEngineIdentifier()); + } + + public function testHostType() { + $engine = $this->newEngine(); + $host = $engine->getHostType(); + $this->assertTrue($host instanceof VyOSElasticModernHost); + } + + public function testGetTextFieldType() { + $engine = $this->newEngine()->setVersion(7); + $this->assertEqual('text', $engine->getTextFieldType()); + } + + public function testGetTimestampField() { + $engine = $this->newEngine()->setVersion(7); + $this->assertEqual('lastModified', $engine->getTimestampField()); + } + } diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php index fe88adc..42e2fd6 100644 --- a/src/engine/VyOSElasticModernFulltextStorageEngine.php +++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php @@ -8,6 +8,46 @@ abstract class VyOSElasticModernFulltextStorageEngine extends PhabricatorFulltextStorageEngine { private $version = null; + private $index; + + public function setService(PhabricatorSearchService $service) { + $this->service = $service; // inherited protected property + $config = $service->getConfig(); + $index = idx($config, 'path', '/phabricator'); + $normalized = trim($index, '/'); + if ($normalized === '') { + throw new Exception( + pht( + 'Invalid index path "%s" in cluster.search config: '. + 'path must contain at least one non-slash character.', + $index)); + } + $this->index = $normalized; + $this->setVersion(idx($config, 'version', 7)); + return $this; + } + + public function getTimestampField() { + return 'lastModified'; + } + + public function getTextFieldType() { + return 'text'; + } + + public function getHostForRead() { + return $this->getService()->getAnyHostForRole('read'); + } + + public function getHostForWrite() { + return $this->getService()->getAnyHostForRole('write'); + } + + public function getTypeConstants($class) { + $relationship_class = new ReflectionClass($class); + $typeconstants = $relationship_class->getConstants(); + return array_unique(array_values($typeconstants)); + } public function setVersion($version) { $version = (int)$version; |
