diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 988f061ed5..765688e1ee 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -538,7 +538,7 @@ App::get('/v1/health/queue/databases') ->inject('response') ->action(function (string $name, int|string $threshold, Database $queueForDatabase, Response $response) { $threshold = \intval($threshold); - $size = $queueForDatabase->getSize(); + $size = $queueForDatabase->setQueue($name)->getSize(); if ($size >= $threshold) { throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 6dcb99b56f..959ee77b7d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -246,10 +246,11 @@ App::init() $role = $apiKey->getRole(); $scopes = $apiKey->getScopes(); - // Disable authorization checks for API keys - Authorization::setDefaultStatus(false); if ($apiKey->getRole() === Auth::USER_ROLE_APPS) { + // Disable authorization checks for API keys + Authorization::setDefaultStatus(false); + $user = new Document([ '$id' => '', 'status' => true, diff --git a/composer.lock b/composer.lock index 48a34e76f3..e454de0313 100644 --- a/composer.lock +++ b/composer.lock @@ -3638,16 +3638,16 @@ }, { "name": "utopia-php/database", - "version": "1.4.6", + "version": "1.4.8", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "c7dcfd8a5671944d1a9a454cbf26b95a8bd47544" + "reference": "dbecdf89fde33a5f81ec19f4f97fe0c3715dc83a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/c7dcfd8a5671944d1a9a454cbf26b95a8bd47544", - "reference": "c7dcfd8a5671944d1a9a454cbf26b95a8bd47544", + "url": "https://api.github.com/repos/utopia-php/database/zipball/dbecdf89fde33a5f81ec19f4f97fe0c3715dc83a", + "reference": "dbecdf89fde33a5f81ec19f4f97fe0c3715dc83a", "shasum": "" }, "require": { @@ -3688,9 +3688,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.4.6" + "source": "https://github.com/utopia-php/database/tree/1.4.8" }, - "time": "2025-09-11T06:01:47+00:00" + "time": "2025-09-12T03:35:59+00:00" }, { "name": "utopia-php/detector", diff --git a/package.json b/package.json index 6e32c7d515..1e2b1be430 100644 --- a/package.json +++ b/package.json @@ -4,5 +4,9 @@ "repository": { "type": "git", "url": "git+https://github.com/appwrite/appwrite.git" - } -} \ No newline at end of file + }, + "files": [ + "docs/examples", + "app/config/specs" + ] +} diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index 70051f9055..8e7f6b7625 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -161,17 +161,20 @@ class Database extends Event return $this->document; } - public function getQueue(): string + public function setProject(Document $project): self { - try { - $dsn = new DSN($this->getProject()->getAttribute('database')); - } catch (\InvalidArgumentException) { - // TODO: Temporary until all projects are using shared tables - $dsn = new DSN('mysql://' . $this->getProject()->getAttribute('database')); + $database = $project->getAttribute('database'); + if (!empty($database)) { + try { + $dsn = new DSN($database); + } catch (\InvalidArgumentException) { + // TODO: Temporary until all projects are using shared tables + $dsn = new DSN("mysql://$database"); + } + $this->queue = $dsn->getHost(); } - $this->queue = $dsn->getHost(); - return $this->queue; + return parent::setProject($project); } /** diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index ecf6cfc1ad..8d27aa7230 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -5981,12 +5981,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'name' => 'Upserted Location', - 'location' => [34.0522, -118.2437] // Los Angeles coordinates + 'location' => [34.0522, -80] // Los Angeles coordinates ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + $this->assertEquals([34.0522, -80], $response['body']['location']); // Test 5: Create document without permissions (should fail) $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ @@ -6116,12 +6116,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'distance' => 200, - 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] // LA route + 'route' => [[34.0522, -80], [34.0736, -90]] // LA route ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + $this->assertEquals([[34.0522, -80], [34.0736, -90]], $response['body']['route']); // Test 5: Delete document $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ @@ -6253,12 +6253,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'active' => false, - 'area' => [[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]] // LA area + 'area' => [[[34.0522, -80], [34.0736, -80], [34.0736, -90], [34.0522, -90], [34.0522, -80]]] // LA area ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]], $response['body']['area']); + $this->assertEquals([[[34.0522, -80], [34.0736, -80], [34.0736, -90], [34.0522, -90], [34.0522, -80]]], $response['body']['area']); // Test 5: Create document without required polygon attribute (should fail) $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ @@ -6693,7 +6693,7 @@ trait DatabasesBase '$id' => 'doc1', 'name' => 'Test Document 1', 'pointAttr' => [6.0, 6.0], - 'lineAttr' => [[1.0, 1.0], [2.0, 2.0]], + 'lineAttr' => [[1.0, 1.0], [1.1,1.1] , [2.0, 2.0]], 'polyAttr' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]] ], [ @@ -6775,6 +6775,7 @@ trait DatabasesBase $this->assertCount(1, $response['body']['documents']); $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + // Test 4.2: notContains on polygon (point outside all polygons) $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php index 2c603233a3..c1ce75c38d 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -6682,7 +6682,7 @@ class DatabasesCustomServerTest extends Scope 'path' => [ [0, 0], [50, 50], - [100, 100] + [80, 80] ] // New LINE STRING ], ]); @@ -6696,7 +6696,7 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals([ [0, 0], [50, 50], - [100, 100] + [80, 80] ], $document['path']); } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index e8015ed1e1..eba7ec96a7 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7615,12 +7615,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'name' => 'Upserted Location', - 'location' => [34.0522, -118.2437] + 'location' => [34.0522, -80] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + $this->assertEquals([34.0522, -80], $response['body']['location']); // Create row without permissions (should fail) $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', [ @@ -7749,12 +7749,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'distance' => 200, - 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] + 'route' => [[34.0522, -80], [34.0736, -80]] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + $this->assertEquals([[34.0522, -80], [34.0736, -80]], $response['body']['route']); // Delete row $response = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ @@ -7883,12 +7883,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'active' => false, - 'area' => [[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]] + 'area' => [[[34.0522, -80], [34.0736, -80], [34.0736, -80], [34.0522, -80], [34.0522, -80]]] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]], $response['body']['area']); + $this->assertEquals([[[34.0522, -80], [34.0736, -80], [34.0736, -80], [34.0522, -80], [34.0522, -80]]], $response['body']['area']); // Create row missing required polygon (should fail) $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -8158,7 +8158,7 @@ trait DatabasesBase '$id' => 'row1', 'name' => 'Test Row 1', 'pointAttr' => [6.0, 6.0], - 'lineAttr' => [[1.0, 1.0], [2.0, 2.0]], + 'lineAttr' => [[1.0, 1.0], [1.1,1.1] , [2.0, 2.0]], 'polyAttr' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]] ], [ diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index 0f68d9ea7b..5e35fa065d 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -6379,7 +6379,7 @@ class DatabasesCustomServerTest extends Scope ]); // Coordinates are not validated strictly; creation should succeed - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); // Test 4b: Invalid polygon (insufficient points - should fail) $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ @@ -6650,7 +6650,7 @@ class DatabasesCustomServerTest extends Scope 'path' => [ [0, 0], [50, 50], - [100, 100] + [80, 80] ] // New LINE STRING ], ]); @@ -6664,7 +6664,7 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals([ [0, 0], [50, 50], - [100, 100] + [80, 80] ], $row['path']); }