summaryrefslogtreecommitdiff
path: root/src/engine/VyOSElasticModernFulltextStorageEngine.php
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:54:24 +0300
committerYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:55:22 +0300
commit4d836601cb2f602c0089134eda1604f605fb39da (patch)
treed034801a5667eeb638983bf952a9c8ae3f4cb544 /src/engine/VyOSElasticModernFulltextStorageEngine.php
parent51ceab16c95efc5527445788cb83f0289675d0bf (diff)
downloadphorge-elasticsearch-modern-4d836601cb2f602c0089134eda1604f605fb39da.tar.gz
phorge-elasticsearch-modern-4d836601cb2f602c0089134eda1604f605fb39da.zip
E8 fixup: four correctness fixes from Phase 0 review
1. strlen(\$query_string) → null-safe check \$query->getParameter('query') may return null; strlen(null) is deprecated in PHP 8.1+. Switch to explicit !== null && !== '' check. 2. ids.values nesting fix in buildSpec() 'values' => array(\$exclude) wraps an already-array \$exclude in a nested array, producing invalid Elasticsearch ids syntax. Cast to (array) then re-index with array_values() so both scalar PHID and array-of-PHIDs produce a flat list. 3. initIndex() host consistency: pass write host to indexExists() initIndex() called indexExists() without a host argument, which fell back to the read host, then deleted via getHostForWrite(). A read/write split lag window could cause false-positive "index doesn't exist" results. Pass the already-resolved write host. 4. getIndexStats() unchecked array access \$res['indices'][\$this->index] was accessed without verifying the key exists. If the index was just deleted or the name drifted, this throws an undefined-offset PHP notice. Add an explicit isset() guard with a clear exception message naming the index. 🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src/engine/VyOSElasticModernFulltextStorageEngine.php')
-rw-r--r--src/engine/VyOSElasticModernFulltextStorageEngine.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php
index c49ff5e..70844f9 100644
--- a/src/engine/VyOSElasticModernFulltextStorageEngine.php
+++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php
@@ -313,7 +313,7 @@ abstract class VyOSElasticModernFulltextStorageEngine
private function buildSpec(PhabricatorSavedQuery $query, array $types) {
$q = new PhabricatorElasticsearchQueryBuilder();
$query_string = $query->getParameter('query');
- if (strlen($query_string)) {
+ if ($query_string !== null && $query_string !== '') {
$q->addMustClause(array(
'simple_query_string' => array(
'query' => $query_string,
@@ -343,9 +343,11 @@ abstract class VyOSElasticModernFulltextStorageEngine
$exclude = $query->getParameter('exclude');
if ($exclude) {
// Correct from day one: bool.must_not, not the obsolete 'not' clause.
+ // Cast to array so a single PHID scalar and an already-array of PHIDs
+ // both produce a flat list for the Elasticsearch ids.values field.
$q->addMustNotClause(array(
'ids' => array(
- 'values' => array($exclude),
+ 'values' => array_values((array)$exclude),
),
));
}
@@ -460,7 +462,7 @@ abstract class VyOSElasticModernFulltextStorageEngine
public function initIndex() {
$host = $this->getHostForWrite();
- if ($this->indexExists()) {
+ if ($this->indexExists($host)) {
$this->executeRequest($host, '/', array(), 'DELETE');
}
$data = $this->getIndexConfiguration();
@@ -472,6 +474,12 @@ abstract class VyOSElasticModernFulltextStorageEngine
$host = $this->getHostForRead();
}
$res = $this->executeRequest($host, '/_stats/', array());
+ if (!isset($res['indices'][$this->index])) {
+ throw new Exception(
+ pht(
+ 'Index "%s" not found in Elasticsearch _stats response.',
+ $this->index));
+ }
$stats = $res['indices'][$this->index];
return array(
pht('Queries') =>