From 23995c65457f535ce90c681c2ab4eb6dcc8e1385 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 14:46:31 +0300 Subject: [PATCH 1/6] Go by $id --- src/Database/Adapter/MariaDB.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index bf594d8e7..4530e3f38 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -762,27 +762,34 @@ public function createIndex(string $collection, string $id, string $type, array throw new NotFoundException('Collection not found'); } - $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); - $id = $this->filter($id); foreach ($attributes as $i => $attr) { - $collectionAttribute = \array_filter($collectionAttributes, fn ($collectionAttribute) => array_key_exists('key', $collectionAttribute) && $collectionAttribute['key'] === $attr); - $collectionAttribute = end($collectionAttribute); + $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); + + /** + * We do not have internalId's added to list + */ + $attribute = null; + foreach ($collectionAttributes as $collectionAttribute) { + if (\strtolower($collectionAttribute['$id']) === \strtolower($attr)) { + $attribute = $collectionAttribute; + break; + } + } + $order = empty($orders[$i]) || Database::INDEX_FULLTEXT === $type ? '' : $orders[$i]; $length = empty($lengths[$i]) ? '' : '(' . (int)$lengths[$i] . ')'; - $attr = match ($attr) { - '$id' => '_uid', - '$createdAt' => '_createdAt', - '$updatedAt' => '_updatedAt', - default => $this->filter($attr), - }; + $attr = $this->getInternalKeyForAttribute($attr); + $attr = $this->filter($attr); $attributes[$i] = "`{$attr}`{$length} {$order}"; - if (!empty($collectionAttribute['array']) && $this->getSupportForCastIndexArray()) { - $attributes[$i] = '(CAST(`' . $attr . '` AS char(' . Database::ARRAY_INDEX_LENGTH . ') ARRAY))'; + if($this->getSupportForCastIndexArray()){ + if (!empty($attribute['array'])) { + $attributes[$i] = '(CAST(`' . $attr . '` AS char(' . Database::ARRAY_INDEX_LENGTH . ') ARRAY))'; + } } } From 2695b9e9c3aa4c6d2fc394777005621931911911 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 14:53:21 +0300 Subject: [PATCH 2/6] Fix if case --- src/Database/Adapter/MariaDB.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 4530e3f38..deb001c71 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -786,10 +786,8 @@ public function createIndex(string $collection, string $id, string $type, array $attributes[$i] = "`{$attr}`{$length} {$order}"; - if($this->getSupportForCastIndexArray()){ - if (!empty($attribute['array'])) { - $attributes[$i] = '(CAST(`' . $attr . '` AS char(' . Database::ARRAY_INDEX_LENGTH . ') ARRAY))'; - } + if ($this->getSupportForCastIndexArray() && !empty($attribute['array'])) { + $attributes[$i] = '(CAST(`' . $attr . '` AS char(' . Database::ARRAY_INDEX_LENGTH . ') ARRAY))'; } } From 828a43929a839f767f3b07893f0840c2d1b39d11 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 15:08:13 +0300 Subject: [PATCH 3/6] Update message --- src/Database/Adapter/MariaDB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index deb001c71..123fd90c8 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -768,7 +768,7 @@ public function createIndex(string $collection, string $id, string $type, array $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); /** - * We do not have internalId's added to list + * We do not have internalId's added to list, no need since we check for is array field */ $attribute = null; foreach ($collectionAttributes as $collectionAttribute) { From 74ee3aa56975a142ce640f7ba1e066fa74b01f52 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 15:09:09 +0300 Subject: [PATCH 4/6] Update message --- src/Database/Adapter/MariaDB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 123fd90c8..a97de9b22 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -768,7 +768,7 @@ public function createIndex(string $collection, string $id, string $type, array $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); /** - * We do not have internalId's added to list, no need since we check for is array field + * We do not have internalId's added to list, since we check only for array field */ $attribute = null; foreach ($collectionAttributes as $collectionAttribute) { From fde0f4f169bcd8cbf33a2a9a42983619bbb887bf Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 15:38:46 +0300 Subject: [PATCH 5/6] Outside the loop --- src/Database/Adapter/MariaDB.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index a97de9b22..14fe63b2e 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -762,14 +762,15 @@ public function createIndex(string $collection, string $id, string $type, array throw new NotFoundException('Collection not found'); } + $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); + + /** + * We do not have internalId's added to list, since we check only for array field + */ + $id = $this->filter($id); foreach ($attributes as $i => $attr) { - $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); - - /** - * We do not have internalId's added to list, since we check only for array field - */ $attribute = null; foreach ($collectionAttributes as $collectionAttribute) { if (\strtolower($collectionAttribute['$id']) === \strtolower($attr)) { From 6602b05b65bfc69fcb8db539736c26d6789d3763 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 29 Apr 2025 15:44:36 +0300 Subject: [PATCH 6/6] message --- src/Database/Adapter/MariaDB.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 14fe63b2e..db3710e0a 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -762,11 +762,10 @@ public function createIndex(string $collection, string $id, string $type, array throw new NotFoundException('Collection not found'); } - $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); - /** * We do not have internalId's added to list, since we check only for array field */ + $collectionAttributes = \json_decode($collection->getAttribute('attributes', []), true); $id = $this->filter($id);