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
148 changes: 77 additions & 71 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
stopOnFailure="false"
>
<testsuites>
<testsuite name="unit">
Expand Down
22 changes: 22 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,28 @@ abstract public function getSupportForBoundaryInclusiveContains(): bool;
*/
abstract public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters(): bool;

/**
* Does the adapter support multiple fulltext indexes?
*
* @return bool
*/
abstract public function getSupportForMultipleFulltextIndexes(): bool;


/**
* Does the adapter support identical indexes?
*
* @return bool
*/
abstract public function getSupportForIdenticalIndexes(): bool;

/**
* Does the adapter support random order by?
*
* @return bool
*/
abstract public function getSupportForOrderRandom(): bool;

/**
* Get current attribute count from collection document
*
Expand Down
75 changes: 59 additions & 16 deletions src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ public function createCollection(string $name, array $attributes = [], array $in
unset($index);
}

$indexesCreated = $this->client->createIndexes($id, $internalIndex);
try {
$indexesCreated = $this->client->createIndexes($id, $internalIndex);
} catch (\Exception $e) {
throw $this->processException($e);
}

if (!$indexesCreated) {
return false;
Expand Down Expand Up @@ -327,7 +331,14 @@ public function createCollection(string $name, array $attributes = [], array $in
}
}

if (!$this->getClient()->createIndexes($id, $newIndexes)) {

try {
$indexesCreated = $this->getClient()->createIndexes($id, $newIndexes);
} catch (\Exception $e) {
throw $this->processException($e);
}

if (!$indexesCreated) {
return false;
}
}
Expand Down Expand Up @@ -714,8 +725,11 @@ public function createIndex(string $collection, string $id, string $type, array
$indexes['partialFilterExpression'] = $partialFilter;
}
}

return $this->client->createIndexes($name, [$indexes], $options);
try {
return $this->client->createIndexes($name, [$indexes], $options);
} catch (\Exception $e) {
throw $this->processException($e);
}
}

/**
Expand Down Expand Up @@ -762,18 +776,14 @@ public function renameIndex(string $collection, string $old, string $new): bool
}
}

if ($index
&& $this->deleteIndex($collection, $old)
&& $this->createIndex(
$collection,
$new,
$index['type'],
$index['attributes'],
$index['lengths'] ?? [],
$index['orders'] ?? [],
$indexAttributeTypes, // Use extracted attribute types
[]
)) {
try {
$deletedindex = $this->deleteIndex($collection, $old);
$createdindex = $this->createIndex($collection, $new, $index['type'], $index['attributes'], $index['lengths'] ?? [], $index['orders'] ?? [], $indexAttributeTypes, []);
} catch (\Exception $e) {
throw $this->processException($e);
}

if ($index && $deletedindex && $createdindex) {
return true;
}

Expand Down Expand Up @@ -2542,6 +2552,39 @@ public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters(): bo
return false;
}

public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return false;
}

/**
* Does the adapter support multiple fulltext indexes?
*
* @return bool
*/
public function getSupportForMultipleFulltextIndexes(): bool
{
return false;
}
/**
* Does the adapter support identical indexes?
*
* @return bool
*/
public function getSupportForIdenticalIndexes(): bool
{
return false;
}

/**
* Does the adapter support random order for queries?
*
* @return bool
*/
public function getSupportForOrderRandom(): bool
{
return false;
}

/**
* Flattens the array.
Expand Down
31 changes: 16 additions & 15 deletions src/Database/Adapter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,36 +524,37 @@ public function getSupportForSpatialIndexOrder(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}
/**
* Does the adapter support calculating distance(in meters) between multidimension geometry(line, polygon,etc)?
*
* @return bool
*/

public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

/**
* Does the adapter support spatial axis order specification?
*
* @return bool
*/
public function getSupportForSpatialAxisOrder(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function getSupportForMultipleFulltextIndexes(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function getSupportForIdenticalIndexes(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function getSupportForOrderRandom(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function decodePoint(string $wkb): array
{
return $this->delegate(__FUNCTION__, \func_get_args());
Expand Down
38 changes: 34 additions & 4 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -1513,15 +1513,45 @@ public function getSupportForSpatialIndexOrder(): bool
}

/**
* Is internal casting supported?
*
* @return bool
*/
* Is internal casting supported?
*
* @return bool
*/
public function getSupportForInternalCasting(): bool
{
return false;
}

/**
* Does the adapter support multiple fulltext indexes?
*
* @return bool
*/
public function getSupportForMultipleFulltextIndexes(): bool
{
return true;
}

/**
* Does the adapter support identical indexes?
*
* @return bool
*/
public function getSupportForIdenticalIndexes(): bool
{
return true;
}

/**
* Does the adapter support random order for queries?
*
* @return bool
*/
public function getSupportForOrderRandom(): bool
{
return true;
}

public function isMongo(): bool
{
return false;
Expand Down
27 changes: 22 additions & 5 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1407,13 +1407,16 @@ public function createCollection(string $id, array $attributes = [], array $inde
if ($this->validate) {
$validator = new IndexValidator(
$attributes,
[],
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray(),
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
$this->adapter->getSupportForAttributes(),
$this->adapter->getSupportForMultipleFulltextIndexes(),
$this->adapter->getSupportForIdenticalIndexes(),
);
foreach ($indexes as $index) {
if (!$validator->isValid($index)) {
Expand Down Expand Up @@ -2247,6 +2250,13 @@ public function updateAttributeDefault(string $collection, string $id, mixed $de
public function updateAttribute(string $collection, string $id, ?string $type = null, ?int $size = null, ?bool $required = null, mixed $default = null, ?bool $signed = null, ?bool $array = null, ?string $format = null, ?array $formatOptions = null, ?array $filters = null, ?string $newKey = null): Document
{
return $this->updateAttributeMeta($collection, $id, function ($attribute, $collectionDoc, $attributeIndex) use ($collection, $id, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters, $newKey) {

// Store original indexes before any modifications (deep copy preserving Document objects)
$originalIndexes = [];
foreach ($collectionDoc->getAttribute('indexes', []) as $index) {
$originalIndexes[] = clone $index;
}

$altering = !\is_null($type)
|| !\is_null($size)
|| !\is_null($signed)
Expand Down Expand Up @@ -2417,13 +2427,16 @@ public function updateAttribute(string $collection, string $id, ?string $type =
if ($this->validate) {
$validator = new IndexValidator(
$attributes,
$originalIndexes,
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray(),
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
$this->adapter->getSupportForAttributes(),
$this->adapter->getSupportForMultipleFulltextIndexes(),
$this->adapter->getSupportForIdenticalIndexes(),
);

foreach ($indexes as $index) {
Expand Down Expand Up @@ -3356,24 +3369,28 @@ public function createIndex(string $collection, string $id, string $type, array
'orders' => $orders,
]);

$collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND);

if ($this->validate) {

$validator = new IndexValidator(
$collection->getAttribute('attributes', []),
$collection->getAttribute('indexes', []),
$this->adapter->getMaxIndexLength(),
$this->adapter->getInternalIndexesKeys(),
$this->adapter->getSupportForIndexArray(),
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
$this->adapter->getSupportForAttributes(),
$this->adapter->getSupportForMultipleFulltextIndexes(),
$this->adapter->getSupportForIdenticalIndexes(),
);
if (!$validator->isValid($index)) {
throw new IndexException($validator->getDescription());
}
}

$collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND);

try {
$created = $this->adapter->createIndex($collection->getId(), $id, $type, $attributes, $lengths, $orders, $indexAttributesWithTypes);

Expand Down
Loading