From a9fd6c628290276bf4f9e87010652cca75de7c9f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 31 Mar 2026 19:47:55 +1300 Subject: [PATCH] (fix): resolve PermissionType enum, Method enum, VectorsDB and database library issues - Use PermissionType->value when constructing Permission objects (Documents/Create, Upsert, Transactions/Create, Storage/Files/Create) - Convert Method enum to string in Realtime adapter implode and interpolation - Use Attribute/Index object property access in VectorsDB Collections/Create - Update utopia-php/database with Structure Float case, TenantFilter alias fix, and Document::getTenant() type cast removal Co-Authored-By: Claude Opus 4.6 (1M context) --- composer.lock | 8 ++-- src/Appwrite/Messaging/Adapter/Realtime.php | 4 +- .../Collections/Documents/Create.php | 2 +- .../Collections/Documents/Upsert.php | 2 +- .../Http/Databases/Transactions/Create.php | 2 +- .../Http/VectorsDB/Collections/Create.php | 42 +++++++++---------- .../Storage/Http/Buckets/Files/Create.php | 2 +- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/composer.lock b/composer.lock index 01c1fa5e8e..58748e01ca 100644 --- a/composer.lock +++ b/composer.lock @@ -4038,12 +4038,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "2444fe6006d173ccc655f9e00fc4b294a4217a30" + "reference": "89e7afcc42863673766df3007c8f2feed31445e2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/2444fe6006d173ccc655f9e00fc4b294a4217a30", - "reference": "2444fe6006d173ccc655f9e00fc4b294a4217a30", + "url": "https://api.github.com/repos/utopia-php/database/zipball/89e7afcc42863673766df3007c8f2feed31445e2", + "reference": "89e7afcc42863673766df3007c8f2feed31445e2", "shasum": "" }, "require": { @@ -4091,7 +4091,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/feat-query-lib" }, - "time": "2026-03-31T05:55:38+00:00" + "time": "2026-03-31T06:36:52+00:00" }, { "name": "utopia-php/detector", diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index 5034506902..305cbce119 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -415,7 +415,7 @@ class Realtime extends MessagingAdapter { $queries = Query::parseQueries($queries); $stack = $queries; - $allowed = implode(', ', RuntimeQuery::ALLOWED_QUERIES); + $allowed = implode(', ', array_map(fn (Method $m) => $m->value, RuntimeQuery::ALLOWED_QUERIES)); while (!empty($stack)) { $query = array_pop($stack); @@ -423,7 +423,7 @@ class Realtime extends MessagingAdapter if (!in_array($method, RuntimeQuery::ALLOWED_QUERIES, true)) { throw new QueryException( - "Query method '{$method}' is not supported in Realtime queries. Allowed: {$allowed}" + "Query method '{$method->value}' is not supported in Realtime queries. Allowed: {$allowed}" ); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index a1d0c49142..478834f656 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -235,7 +235,7 @@ class Create extends Action $permissions = []; if (!empty($user->getId()) && !$isPrivilegedUser) { foreach ($allowedPermissions as $permission) { - $permissions[] = (new Permission($permission, 'user', $user->getId()))->toString(); + $permissions[] = (new Permission($permission->value, 'user', $user->getId()))->toString(); } } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index cae34e9c71..c95206c58b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -152,7 +152,7 @@ class Upsert extends Action if (!empty($user->getId())) { $defaultPermissions = []; foreach ($allowedPermissions as $permission) { - $defaultPermissions[] = (new Permission($permission, 'user', $user->getId()))->toString(); + $defaultPermissions[] = (new Permission($permission->value, 'user', $user->getId()))->toString(); } $permissions = $defaultPermissions; } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php index 43839ca9b1..ae4c886753 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php @@ -71,7 +71,7 @@ class Create extends Action ]; foreach ($allowedPermissions as $permission) { - $permissions[] = (new Permission($permission, 'user', $user->getId()))->toString(); + $permissions[] = (new Permission($permission->value, 'user', $user->getId()))->toString(); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php index 175625c253..9bff792c29 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php @@ -21,6 +21,7 @@ use Utopia\Database\Exception\Limit as LimitException; use Utopia\Database\Exception\NotFound as NotFoundException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; +use Utopia\Database\Index; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; @@ -141,45 +142,42 @@ class Create extends CollectionAction ); // Create attribute and indexes metadata documents in the attributes and indexes collections // needed for the get and list calls - $attributeDocs = array_map(function ($attributeConfig) use ($database, $collection, $databaseId, $collectionId, $dimension) { - $key = \is_string($attributeConfig['$id']) ? $attributeConfig['$id'] : (string) $attributeConfig['$id']; + $attributeDocs = array_map(function (Attribute $attributeConfig) use ($database, $collection, $databaseId, $collectionId, $dimension) { return new Document([ - '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), - 'key' => $key, + '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $attributeConfig->key), + 'key' => $attributeConfig->key, 'databaseInternalId' => $database->getSequence(), 'databaseId' => $databaseId, 'collectionInternalId' => $collection->getSequence(), 'collectionId' => $collectionId, - 'type' => $attributeConfig['type'], + 'type' => $attributeConfig->type->value, 'status' => 'available', 'size' => $dimension, - 'required' => $attributeConfig['required'] ?? false, - 'signed' => $attributeConfig['signed'] ?? false, - 'default' => $attributeConfig['default'] ?? null, - 'array' => $attributeConfig['array'] ?? false, - 'format' => $attributeConfig['format'] ?? '', - 'formatOptions' => $attributeConfig['formatOptions'] ?? [], - 'filters' => $attributeConfig['filters'] ?? [], - 'options' => $attributeConfig['options'] ?? [], + 'required' => $attributeConfig->required, + 'signed' => $attributeConfig->signed, + 'default' => $attributeConfig->default, + 'array' => $attributeConfig->array, + 'format' => $attributeConfig->format ?? '', + 'formatOptions' => $attributeConfig->formatOptions, + 'filters' => $attributeConfig->filters, + 'options' => $attributeConfig->options ?? [], ]); }, $collections['defaultAttributes']); $dbForProject->createDocuments('attributes', $attributeDocs); - $indexDocs = array_map(function ($indexConfig) use ($database, $collection, $databaseId, $collectionId) { - $key = \is_string($indexConfig['$id']) ? $indexConfig['$id'] : (string) $indexConfig['$id']; - + $indexDocs = array_map(function (Index $indexConfig) use ($database, $collection, $databaseId, $collectionId) { return new Document([ - '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), - 'key' => $key, + '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $indexConfig->key), + 'key' => $indexConfig->key, 'status' => 'available', 'databaseInternalId' => $database->getSequence(), 'databaseId' => $databaseId, 'collectionInternalId' => $collection->getSequence(), 'collectionId' => $collectionId, - 'type' => $indexConfig['type'], - 'attributes' => $indexConfig['attributes'] ?? [], - 'lengths' => $indexConfig['lengths'] ?? [], - 'orders' => $indexConfig['orders'] ?? [], + 'type' => $indexConfig->type->value, + 'attributes' => $indexConfig->attributes, + 'lengths' => $indexConfig->lengths, + 'orders' => $indexConfig->orders, ]); }, $collections['defaultIndexes']); diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php index f47810bea9..6be837115a 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php @@ -138,7 +138,7 @@ class Create extends Action $permissions = []; if (!empty($user->getId()) && !$isPrivilegedUser) { foreach ($allowedPermissions as $permission) { - $permissions[] = (new Permission($permission, 'user', $user->getId()))->toString(); + $permissions[] = (new Permission($permission->value, 'user', $user->getId()))->toString(); } } }