From 4d836601cb2f602c0089134eda1604f605fb39da Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Sat, 23 May 2026 13:54:24 +0300 Subject: E8 fixup: four correctness fixes from Phase 0 review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/engine/VyOSElasticModernFulltextStorageEngine.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/engine/VyOSElasticModernFulltextStorageEngine.php') 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') => -- cgit v1.2.3