Skip to content

Commit 7ed30f4

Browse files
updated index validator for spatial types
1 parent d291d6a commit 7ed30f4

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/Database/Validator/Index.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,27 @@ public function checkSpatialIndex(Document $index): bool
340340
{
341341
$type = $index->getAttribute('type');
342342

343-
if (!$this->spatialIndexSupport) {
344-
$this->message = 'Spatial indexes are not supported';
345-
return false;
346-
}
347-
348343
$attributes = $index->getAttribute('attributes', []);
349344
$orders = $index->getAttribute('orders', []);
350345

351-
if (count($attributes) !== 1) {
352-
$this->message = 'Spatial index can be created on a single spatial attribute';
353-
return false;
354-
}
355-
356346
foreach ($attributes as $attributeName) {
357347
$attribute = $this->attributes[\strtolower($attributeName)] ?? new Document();
358348
$attributeType = $attribute->getAttribute('type', '');
349+
359350
if (!\in_array($attributeType, Database::SPATIAL_TYPES, true)) {
360351
continue;
361352
}
362353

354+
if (!$this->spatialIndexSupport) {
355+
$this->message = 'Spatial indexes are not supported';
356+
return false;
357+
}
358+
359+
if (count($attributes) !== 1) {
360+
$this->message = 'Spatial index can be created on a single spatial attribute';
361+
return false;
362+
}
363+
363364
if ($type !== Database::INDEX_SPATIAL) {
364365
$this->message = 'Spatial index can only be created on spatial attributes (point, linestring, polygon). Attribute "' . $attributeName . '" is of type "' . $attributeType . '"';
365366
return false;
@@ -369,13 +370,14 @@ public function checkSpatialIndex(Document $index): bool
369370
$this->message = 'Spatial indexes do not allow null values. Mark the attribute "' . $attributeName . '" as required or create the index on a column with no null values.';
370371
return false;
371372
}
372-
}
373373

374-
if (!empty($orders) && !$this->spatialIndexOrderSupport) {
375-
$this->message = 'Spatial indexes with explicit orders are not supported. Remove the orders to create this index.';
376-
return false;
374+
if (!empty($orders) && !$this->spatialIndexOrderSupport) {
375+
$this->message = 'Spatial indexes with explicit orders are not supported. Remove the orders to create this index.';
376+
return false;
377+
}
377378
}
378379

380+
379381
return true;
380382
}
381383
}

0 commit comments

Comments
 (0)