summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-22 10:56:29 +0300
committerYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:07:02 +0300
commit04acd3d6b9a95ff49d430eaf4f65aabc25282d88 (patch)
tree00e643a8a5678d4c8dcdce77afe5604860e21612 /src
parent0b466b90271553d0c4f620e326305453a4b23dd7 (diff)
downloadphorge-elasticsearch-modern-04acd3d6b9a95ff49d430eaf4f65aabc25282d88.tar.gz
phorge-elasticsearch-modern-04acd3d6b9a95ff49d430eaf4f65aabc25282d88.zip
Engine: Add setVersion() with strict validation
Engine accepts only versions 7 and above (covering ES 7.x, 8.x, and OpenSearch 1.x/2.x/3.x via the typeless API). Anything below 7 raises with a clear message pointing at the bundled engine for ES 5 users. 🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src')
-rw-r--r--src/__phutil_library_map__.php2
-rw-r--r--src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php38
-rw-r--r--src/engine/VyOSElasticModernFulltextStorageEngine.php21
3 files changed, 61 insertions, 0 deletions
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index 298810e..d365d58 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -10,12 +10,14 @@ phutil_register_library_map(array(
'__library_version__' => 2,
'class' => array(
'VyOSElasticModernFulltextStorageEngine' => 'engine/VyOSElasticModernFulltextStorageEngine.php',
+ 'VyOSElasticModernFulltextStorageEngineTestCase' => '__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php',
'VyOSElasticModernHost' => 'host/VyOSElasticModernHost.php',
'VyOSElasticModernHostTestCase' => '__tests__/VyOSElasticModernHostTestCase.php',
),
'function' => array(),
'xmap' => array(
'VyOSElasticModernFulltextStorageEngine' => 'PhabricatorFulltextStorageEngine',
+ 'VyOSElasticModernFulltextStorageEngineTestCase' => 'PhutilTestCase',
'VyOSElasticModernHost' => 'PhabricatorSearchHost',
'VyOSElasticModernHostTestCase' => 'PhutilTestCase',
),
diff --git a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
new file mode 100644
index 0000000..7a41ca1
--- /dev/null
+++ b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
@@ -0,0 +1,38 @@
+<?php
+
+final class VyOSElasticModernFulltextStorageEngineTestCase
+ extends PhutilTestCase {
+
+ public function testSetVersionAcceptsSevenAndAbove() {
+ foreach (array(7, 8, 9, 100) as $v) {
+ $engine = new VyOSElasticModernFulltextStorageEngine();
+ $caught = null;
+ try {
+ $engine->setVersion($v);
+ } catch (Exception $e) {
+ $caught = $e;
+ }
+ $this->assertEqual(
+ null,
+ $caught,
+ pht('Expected no exception for version=%d.', $v));
+ $this->assertEqual($v, $engine->getVersion());
+ }
+ }
+
+ public function testSetVersionRejectsBelowSeven() {
+ foreach (array(0, 1, 2, 5, 6) as $v) {
+ $engine = new VyOSElasticModernFulltextStorageEngine();
+ $caught = null;
+ try {
+ $engine->setVersion($v);
+ } catch (Exception $e) {
+ $caught = $e;
+ }
+ $this->assertTrue(
+ $caught !== null,
+ pht('Expected an exception for version=%d.', $v));
+ }
+ }
+
+}
diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php
index f11eeab..60683b1 100644
--- a/src/engine/VyOSElasticModernFulltextStorageEngine.php
+++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php
@@ -7,6 +7,27 @@
abstract class VyOSElasticModernFulltextStorageEngine
extends PhabricatorFulltextStorageEngine {
+ private $version;
+
+ public function setVersion($version) {
+ $version = (int)$version;
+ if ($version < 7) {
+ throw new Exception(
+ pht(
+ 'Unsupported Elasticsearch version "%d" for the '.
+ '"elasticsearch-modern" engine. This engine supports version 7 '.
+ 'and above (Elasticsearch 7.x, 8.x, or OpenSearch 1.x/2.x/3.x). '.
+ 'For ES 5.x, use the bundled "elasticsearch" engine instead.',
+ $version));
+ }
+ $this->version = $version;
+ return $this;
+ }
+
+ public function getVersion() {
+ return $this->version;
+ }
+
public function getEngineIdentifier() {
return 'elasticsearch-modern';
}