Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2102,4 +2102,12 @@ public function getSupportForNumericCasting(): bool
{
return true;
}

public function getSupportForIndexArray(): bool
{
/**
* Disabled to be compatible with Mysql adapter
*/
return false;
}
}
17 changes: 6 additions & 11 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1242,10 +1242,6 @@ public function createCollection(string $id, array $attributes = [], array $inde

$isArray = $collectionAttribute->getAttribute('array', false);
if ($isArray) {
if (!$this->adapter->getSupportForIndexArray()) {
throw new IndexException('Indexing an array attribute is not supported');
}

if ($this->adapter->getMaxIndexLength() > 0) {
$lengths[$i] = self::ARRAY_INDEX_LENGTH;
}
Expand Down Expand Up @@ -1274,7 +1270,8 @@ public function createCollection(string $id, array $attributes = [], array $inde
$validator = new IndexValidator(
$attributes,
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys()
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray()
);
foreach ($indexes as $index) {
if (!$validator->isValid($index)) {
Expand Down Expand Up @@ -2199,7 +2196,8 @@ public function updateAttribute(string $collection, string $id, ?string $type =
$validator = new IndexValidator(
$attributes,
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys()
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray()
);

foreach ($indexes as $index) {
Expand Down Expand Up @@ -3079,10 +3077,6 @@ public function createIndex(string $collection, string $id, string $type, array

$isArray = $collectionAttribute->getAttribute('array', false);
if ($isArray) {
if (!$this->adapter->getSupportForIndexArray()) {
throw new IndexException('Indexing an array attribute is not supported');
}

if ($this->adapter->getMaxIndexLength() > 0) {
$lengths[$i] = self::ARRAY_INDEX_LENGTH;
}
Expand All @@ -3108,7 +3102,8 @@ public function createIndex(string $collection, string $id, string $type, array
$validator = new IndexValidator(
$collection->getAttribute('attributes', []),
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys()
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray()
);
if (!$validator->isValid($index)) {
throw new IndexException($validator->getDescription());
Expand Down
11 changes: 10 additions & 1 deletion src/Database/Validator/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ class Index extends Validator
*/
protected array $reservedKeys;

protected bool $arrayIndexSupport;

/**
* @param array<Document> $attributes
* @param int $maxLength
* @param array<string> $reservedKeys
* @param bool $arrayIndexSupport
* @throws DatabaseException
*/
public function __construct(array $attributes, int $maxLength, array $reservedKeys = [])
public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], bool $arrayIndexSupport = false)
{
$this->maxLength = $maxLength;
$this->reservedKeys = $reservedKeys;
$this->arrayIndexSupport = $arrayIndexSupport;

foreach ($attributes as $attribute) {
$key = \strtolower($attribute->getAttribute('key', $attribute->getAttribute('$id')));
Expand Down Expand Up @@ -156,6 +160,11 @@ public function checkArrayIndex(Document $index): bool
$this->message = 'Invalid index order "' . $direction . '" on array attribute "'. $attribute->getAttribute('key', '') .'"';
return false;
}

if ($this->arrayIndexSupport === false) {
$this->message = 'Indexing an array attribute is not supported';
return false;
}
} elseif ($attribute->getAttribute('type') !== Database::VAR_STRING && !empty($lengths[$attributePosition])) {
$this->message = 'Cannot set a length on "'. $attribute->getAttribute('type') . '" attributes';
return false;
Expand Down