Throw exception on index creation if any attribute is not ready
This commit is contained in:
parent
2aa94e7897
commit
d57f7b0a30
|
@ -1217,7 +1217,6 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
|||
// lengths hidden by default
|
||||
$lengths = [];
|
||||
|
||||
// set attribute size as length for strings, null otherwise
|
||||
foreach ($attributes as $key => $attribute) {
|
||||
// find attribute metadata in collection document
|
||||
$attributeIndex = \array_search($attribute, array_column($oldAttributes, 'key'));
|
||||
|
@ -1226,10 +1225,16 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
|||
throw new Exception('Unknown attribute: ' . $attribute, 400);
|
||||
}
|
||||
|
||||
$attributeStatus = $oldAttributes[$attributeIndex]['status'];
|
||||
$attributeType = $oldAttributes[$attributeIndex]['type'];
|
||||
$attributeSize = $oldAttributes[$attributeIndex]['size'];
|
||||
|
||||
// Only set length for indexes on strings
|
||||
// ensure attribute is available
|
||||
if ($attributeStatus !== 'available') {
|
||||
throw new Exception ('Attribute not available: ' . $oldAttributes[$attributeIndex]['key'], 400);
|
||||
}
|
||||
|
||||
// set attribute size as index length only for strings
|
||||
$lengths[$key] = ($attributeType === Database::VAR_STRING) ? $attributeSize : null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue