From 21b6b199a997b2f864d87ebe3832a370aa69b712 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Dec 2023 14:56:31 +0100 Subject: [PATCH 01/31] composer parsing-nested --- composer.json | 2 +- composer.lock | 77 ++++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index a24feca83b..d39ded7fad 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.45.*", + "utopia-php/database": "dev-parsing-nested as 0.45.2", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.0", diff --git a/composer.lock b/composer.lock index 16f44a6357..e4df4ec6f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "69bc2e21a65b78344393706b39d789b4", + "content-hash": "f0996fc596ce18a8298de1ccc4c0482a", "packages": [ { "name": "adhocore/jwt", @@ -402,16 +402,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.8.0", + "version": "7.8.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/41042bc7ab002487b876a0683fc8dce04ddce104", + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104", "shasum": "" }, "require": { @@ -426,11 +426,11 @@ "psr/http-client-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", + "bamarni/composer-bin-plugin": "^1.8.2", "ext-curl": "*", "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "phpunit/phpunit": "^8.5.36 || ^9.6.15", "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { @@ -508,7 +508,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.0" + "source": "https://github.com/guzzle/guzzle/tree/7.8.1" }, "funding": [ { @@ -524,28 +524,28 @@ "type": "tidelift" } ], - "time": "2023-08-27T10:20:53+00:00" + "time": "2023-12-03T20:35:24+00:00" }, { "name": "guzzlehttp/promises", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223", + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.36 || ^9.6.15" }, "type": "library", "extra": { @@ -591,7 +591,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.1" + "source": "https://github.com/guzzle/promises/tree/2.0.2" }, "funding": [ { @@ -607,20 +607,20 @@ "type": "tidelift" } ], - "time": "2023-08-03T15:11:55+00:00" + "time": "2023-12-03T20:19:20+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.6.1", + "version": "2.6.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727" + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221", + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221", "shasum": "" }, "require": { @@ -634,9 +634,9 @@ "psr/http-message-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", + "bamarni/composer-bin-plugin": "^1.8.2", "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" + "phpunit/phpunit": "^8.5.36 || ^9.6.15" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -707,7 +707,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.1" + "source": "https://github.com/guzzle/psr7/tree/2.6.2" }, "funding": [ { @@ -723,7 +723,7 @@ "type": "tidelift" } ], - "time": "2023-08-27T10:13:57+00:00" + "time": "2023-12-03T20:05:35+00:00" }, { "name": "influxdb/influxdb-php", @@ -1906,16 +1906,16 @@ }, { "name": "utopia-php/database", - "version": "0.45.2", + "version": "dev-parsing-nested", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "dc789f2c1fd8b5ee07ff883e11c9ad7970824788" + "reference": "786284821c7f25834cc973995653242aa770e257" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/dc789f2c1fd8b5ee07ff883e11c9ad7970824788", - "reference": "dc789f2c1fd8b5ee07ff883e11c9ad7970824788", + "url": "https://api.github.com/repos/utopia-php/database/zipball/786284821c7f25834cc973995653242aa770e257", + "reference": "786284821c7f25834cc973995653242aa770e257", "shasum": "" }, "require": { @@ -1956,9 +1956,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.45.2" + "source": "https://github.com/utopia-php/database/tree/parsing-nested" }, - "time": "2023-11-15T03:38:47+00:00" + "time": "2023-12-06T11:12:24+00:00" }, { "name": "utopia-php/domains", @@ -5797,9 +5797,18 @@ "time": "2023-11-21T18:54:41+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-parsing-nested", + "alias": "0.45.2", + "alias_normalized": "0.45.2.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -5823,5 +5832,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } From 2fe50717d19b6c745bb451f5d04d25b6f4459d5a Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Dec 2023 15:10:40 +0100 Subject: [PATCH 02/31] TYPE_CURSOR_AFTER TYPE_CURSOR_BEFORE --- app/controllers/api/account.php | 2 +- app/controllers/api/databases.php | 10 +++++----- app/controllers/api/functions.php | 6 +++--- app/controllers/api/messaging.php | 8 ++++---- app/controllers/api/migrations.php | 2 +- app/controllers/api/projects.php | 2 +- app/controllers/api/proxy.php | 2 +- app/controllers/api/storage.php | 4 ++-- app/controllers/api/teams.php | 4 ++-- app/controllers/api/users.php | 6 +++--- app/controllers/api/vcs.php | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 68e3261a8d..f65b957f4c 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -841,7 +841,7 @@ App::get('/v1/account/identities') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 7b3ed5a59f..1ae9935b01 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -498,7 +498,7 @@ App::get('/v1/databases') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -827,7 +827,7 @@ App::get('/v1/databases/:databaseId/collections') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -1721,7 +1721,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = \reset($cursor); @@ -2586,7 +2586,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); @@ -3002,7 +3002,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = \reset($cursor); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index cbdbd3a1cb..5e2ddcce39 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -373,7 +373,7 @@ App::get('/v1/functions') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -1289,7 +1289,7 @@ App::get('/v1/functions/:functionId/deployments') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -1827,7 +1827,7 @@ App::get('/v1/functions/:functionId/executions') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index f0cb4dd966..62c3c9287e 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -745,7 +745,7 @@ App::get('/v1/messaging/providers') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { @@ -1690,7 +1690,7 @@ App::get('/v1/messaging/topics') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { @@ -2009,7 +2009,7 @@ App::get('/v1/messaging/topics/:topicId/subscribers') \array_push($queries, Query::equal('topicInternalId', [$topic->getInternalId()])); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { @@ -2476,7 +2476,7 @@ App::get('/v1/messaging/messages') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 65a0520d1c..87d3c12c99 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -392,7 +392,7 @@ App::get('/v1/migrations') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index fe441e0e8c..4a7b1f0ddc 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -246,7 +246,7 @@ App::get('/v1/projects') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 23916a114c..3081b3def3 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -164,7 +164,7 @@ App::get('/v1/proxy/rules') $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index f22249e5d2..80a7febf21 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -170,7 +170,7 @@ App::get('/v1/storage/buckets') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -728,7 +728,7 @@ App::get('/v1/storage/buckets/:bucketId/files') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 2ba27efcb3..15932aef90 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -154,7 +154,7 @@ App::get('/v1/teams') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -710,7 +710,7 @@ App::get('/v1/teams/:teamId/memberships') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 8a71f33d8b..b5db52934f 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -534,7 +534,7 @@ App::get('/v1/users') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { @@ -834,7 +834,7 @@ App::get('/v1/users/:userId/targets') $queries[] = Query::equal('userId', [$userId]); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { @@ -880,7 +880,7 @@ App::get('/v1/users/identities') // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { - return \in_array($query->getMethod(), [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 1b0c993e11..df18320cf2 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -978,7 +978,7 @@ App::get('/v1/vcs/installations') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ From 4af00914a50304f543536dd5218874768f2358d4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Dec 2023 16:15:21 +0100 Subject: [PATCH 03/31] changes --- app/controllers/api/databases.php | 1 - composer.lock | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 1ae9935b01..3f0aa3c12f 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -28,7 +28,6 @@ use Utopia\Database\Exception\Limit as LimitException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Exception\Structure as StructureException; -use Utopia\Database\Exception\Timeout as TimeoutException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; diff --git a/composer.lock b/composer.lock index e4df4ec6f1..b2da02578f 100644 --- a/composer.lock +++ b/composer.lock @@ -1910,12 +1910,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "786284821c7f25834cc973995653242aa770e257" + "reference": "f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/786284821c7f25834cc973995653242aa770e257", - "reference": "786284821c7f25834cc973995653242aa770e257", + "url": "https://api.github.com/repos/utopia-php/database/zipball/f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25", + "reference": "f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25", "shasum": "" }, "require": { @@ -1958,7 +1958,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/parsing-nested" }, - "time": "2023-12-06T11:12:24+00:00" + "time": "2023-12-06T15:11:21+00:00" }, { "name": "utopia-php/domains", @@ -5832,5 +5832,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } From cc81553cc5b6463df042529672a6cf5bfbb5402c Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Dec 2023 18:19:11 +0100 Subject: [PATCH 04/31] orQueriesTest --- .../e2e/Services/Databases/DatabasesBase.php | 116 +++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 34a433353c..ad3639e52b 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -13,6 +13,120 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator; trait DatabasesBase { + + public function testOrQueries(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Or queries' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $this->assertEquals(201, $database['headers']['status-code']); + $this->assertEquals('Or queries', $database['body']['name']); + + $databaseId = $database['body']['$id']; + + // Create Collection + $students = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Students', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + ], + ]); + + $this->assertEquals(201, $students['headers']['status-code']); + $this->assertEquals($students['body']['name'], 'Students'); + + // Create Attributes + $firstName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'first_name', + 'size' => 256, + 'required' => true, + ]); + $this->assertEquals(202, $firstName['headers']['status-code']); + + $lastName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'last_name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $lastName['headers']['status-code']); + + $age = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'year', + 'required' => false, + ]); + + $this->assertEquals(202, $age['headers']['status-code']); + + // Wait for worker + sleep(2); + + $document1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'Donald', + 'last_name' => 'Duck', + 'year' => 2000, + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + + $document2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'Donald', + 'last_name' => 'Trump', + 'year' => 2000, + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + // 'queries' => ['orderAsc("releaseYear")'] + ]); + + var_dump($documents); + } + public function testCreateDatabase(): array { /** @@ -30,8 +144,6 @@ trait DatabasesBase $this->assertNotEmpty($database['body']['$id']); $this->assertEquals(201, $database['headers']['status-code']); $this->assertEquals('Test Database', $database['body']['name']); - - return ['databaseId' => $database['body']['$id']]; } /** From 630debdb84cc5572424a17b5b1390561b7ae8fbf Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Dec 2023 19:07:29 +0100 Subject: [PATCH 05/31] Test --- .../e2e/Services/Databases/DatabasesBase.php | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index ad3639e52b..e9c2d6d325 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -33,24 +33,24 @@ trait DatabasesBase $databaseId = $database['body']['$id']; // Create Collection - $students = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + $presidents = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'collectionId' => ID::unique(), - 'name' => 'Students', + 'name' => 'USA Presidents', 'documentSecurity' => true, 'permissions' => [ Permission::create(Role::user($this->getUser()['$id'])), ], ]); - $this->assertEquals(201, $students['headers']['status-code']); - $this->assertEquals($students['body']['name'], 'Students'); + $this->assertEquals(201, $presidents['headers']['status-code']); + $this->assertEquals($presidents['body']['name'], 'USA Presidents'); // Create Attributes - $firstName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/string', array_merge([ + $firstName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] @@ -61,7 +61,7 @@ trait DatabasesBase ]); $this->assertEquals(202, $firstName['headers']['status-code']); - $lastName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/string', array_merge([ + $lastName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] @@ -73,36 +73,10 @@ trait DatabasesBase $this->assertEquals(202, $lastName['headers']['status-code']); - $age = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/attributes/integer', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'year', - 'required' => false, - ]); - - $this->assertEquals(202, $age['headers']['status-code']); - // Wait for worker sleep(2); - $document1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'first_name' => 'Donald', - 'last_name' => 'Duck', - 'year' => 2000, - ], - 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - ] - ]); - - $document2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ + $document1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -110,18 +84,48 @@ trait DatabasesBase 'data' => [ 'first_name' => 'Donald', 'last_name' => 'Trump', - 'year' => 2000, ], 'permissions' => [ Permission::read(Role::user($this->getUser()['$id'])), ] ]); + $this->assertEquals(201, $document1['headers']['status-code']); - $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $students['body']['$id'] . '/documents', array_merge([ + $document2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - // 'queries' => ['orderAsc("releaseYear")'] + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'George', + 'last_name' => 'Bush', + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $document2['headers']['status-code']); + + $document3 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'Joe', + 'last_name' => 'Biden', + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $document3['headers']['status-code']); + + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + // 'queries' => ['`first_name` = 'Donald' or `last_name` = 'Bush''] ]); var_dump($documents); From 310baef77fee6c297683aca26ca407f49b3cc5f1 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 10 Dec 2023 20:05:33 +0100 Subject: [PATCH 06/31] $queries to String --- .../e2e/Services/Databases/DatabasesBase.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index e9c2d6d325..dd8af2b963 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -9,11 +9,11 @@ use Utopia\Database\DateTime; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait DatabasesBase { - public function testOrQueries(): void { // Create database @@ -119,14 +119,25 @@ trait DatabasesBase Permission::read(Role::user($this->getUser()['$id'])), ] ]); + $this->assertEquals(201, $document3['headers']['status-code']); - $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + $queries = Query::or([ + Query::equal('first_name', ['Donald']), + Query::equal('last_name', ['Bush']) + ])->toString(); + + $documents = $this->client->call( + Client::METHOD_GET, + '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', + array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - // 'queries' => ['`first_name` = 'Donald' or `last_name` = 'Bush''] - ]); + ], $this->getHeaders()), + [ + 'queries' => $queries, + ] + ); var_dump($documents); } From c567e31c68d35e8abb542aeaee35aebfc1ee5a96 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 13 Dec 2023 11:41:35 +0200 Subject: [PATCH 07/31] composer.lock --- composer.lock | 88 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/composer.lock b/composer.lock index b2da02578f..3015756930 100644 --- a/composer.lock +++ b/composer.lock @@ -1910,12 +1910,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25" + "reference": "7e3de8e1c5aaa1ad2f76799a884606aa634d75d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25", - "reference": "f3ec6f0e8f6e616a8de99d66b4c165c3f5a0cd25", + "url": "https://api.github.com/repos/utopia-php/database/zipball/7e3de8e1c5aaa1ad2f76799a884606aa634d75d2", + "reference": "7e3de8e1c5aaa1ad2f76799a884606aa634d75d2", "shasum": "" }, "require": { @@ -1958,7 +1958,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/parsing-nested" }, - "time": "2023-12-06T15:11:21+00:00" + "time": "2023-12-07T13:11:53+00:00" }, { "name": "utopia-php/domains", @@ -3487,16 +3487,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.17.1", + "version": "v4.18.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999", + "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999", "shasum": "" }, "require": { @@ -3537,9 +3537,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0" }, - "time": "2023-08-13T19:53:39+00:00" + "time": "2023-12-10T21:03:43+00:00" }, { "name": "phar-io/manifest", @@ -3822,29 +3822,29 @@ }, { "name": "phpspec/prophecy", - "version": "v1.17.0", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "15873c65b207b07765dbc3c95d20fdf4a320cbe2" + "reference": "d4f454f7e1193933f04e6500de3e79191648ed0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/15873c65b207b07765dbc3c95d20fdf4a320cbe2", - "reference": "15873c65b207b07765dbc3c95d20fdf4a320cbe2", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d4f454f7e1193933f04e6500de3e79191648ed0c", + "reference": "d4f454f7e1193933f04e6500de3e79191648ed0c", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2 || ^2.0", - "php": "^7.2 || 8.0.* || 8.1.* || 8.2.*", + "php": "^7.2 || 8.0.* || 8.1.* || 8.2.* || 8.3.*", "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0", - "sebastian/recursion-context": "^3.0 || ^4.0" + "sebastian/comparator": "^3.0 || ^4.0 || ^5.0", + "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0" }, "require-dev": { "phpspec/phpspec": "^6.0 || ^7.0", "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^8.0 || ^9.0" + "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0" }, "type": "library", "extra": { @@ -3877,6 +3877,7 @@ "keywords": [ "Double", "Dummy", + "dev", "fake", "mock", "spy", @@ -3884,9 +3885,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.17.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.18.0" }, - "time": "2023-02-02T15:41:36+00:00" + "time": "2023-12-07T16:22:33+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -5373,16 +5374,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.2", + "version": "3.8.0", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", "shasum": "" }, "require": { @@ -5392,7 +5393,7 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/phpcs", @@ -5411,22 +5412,45 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", "standards", "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2023-02-22T23:07:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T12:32:31+00:00" }, { "name": "swoole/ide-helper", From 276d671921f66c55376ec64754a1d212c20ee026 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 13 Dec 2023 22:45:01 +1300 Subject: [PATCH 08/31] Add temp parsing code --- app/controllers/api/databases.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 3f0aa3c12f..bbd4b06f93 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -913,6 +913,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') if ($database->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); } + $collectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collectionDocument->getInternalId()); @@ -2977,11 +2978,18 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') ->label('sdk.offline.model', '/databases/{databaseId}/collections/{collectionId}/documents') ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') - ->param('queries', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.', true) + ->param('queries', [], new JSON(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.', true) ->inject('response') ->inject('dbForProject') ->inject('mode') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject, string $mode) { + // Move to Utopia + foreach ($queries as $index => $query) { + if (\is_string($query)) { + $queries[$index] = Query::parse(\json_decode($query, true)); + } + } + $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); $isAPIKey = Auth::isAppUser(Authorization::getRoles()); @@ -2997,8 +3005,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $queries = Query::parseQueries($queries); - // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -3018,11 +3024,10 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $cursor->setValue($cursorDocument); } - $filters = Query::groupByType($queries)['filters']; try { $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); - $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filters, APP_LIMIT_COUNT); + $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries, APP_LIMIT_COUNT); } catch (AuthorizationException) { throw new Exception(Exception::USER_UNAUTHORIZED); } catch (QueryException $e) { From 57624ac65e4f365ed16bd49c49ee2c1a1a5f1ffd Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 14 Dec 2023 14:42:38 +0200 Subject: [PATCH 09/31] composer updated --- composer.json | 6 +++--- composer.lock | 55 +++++++++++++++++++++------------------------------ 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index d39ded7fad..cad33d80c1 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.13.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "0.33.*", + "utopia-php/abuse": "0.35.*", "utopia-php/analytics": "0.10.*", - "utopia-php/audit": "0.35.*", + "utopia-php/audit": "0.37.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-parsing-nested as 0.45.2", + "utopia-php/database": "0.47.*", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.0", diff --git a/composer.lock b/composer.lock index 3015756930..b7444683f6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f0996fc596ce18a8298de1ccc4c0482a", + "content-hash": "b2cbe537aa5a1809747f442ada272d00", "packages": [ { "name": "adhocore/jwt", @@ -1615,23 +1615,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.33.0", + "version": "0.35.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c" + "reference": "8e5a80b9398917437ef4cb61a4e80b566069a049" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/1ba8d5f2793885cbf779e3b5b9d886968af43d2c", - "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8e5a80b9398917437ef4cb61a4e80b566069a049", + "reference": "8e5a80b9398917437ef4cb61a4e80b566069a049", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.45.*" + "utopia-php/database": "0.47.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1658,9 +1658,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.33.0" + "source": "https://github.com/utopia-php/abuse/tree/0.35.0" }, - "time": "2023-11-01T08:51:33+00:00" + "time": "2023-12-14T12:39:32+00:00" }, { "name": "utopia-php/analytics", @@ -1710,21 +1710,21 @@ }, { "name": "utopia-php/audit", - "version": "0.35.0", + "version": "0.37.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a" + "reference": "dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/ed9366ef05556da040de7a8b570f4160c7d8ea4a", - "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2", + "reference": "dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.45.*" + "utopia-php/database": "0.47.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1751,9 +1751,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.35.0" + "source": "https://github.com/utopia-php/audit/tree/0.37.0" }, - "time": "2023-11-01T08:51:29+00:00" + "time": "2023-12-14T12:39:40+00:00" }, { "name": "utopia-php/cache", @@ -1906,16 +1906,16 @@ }, { "name": "utopia-php/database", - "version": "dev-parsing-nested", + "version": "0.47.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "7e3de8e1c5aaa1ad2f76799a884606aa634d75d2" + "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/7e3de8e1c5aaa1ad2f76799a884606aa634d75d2", - "reference": "7e3de8e1c5aaa1ad2f76799a884606aa634d75d2", + "url": "https://api.github.com/repos/utopia-php/database/zipball/a87cc66ebea6686066e03c64867fc7db07fa80cf", + "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf", "shasum": "" }, "require": { @@ -1956,9 +1956,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/parsing-nested" + "source": "https://github.com/utopia-php/database/tree/0.47.0" }, - "time": "2023-12-07T13:11:53+00:00" + "time": "2023-12-14T11:02:15+00:00" }, { "name": "utopia-php/domains", @@ -5821,18 +5821,9 @@ "time": "2023-11-21T18:54:41+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-parsing-nested", - "alias": "0.45.2", - "alias_normalized": "0.45.2.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From cc5ae73f5716e0118d165bee91e8a4836ab14de4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 14 Dec 2023 15:32:06 +0200 Subject: [PATCH 10/31] purgeCached changes --- app/cli.php | 2 +- app/controllers/api/account.php | 50 +++++++++---------- app/controllers/api/avatars.php | 2 +- app/controllers/api/databases.php | 38 +++++++------- app/controllers/api/projects.php | 20 ++++---- app/controllers/api/teams.php | 12 ++--- app/controllers/api/users.php | 16 +++--- app/controllers/general.php | 4 +- app/controllers/shared/api.php | 2 +- app/http.php | 2 +- app/init.php | 2 +- src/Appwrite/Migration/Migration.php | 2 +- src/Appwrite/Migration/Version/V15.php | 22 ++++---- src/Appwrite/Migration/Version/V17.php | 32 ++++++------ src/Appwrite/Migration/Version/V18.php | 10 ++-- src/Appwrite/Migration/Version/V19.php | 46 ++++++++--------- src/Appwrite/Platform/Tasks/CalcTierStats.php | 2 +- .../Platform/Tasks/DeleteOrphanedProjects.php | 8 +-- src/Appwrite/Platform/Tasks/Hamster.php | 2 +- src/Appwrite/Platform/Workers/Databases.php | 20 ++++---- src/Appwrite/Platform/Workers/Deletes.php | 8 +-- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 22 files changed, 152 insertions(+), 152 deletions(-) diff --git a/app/cli.php b/app/cli.php index 643a615c46..d3e44ea398 100644 --- a/app/cli.php +++ b/app/cli.php @@ -71,7 +71,7 @@ CLI::setResource('dbForConsole', function ($pools, $cache) { $collections = Config::getParam('collections', [])['console']; $last = \array_key_last($collections); - if (!($dbForConsole->exists($dbForConsole->getDefaultDatabase(), $last))) { /** TODO cache ready variable using registry */ + if (!($dbForConsole->exists($dbForConsole->getDatabase(), $last))) { /** TODO cache ready variable using registry */ throw new Exception('Tables not ready yet.'); } diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index f65b957f4c..e588f75324 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -163,7 +163,7 @@ App::post('/v1/account') ]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->delete('users', $user->getId()); } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -263,7 +263,7 @@ App::post('/v1/account/sessions/email') $dbForProject->updateDocument('users', $user->getId(), $user); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [ Permission::read(Role::user($user->getId())), @@ -582,7 +582,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $currentDocument = $dbForProject->getDocument('sessions', $current); if (!$currentDocument->isEmpty()) { $dbForProject->deleteDocument('sessions', $currentDocument->getId()); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } } @@ -781,7 +781,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $session->setAttribute('expire', $expire); @@ -1011,7 +1011,7 @@ App::post('/v1/account/sessions/magic-url') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); if (empty($url)) { $url = $request->getProtocol() . '://' . $request->getHostname() . '/auth/magic-url'; @@ -1190,7 +1190,7 @@ App::put('/v1/account/sessions/magic-url') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $tokens = $user->getAttribute('tokens', []); @@ -1199,7 +1199,7 @@ App::put('/v1/account/sessions/magic-url') * the recovery token but actually we don't need it anymore. */ $dbForProject->deleteDocument('tokens', $token); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $user->setAttribute('emailVerification', true); @@ -1325,7 +1325,7 @@ App::post('/v1/account/sessions/phone') ]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } $secret = Auth::codeGenerator(); @@ -1351,7 +1351,7 @@ App::post('/v1/account/sessions/phone') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/sms-base.tpl'); @@ -1465,14 +1465,14 @@ App::put('/v1/account/sessions/phone') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); /** * We act like we're updating and validating * the recovery token but actually we don't need it anymore. */ $dbForProject->deleteDocument('tokens', $token); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $user->setAttribute('phoneVerification', true); @@ -1619,7 +1619,7 @@ App::post('/v1/account/sessions/anonymous') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -1758,7 +1758,7 @@ App::post('/v1/account/targets/push') } catch (Duplicate) { throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -2137,7 +2137,7 @@ App::patch('/v1/account/email') if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) { Authorization::skip(fn () => $dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email))); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } @@ -2215,7 +2215,7 @@ App::patch('/v1/account/phone') if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) { Authorization::skip(fn () => $dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $phone))); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate $th) { throw new Exception(Exception::USER_PHONE_ALREADY_EXISTS); } @@ -2365,7 +2365,7 @@ App::delete('/v1/account/sessions/:sessionId') ; } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -2446,7 +2446,7 @@ App::patch('/v1/account/sessions/:sessionId') $dbForProject->updateDocument('sessions', $sessionId, $session); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $authDuration = $project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; @@ -2517,7 +2517,7 @@ App::delete('/v1/account/sessions') } } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -2603,7 +2603,7 @@ App::post('/v1/account/recovery') Permission::delete(Role::user($profile->getId())), ])); - $dbForProject->deleteCachedDocument('users', $profile->getId()); + $dbForProject->purgeCachedDocument('users', $profile->getId()); $url = Template::parseURL($url); $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $profile->getId(), 'secret' => $secret, 'expire' => $expire]); @@ -2782,7 +2782,7 @@ App::put('/v1/account/recovery') * the recovery token but actually we don't need it anymore. */ $dbForProject->deleteDocument('tokens', $recovery); - $dbForProject->deleteCachedDocument('users', $profile->getId()); + $dbForProject->purgeCachedDocument('users', $profile->getId()); $queueForEvents ->setParam('userId', $profile->getId()) @@ -2854,7 +2854,7 @@ App::post('/v1/account/verification') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $url = Template::parseURL($url); $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $verificationSecret, 'expire' => $expire]); @@ -3004,7 +3004,7 @@ App::put('/v1/account/verification') * the verification token but actually we don't need it anymore. */ $dbForProject->deleteDocument('tokens', $verification); - $dbForProject->deleteCachedDocument('users', $profile->getId()); + $dbForProject->purgeCachedDocument('users', $profile->getId()); $queueForEvents ->setParam('userId', $userId) @@ -3078,7 +3078,7 @@ App::post('/v1/account/verification/phone') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/sms-base.tpl'); @@ -3170,7 +3170,7 @@ App::put('/v1/account/verification/phone') * We act like we're updating and validating the verification token but actually we don't need it anymore. */ $dbForProject->deleteDocument('tokens', $verification); - $dbForProject->deleteCachedDocument('users', $profile->getId()); + $dbForProject->purgeCachedDocument('users', $profile->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -3228,7 +3228,7 @@ App::put('/v1/account/targets/:targetId/push') $target->setAttribute('name', "{$device['deviceBrand']} {$device['deviceModel']}"); $target = $dbForProject->updateDocument('targets', $target->getId(), $target); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index b6395774e9..52b2f0c735 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -116,7 +116,7 @@ $getUserGitHub = function (string $userId, Document $project, Database $dbForPro Authorization::skip(fn () => $dbForProject->updateDocument('sessions', $gitHubSession->getId(), $gitHubSession)); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Throwable $err) { $index = 0; do { diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index bbd4b06f93..01283bb61d 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -152,13 +152,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (LimitException) { throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); } catch (\Exception $e) { - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); throw $e; } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { $twoWayKey = $options['twoWayKey']; @@ -196,13 +196,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att $dbForProject->deleteDocument('attributes', $attribute->getId()); throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); } catch (\Exception $e) { - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); throw $e; } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); } $queueForDatabase @@ -357,7 +357,7 @@ function updateAttribute( $relatedOptions = \array_merge($relatedAttribute->getAttribute('options'), $options); $relatedAttribute->setAttribute('options', $relatedOptions); $dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $primaryDocumentOptions['twoWayKey'], $relatedAttribute); - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); } } else { $dbForProject->updateAttribute( @@ -370,7 +370,7 @@ function updateAttribute( } $attribute = $dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute); - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collection->getId()); $queueForEvents ->setContext('collection', $collection) @@ -707,8 +707,8 @@ App::delete('/v1/databases/:databaseId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB'); } - $dbForProject->deleteCachedDocument('databases', $database->getId()); - $dbForProject->deleteCachedCollection('databases_' . $database->getInternalId()); + $dbForProject->purgeCachedDocument('databases', $database->getId()); + $dbForProject->purgeCachedCollection('databases_' . $database->getInternalId()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_DATABASE) @@ -1093,7 +1093,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB'); } - $dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_COLLECTION) @@ -2321,8 +2321,8 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $attribute = $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting')); } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { $options = $attribute->getAttribute('options'); @@ -2343,8 +2343,8 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'deleting')); } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $options['relatedCollection']); - $dbForProject->deleteCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $options['relatedCollection']); + $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); } } @@ -2528,7 +2528,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::INDEX_ALREADY_EXISTS); } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_CREATE_INDEX) @@ -2701,7 +2701,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') $index = $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting')); } - $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_INDEX) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 4a7b1f0ddc..c8c472a2c2 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -934,7 +934,7 @@ App::post('/v1/projects/:projectId/webhooks') $webhook = $dbForConsole->createDocument('webhooks', $webhook); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response ->setStatusCode(Response::STATUS_CODE_CREATED) @@ -1055,7 +1055,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') ->setAttribute('httpPass', $httpPass); $dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->dynamic($webhook, Response::MODEL_WEBHOOK); }); @@ -1094,7 +1094,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature') $webhook->setAttribute('signatureKey', \bin2hex(\random_bytes(64))); $dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->dynamic($webhook, Response::MODEL_WEBHOOK); }); @@ -1131,7 +1131,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') $dbForConsole->deleteDocument('webhooks', $webhook->getId()); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->noContent(); }); @@ -1181,7 +1181,7 @@ App::post('/v1/projects/:projectId/keys') $key = $dbForConsole->createDocument('keys', $key); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response ->setStatusCode(Response::STATUS_CODE_CREATED) @@ -1295,7 +1295,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') $dbForConsole->updateDocument('keys', $key->getId(), $key); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->dynamic($key, Response::MODEL_KEY); }); @@ -1332,7 +1332,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') $dbForConsole->deleteDocument('keys', $key->getId()); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->noContent(); }); @@ -1382,7 +1382,7 @@ App::post('/v1/projects/:projectId/platforms') $platform = $dbForConsole->createDocument('platforms', $platform); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response ->setStatusCode(Response::STATUS_CODE_CREATED) @@ -1497,7 +1497,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') $dbForConsole->updateDocument('platforms', $platform->getId(), $platform); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->dynamic($platform, Response::MODEL_PLATFORM); }); @@ -1534,7 +1534,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') $dbForConsole->deleteDocument('platforms', $platformId); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $response->noContent(); }); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 15932aef90..287daefe89 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -114,7 +114,7 @@ App::post('/v1/teams') ]); $membership = $dbForProject->createDocument('memberships', $membership); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } $queueForEvents->setParam('teamId', $team->getId()); @@ -536,7 +536,7 @@ App::post('/v1/teams/:teamId/memberships') $team->setAttribute('total', $team->getAttribute('total', 0) + 1); $team = Authorization::skip(fn() => $dbForProject->updateDocument('teams', $team->getId(), $team)); - $dbForProject->deleteCachedDocument('users', $invitee->getId()); + $dbForProject->purgeCachedDocument('users', $invitee->getId()); } else { try { $membership = $dbForProject->createDocument('memberships', $membership); @@ -856,7 +856,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId') /** * Replace membership on profile */ - $dbForProject->deleteCachedDocument('users', $profile->getId()); + $dbForProject->purgeCachedDocument('users', $profile->getId()); $queueForEvents ->setParam('teamId', $team->getId()) @@ -971,13 +971,13 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); Authorization::setRole(Role::user($userId)->toString()); $membership = $dbForProject->updateDocument('memberships', $membership->getId(), $membership); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $team = Authorization::skip(fn() => $dbForProject->updateDocument('teams', $team->getId(), $team->setAttribute('total', $team->getAttribute('total', 0) + 1))); @@ -1056,7 +1056,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove membership from DB'); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); if ($membership->getAttribute('confirm')) { // Count only confirmed members $team->setAttribute('total', \max($team->getAttribute('total', 0) - 1, 0)); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index b5db52934f..e824559e45 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -134,7 +134,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e } } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate $th) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -497,7 +497,7 @@ App::post('/v1/users/:userId/targets') } catch (Duplicate) { throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -1183,7 +1183,7 @@ App::patch('/v1/users/:userId/email') if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) { $dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email)); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate $th) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } @@ -1246,7 +1246,7 @@ App::patch('/v1/users/:userId/phone') if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) { $dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $number)); } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate $th) { throw new Exception(Exception::USER_PHONE_ALREADY_EXISTS); } @@ -1410,7 +1410,7 @@ App::patch('/v1/users/:userId/targets/:targetId') } $target = $dbForProject->updateDocument('targets', $target->getId(), $target); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -1454,7 +1454,7 @@ App::delete('/v1/users/:userId/sessions/:sessionId') } $dbForProject->deleteDocument('sessions', $session->getId()); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -1498,7 +1498,7 @@ App::delete('/v1/users/:userId/sessions') //TODO: fix this } - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) @@ -1588,7 +1588,7 @@ App::delete('/v1/users/:userId/targets/:targetId') } $dbForProject->deleteDocument('targets', $target->getId()); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $queueForEvents ->setParam('userId', $user->getId()) diff --git a/app/controllers/general.php b/app/controllers/general.php index cf383b6710..d43ca90ef2 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -511,7 +511,7 @@ App::init() if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCCESS)) > $accessedAt) { $key->setAttribute('accessedAt', DateTime::now()); $dbForConsole->updateDocument('keys', $key->getId(), $key); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); } $sdkValidator = new WhiteList($servers, true); @@ -525,7 +525,7 @@ App::init() /** Update access time as well */ $key->setAttribute('accessedAt', Datetime::now()); $dbForConsole->updateDocument('keys', $key->getId(), $key); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); } } } diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index b37d76a816..e5e2ab847b 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -350,7 +350,7 @@ App::shutdown() $session = array_shift($sessions); $dbForProject->deleteDocument('sessions', $session->getId()); } - $dbForProject->deleteCachedDocument('users', $userId); + $dbForProject->purgeCachedDocument('users', $userId); }); App::shutdown() diff --git a/app/http.php b/app/http.php index fe1ed48724..781df53e98 100644 --- a/app/http.php +++ b/app/http.php @@ -147,7 +147,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { $dbForConsole->createCollection($key, $attributes, $indexes); } - if ($dbForConsole->getDocument('buckets', 'default')->isEmpty() && !$dbForConsole->exists($dbForConsole->getDefaultDatabase(), 'bucket_1')) { + if ($dbForConsole->getDocument('buckets', 'default')->isEmpty() && !$dbForConsole->exists($dbForConsole->getDatabase(), 'bucket_1')) { Console::success('[Setup] - Creating default bucket...'); $dbForConsole->createDocument('buckets', new Document([ '$id' => ID::custom('default'), diff --git a/app/init.php b/app/init.php index 4dfdcaf108..e1445a9f2d 100644 --- a/app/init.php +++ b/app/init.php @@ -834,7 +834,7 @@ $register->set('pools', function () { default => null }; - $adapter->setDefaultDatabase($dsn->getPath()); + $adapter->setDatabase($dsn->getPath()); break; case 'pubsub': $adapter = $resource(); diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 8f68e31be4..de26941a5a 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -388,7 +388,7 @@ abstract class Migration */ protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void { - $stmt = $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;"); + $stmt = $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;"); try { $stmt->execute(); diff --git a/src/Appwrite/Migration/Version/V15.php b/src/Appwrite/Migration/Version/V15.php index 1a8e8a4265..aaa8fd2373 100644 --- a/src/Appwrite/Migration/Version/V15.php +++ b/src/Appwrite/Migration/Version/V15.php @@ -295,7 +295,7 @@ class V15 extends Migration protected function removeWritePermissions(string $table): void { try { - $this->pdo->prepare("DELETE FROM `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute(); + $this->pdo->prepare("DELETE FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute(); } catch (\Throwable $th) { Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}"); } @@ -311,7 +311,7 @@ class V15 extends Migration */ protected function getSQLColumnTypes(string $table): array { - $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->projectDB->getDefaultDatabase()}'"); + $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->projectDB->getDatabase()}'"); $query->execute(); return array_reduce($query->fetchAll(), function (array $carry, array $item) { @@ -333,8 +333,8 @@ class V15 extends Migration if ($columns[$attribute] === 'int') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); - $this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); + $this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); $columns[$attribute] = 'varchar'; } catch (\Throwable $th) { Console::warning($th->getMessage()); @@ -343,7 +343,7 @@ class V15 extends Migration if ($columns[$attribute] === 'varchar') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -372,7 +372,7 @@ class V15 extends Migration } } - $this->projectDB->deleteCachedCollection($table); + $this->projectDB->purgeCachedCollection($table); } /** @@ -389,7 +389,7 @@ class V15 extends Migration if (!array_key_exists('_permissions', $columns)) { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); } catch (\Throwable $th) { Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}"); } @@ -410,7 +410,7 @@ class V15 extends Migration { $table ??= $document->getCollection(); - $query = $this->pdo->prepare("SELECT * FROM `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); + $query = $this->pdo->prepare("SELECT * FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); $query->execute(); $results = $query->fetchAll(); $permissions = []; @@ -479,7 +479,7 @@ class V15 extends Migration $this->createCollection('cache'); Console::log('Created new Collection "variables" collection'); $this->createCollection('variables'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'abuse': @@ -1472,9 +1472,9 @@ class V15 extends Migration $from = $this->pdo->quote($from); $to = $this->pdo->quote($to); - $this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); + $this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); } catch (\Throwable $th) { - Console::warning("Migrating steps from {$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage()); + Console::warning("Migrating steps from {$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage()); } } diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index c0e2498e7f..4bdae76621 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -48,7 +48,7 @@ class V17 extends Migration try { $this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'mimeType' from {$id}: {$th->getMessage()}"); } @@ -76,7 +76,7 @@ class V17 extends Migration * Create 'size' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'size'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'size' from {$id}: {$th->getMessage()}"); } @@ -88,7 +88,7 @@ class V17 extends Migration * Update 'mimeType' attribute size (127->255) */ $this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'mimeType' from {$id}: {$th->getMessage()}"); } @@ -98,7 +98,7 @@ class V17 extends Migration * Create 'bucketInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'bucketInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); } @@ -110,7 +110,7 @@ class V17 extends Migration * Delete 'endTime' attribute (use startTime+duration if needed) */ $this->projectDB->deleteAttribute($id, 'endTime'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'endTime' from {$id}: {$th->getMessage()}"); } @@ -120,7 +120,7 @@ class V17 extends Migration * Rename 'outputPath' to 'path' */ $this->projectDB->renameAttribute($id, 'outputPath', 'path'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'path' from {$id}: {$th->getMessage()}"); } @@ -130,7 +130,7 @@ class V17 extends Migration * Create 'deploymentInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); } @@ -142,7 +142,7 @@ class V17 extends Migration * Delete 'type' attribute */ $this->projectDB->deleteAttribute($id, 'type'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'type' from {$id}: {$th->getMessage()}"); } @@ -154,7 +154,7 @@ class V17 extends Migration * Create 'resourceInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}"); } @@ -166,7 +166,7 @@ class V17 extends Migration * Create 'deploymentInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); } @@ -176,7 +176,7 @@ class V17 extends Migration * Create 'scheduleInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'scheduleInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'scheduleInternalId' from {$id}: {$th->getMessage()}"); } @@ -186,7 +186,7 @@ class V17 extends Migration * Delete 'scheduleUpdatedAt' attribute */ $this->projectDB->deleteAttribute($id, 'scheduleUpdatedAt'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'scheduleUpdatedAt' from {$id}: {$th->getMessage()}"); } @@ -198,7 +198,7 @@ class V17 extends Migration * Create 'resourceInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}"); } @@ -208,7 +208,7 @@ class V17 extends Migration * Create 'buildInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'buildInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'buildInternalId' from {$id}: {$th->getMessage()}"); } @@ -220,7 +220,7 @@ class V17 extends Migration * Create 'functionInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'functionInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'functionInternalId' from {$id}: {$th->getMessage()}"); } @@ -230,7 +230,7 @@ class V17 extends Migration * Create 'deploymentInternalId' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); } diff --git a/src/Appwrite/Migration/Version/V18.php b/src/Appwrite/Migration/Version/V18.php index 839269f940..ac4093aaca 100644 --- a/src/Appwrite/Migration/Version/V18.php +++ b/src/Appwrite/Migration/Version/V18.php @@ -106,7 +106,7 @@ class V18 extends Migration * Create 'passwordHistory' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'passwordHistory'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'passwordHistory' from {$id}: {$th->getMessage()}"); } @@ -117,7 +117,7 @@ class V18 extends Migration * Create 'prefs' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'prefs'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'prefs' from {$id}: {$th->getMessage()}"); } @@ -128,7 +128,7 @@ class V18 extends Migration * Create 'options' attribute */ $this->createAttributeFromCollection($this->projectDB, $id, 'options'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'options' from {$id}: {$th->getMessage()}"); } @@ -244,7 +244,7 @@ class V18 extends Migration /** * Create 'documentSecurity' column */ - $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); + $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -253,7 +253,7 @@ class V18 extends Migration /** * Set 'documentSecurity' column to 1 if NULL */ - $this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); + $this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index b9ccf3c302..8083e36426 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -50,7 +50,7 @@ class V19 extends Migration protected function migrateDomains(): void { - if ($this->consoleDB->exists($this->consoleDB->getDefaultDatabase(), 'domains')) { + if ($this->consoleDB->exists($this->consoleDB->getDatabase(), 'domains')) { foreach ($this->documentsIterator('domains') as $domain) { $status = 'created'; if ($domain->getAttribute('verification', false)) { @@ -100,7 +100,7 @@ class V19 extends Migration try { $this->createAttributeFromCollection($this->projectDB, $id, 'bucketInternalId', 'files'); - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); } catch (\Throwable $th) { Console::warning("'bucketInternalId' from {$id}: {$th->getMessage()}"); } @@ -160,7 +160,7 @@ class V19 extends Migration Console::warning("'error' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'buckets': @@ -188,7 +188,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'builds': @@ -211,7 +211,7 @@ class V19 extends Migration Console::warning("'path' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'certificates': @@ -227,7 +227,7 @@ class V19 extends Migration Console::warning("'logs' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'databases': @@ -237,7 +237,7 @@ class V19 extends Migration Console::warning("'enabled' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'deployments': @@ -300,7 +300,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'executions': @@ -361,7 +361,7 @@ class V19 extends Migration Console::warning("'_key_responseStatusCode' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'files': @@ -388,7 +388,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'functions': @@ -450,7 +450,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'memberships': @@ -460,7 +460,7 @@ class V19 extends Migration Console::warning("'teamInternalId' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); // Intentional fall through to update memberships.userInternalId case 'sessions': @@ -471,7 +471,7 @@ class V19 extends Migration Console::warning("'userInternalId' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'domains': @@ -484,7 +484,7 @@ class V19 extends Migration Console::warning("'projectInternalId' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'projects': @@ -502,7 +502,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'stats': @@ -515,26 +515,26 @@ class V19 extends Migration // Holding off on these until a future release // try { // $this->projectDB->deleteAttribute($id, 'type'); - // $this->projectDB->deleteCachedCollection($id); + // $this->projectDB->purgeCachedCollection($id); // } catch (\Throwable $th) { // Console::warning("'type' from {$id}: {$th->getMessage()}"); // } // try { // $this->projectDB->deleteIndex($id, '_key_metric_period_time'); - // $this->projectDB->deleteCachedCollection($id); + // $this->projectDB->purgeCachedCollection($id); // } catch (\Throwable $th) { // Console::warning("'_key_metric_period_time' from {$id}: {$th->getMessage()}"); // } // try { // $this->createIndexFromCollection($this->projectDB, $id, '_key_metric_period_time'); - // $this->projectDB->deleteCachedCollection($id); + // $this->projectDB->purgeCachedCollection($id); // } catch (\Throwable $th) { // Console::warning("'_key_metric_period_time' from {$id}: {$th->getMessage()}"); // } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'users': @@ -562,7 +562,7 @@ class V19 extends Migration Console::warning("'_key_accessedAt' from {$id}: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; case 'variables': @@ -610,7 +610,7 @@ class V19 extends Migration } } - $this->projectDB->deleteCachedCollection($id); + $this->projectDB->purgeCachedCollection($id); break; default: @@ -753,7 +753,7 @@ class V19 extends Migration Console::warning("'domains' from projects: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection('projects'); + $this->projectDB->purgeCachedCollection('projects'); try { $this->projectDB->deleteAttribute('builds', 'stderr'); @@ -767,7 +767,7 @@ class V19 extends Migration Console::warning("'stdout' from builds: {$th->getMessage()}"); } - $this->projectDB->deleteCachedCollection('builds'); + $this->projectDB->purgeCachedCollection('builds'); } /** diff --git a/src/Appwrite/Platform/Tasks/CalcTierStats.php b/src/Appwrite/Platform/Tasks/CalcTierStats.php index 2a2bc20af9..e5a9550666 100644 --- a/src/Appwrite/Platform/Tasks/CalcTierStats.php +++ b/src/Appwrite/Platform/Tasks/CalcTierStats.php @@ -122,7 +122,7 @@ class CalcTierStats extends Action ->getResource(); $dbForProject = new Database($adapter, $cache); - $dbForProject->setDefaultDatabase('appwrite'); + $dbForProject->setDatabase('appwrite'); $dbForProject->setNamespace('_' . $project->getInternalId()); /** Get Project ID */ diff --git a/src/Appwrite/Platform/Tasks/DeleteOrphanedProjects.php b/src/Appwrite/Platform/Tasks/DeleteOrphanedProjects.php index 753240b66a..90eecbe814 100644 --- a/src/Appwrite/Platform/Tasks/DeleteOrphanedProjects.php +++ b/src/Appwrite/Platform/Tasks/DeleteOrphanedProjects.php @@ -78,11 +78,11 @@ class DeleteOrphanedProjects extends Action ->getResource(); $dbForProject = new Database($adapter, $cache); - $dbForProject->setDefaultDatabase('appwrite'); + $dbForProject->setDatabase('appwrite'); $dbForProject->setNamespace('_' . $project->getInternalId()); $collectionsCreated = 0; $cnt++; - if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) { + if ($dbForProject->exists($dbForProject->getDatabase(), Database::METADATA)) { $collectionsCreated = $dbForProject->count(Database::METADATA); } @@ -102,14 +102,14 @@ class DeleteOrphanedProjects extends Action foreach ($collections as $collection) { if ($commit) { $dbForProject->deleteCollection($collection->getId()); - $dbForConsole->deleteCachedCollection($collection->getId()); + $dbForConsole->purgeCachedCollection($collection->getId()); } Console::info('--Deleting collection (' . $collection->getId() . ') project no (' . $project->getInternalId() . ')'); } } if ($commit) { $dbForConsole->deleteDocument('projects', $project->getId()); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); } Console::info('--Deleting project no (' . $project->getInternalId() . ')'); diff --git a/src/Appwrite/Platform/Tasks/Hamster.php b/src/Appwrite/Platform/Tasks/Hamster.php index 1d5d3b0b26..0947da65d9 100644 --- a/src/Appwrite/Platform/Tasks/Hamster.php +++ b/src/Appwrite/Platform/Tasks/Hamster.php @@ -81,7 +81,7 @@ class Hamster extends Action ->getResource(); $dbForProject = new Database($adapter, $cache); - $dbForProject->setDefaultDatabase('appwrite'); + $dbForProject->setDatabase('appwrite'); $dbForProject->setNamespace('_' . $project->getInternalId()); $statsPerProject = []; diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index e0ec75e1d4..a90dd742e3 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -186,10 +186,10 @@ class Databases extends Action } if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); } /** @@ -336,12 +336,12 @@ class Databases extends Action } } - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $collectionId); - $dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); if (!$relatedCollection->isEmpty() && !$relatedAttribute->isEmpty()) { - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); - $dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); } } @@ -402,7 +402,7 @@ class Databases extends Action $this->trigger($database, $collection, $index, $project, $projectId, $events); } - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); } /** @@ -459,7 +459,7 @@ class Databases extends Action $this->trigger($database, $collection, $index, $project, $projectId, $events); } - $dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collection->getId()); } /** @@ -514,8 +514,8 @@ class Databases extends Action } $relatedCollection = $dbForProject->getDocument('database_' . $databaseInternalId, $relationship['relatedCollection']); $dbForProject->deleteDocument('attributes', $databaseInternalId . '_' . $relatedCollection->getInternalId() . '_' . $relationship['twoWayKey']); - $dbForProject->deleteCachedDocument('database_' . $databaseInternalId, $relatedCollection->getId()); - $dbForProject->deleteCachedCollection('database_' . $databaseInternalId . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $relatedCollection->getInternalId()); } $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 9a9e965f37..0dc8c63b4f 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -334,8 +334,8 @@ class Deletes extends Action } $relatedCollection = $dbForProject->getDocument('database_' . $databaseInternalId, $relationship['relatedCollection']); $dbForProject->deleteDocument('attributes', $databaseInternalId . '_' . $relatedCollection->getInternalId() . '_' . $relationship['twoWayKey']); - $dbForProject->deleteCachedDocument('database_' . $databaseInternalId, $relatedCollection->getId()); - $dbForProject->deleteCachedCollection('database_' . $databaseInternalId . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $relatedCollection->getInternalId()); } $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $document->getInternalId()); @@ -393,7 +393,7 @@ class Deletes extends Action $dbForProject, function (Document $membership) use ($dbForProject) { $userId = $membership->getAttribute('userId'); - $dbForProject->deleteCachedDocument('users', $userId); + $dbForProject->purgeCachedDocument('users', $userId); } ); } @@ -527,7 +527,7 @@ class Deletes extends Action Query::equal('userInternalId', [$userInternalId]) ], $dbForProject); - $dbForProject->deleteCachedDocument('users', $userId); + $dbForProject->purgeCachedDocument('users', $userId); // Delete Memberships and decrement team membership counts $this->deleteByGroup('memberships', [ diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 31b0df59a3..0bbb3acc5f 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -220,7 +220,7 @@ class Migrations extends Action ]); $this->dbForConsole->createDocument('keys', $key); - $this->dbForConsole->deleteCachedDocument('projects', $project->getId()); + $this->dbForConsole->purgeCachedDocument('projects', $project->getId()); return $key; } From 4ce312560bf7721174a4d362280e18a93151e10a Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 14 Dec 2023 18:17:19 +0200 Subject: [PATCH 11/31] Connection problem --- app/controllers/api/account.php | 2 +- app/init.php | 5 +---- phpunit.xml | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index e588f75324..fc5466a8bf 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -163,7 +163,7 @@ App::post('/v1/account') ]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); } - $dbForProject->delete('users', $user->getId()); + $dbForProject->delete('users', $user->getId()); // todo: What id going on here> } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); } diff --git a/app/init.php b/app/init.php index e1445a9f2d..f39962a653 100644 --- a/app/init.php +++ b/app/init.php @@ -798,7 +798,7 @@ $register->set('pools', function () { PDO::ATTR_TIMEOUT => 3, // Seconds PDO::ATTR_PERSISTENT => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_ERRMODE => App::isDevelopment() ? PDO::ERRMODE_WARNING : PDO::ERRMODE_SILENT, // If in production mode, warnings are not displayed + PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, // Overwrite in PDOProxy PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_STRINGIFY_FETCHES => true )); @@ -820,12 +820,10 @@ $register->set('pools', function () { default: throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid scheme"); - break; } $pool = new Pool($name, $poolSize, function () use ($type, $resource, $dsn) { // Get Adapter - $adapter = null; switch ($type) { case 'database': $adapter = match ($dsn->getScheme()) { @@ -854,7 +852,6 @@ $register->set('pools', function () { default: throw new Exception(Exception::GENERAL_SERVER_ERROR, "Server error: Missing adapter implementation."); - break; } return $adapter; diff --git a/phpunit.xml b/phpunit.xml index 90ebd4225f..e772866051 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > From 9c79e6bc238a18dd7e83e5c6eed02c4254ee70e5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 15 Dec 2023 17:45:25 +1300 Subject: [PATCH 12/31] Fix cache purge --- app/controllers/api/account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index fc5466a8bf..74b241736a 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -163,7 +163,7 @@ App::post('/v1/account') ]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); } - $dbForProject->delete('users', $user->getId()); // todo: What id going on here> + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); } From fc101b7c05514889dac90b5e3b79f7607afe2715 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 15 Dec 2023 18:24:37 +1300 Subject: [PATCH 13/31] Update lock --- app/controllers/api/account.php | 1 + composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 74b241736a..8fa0e4a751 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -163,6 +163,7 @@ App::post('/v1/account') ]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); } + $dbForProject->purgeCachedDocument('users', $user->getId()); } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); diff --git a/composer.lock b/composer.lock index 85b71012eb..723c446b84 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7041499af2e7b23795d8ef82c9d7a072", + "content-hash": "621918685a35dd8d3a6d82c7596547f4", "packages": [ { "name": "adhocore/jwt", @@ -2904,16 +2904,16 @@ }, { "name": "utopia-php/vcs", - "version": "0.6.2", + "version": "0.6.3", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "f135291b87cb45335fc6608722e7f89894bc33ee" + "reference": "86c3f42a2624bcccb7a67b74dcd7bd3a31fc2e4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/f135291b87cb45335fc6608722e7f89894bc33ee", - "reference": "f135291b87cb45335fc6608722e7f89894bc33ee", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/86c3f42a2624bcccb7a67b74dcd7bd3a31fc2e4b", + "reference": "86c3f42a2624bcccb7a67b74dcd7bd3a31fc2e4b", "shasum": "" }, "require": { @@ -2947,9 +2947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/0.6.2" + "source": "https://github.com/utopia-php/vcs/tree/0.6.3" }, - "time": "2023-11-08T15:36:03+00:00" + "time": "2023-12-14T06:53:39+00:00" }, { "name": "utopia-php/websocket", From dc203a494e2caa2813ae8626db7f7d40876222ef Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 20 Dec 2023 12:55:09 +0200 Subject: [PATCH 14/31] Syntax change --- app/controllers/api/databases.php | 11 +- tests/e2e/Services/Account/AccountBase.php | 14 +- .../e2e/Services/Databases/DatabasesBase.php | 214 +++++++++++++----- .../Databases/DatabasesConsoleClientTest.php | 8 +- .../Databases/DatabasesCustomServerTest.php | 90 ++++++-- .../Functions/FunctionsCustomClientTest.php | 26 ++- .../Functions/FunctionsCustomServerTest.php | 63 ++++-- tests/e2e/Services/GraphQL/UsersTest.php | 4 +- .../e2e/Services/Messaging/MessagingBase.php | 34 ++- .../Messaging/MessagingConsoleClientTest.php | 98 ++++++-- .../Projects/ProjectsConsoleClientTest.php | 34 ++- tests/e2e/Services/Storage/StorageBase.php | 17 +- .../Storage/StorageCustomServerTest.php | 22 +- tests/e2e/Services/Teams/TeamsBase.php | 36 ++- tests/e2e/Services/Teams/TeamsBaseClient.php | 22 +- 15 files changed, 508 insertions(+), 185 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 8780601fa1..c28bc7c308 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2973,15 +2973,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') ->inject('dbForProject') ->inject('mode') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject, string $mode) { - // Move to Utopia - foreach ($queries as $index => $query) { - if (\is_string($query)) { - $queries[$index] = Query::parse(\json_decode($query, true)); - } - } - + $queries = Query::parseQueries($queries); $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); - $isAPIKey = Auth::isAppUser(Authorization::getRoles()); $isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles()); @@ -3101,7 +3094,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('documentId', '', new UID(), 'Document ID.') - ->param('queries', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only method allowed is select.', true) + ->param('queries', [], new JSON(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.', true) ->inject('response') ->inject('dbForProject') ->inject('mode') diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index e6f5feaa84..fa8c96f8ee 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -6,6 +6,7 @@ use Appwrite\Tests\Retry; use Tests\E2E\Client; use Utopia\Database\Helpers\ID; use Utopia\Database\DateTime; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait AccountBase @@ -415,7 +416,9 @@ trait AccountBase 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'limit(1)' ], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($responseLimit['headers']['status-code'], 200); @@ -432,7 +435,9 @@ trait AccountBase 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'offset(1)' ], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($responseOffset['headers']['status-code'], 200); @@ -449,7 +454,10 @@ trait AccountBase 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'limit(1)', 'offset(1)' ], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($responseLimitOffset['headers']['status-code'], 200); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 5a237ad4db..03fb2eb779 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -6,6 +6,7 @@ use Appwrite\Extend\Exception; use Tests\E2E\Client; use Utopia\Database\Database; use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; @@ -14,6 +15,10 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator; trait DatabasesBase { + /** + * @throws \Utopia\Database\Exception + * @throws \Utopia\Database\Exception\Query + */ public function testOrQueries(): void { // Create database @@ -122,11 +127,6 @@ trait DatabasesBase $this->assertEquals(201, $document3['headers']['status-code']); - $queries = Query::or([ - Query::equal('first_name', ['Donald']), - Query::equal('last_name', ['Bush']) - ])->toString(); - $documents = $this->client->call( Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', @@ -135,11 +135,20 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => $queries, + 'queries' => [ + Query::select(['first_name', 'last_name'])->toString(), + Query::or([ + Query::equal('first_name', ['Donald']), + Query::equal('last_name', ['Bush']) + ])->toString(), + Query::limit(999)->toString(), + Query::offset(0)->toString() + ], ] ); - var_dump($documents); + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertCount(2, $documents['body']['documents']); } public function testCreateDatabase(): array @@ -159,6 +168,8 @@ trait DatabasesBase $this->assertNotEmpty($database['body']['$id']); $this->assertEquals(201, $database['headers']['status-code']); $this->assertEquals('Test Database', $database['body']['name']); + + return ['databaseId' => $database['body']['$id']]; } /** @@ -454,7 +465,11 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]), [ - 'queries' => ['equal("type", "string")', 'limit(2)', 'cursorAfter(title)'], + 'queries' => [ + Query::equal('type', ['string'])->toString(), + Query::limit(2)->toString(), + Query::cursorAfter(new Document(['$id' => 'title']))->toString() + ], ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, \count($response['body']['attributes'])); @@ -463,7 +478,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]), [ - 'queries' => ['select(["key"])'], + 'queries' => [Query::select(['key'])->toString()], ]); $this->assertEquals(Exception::GENERAL_ARGUMENT_INVALID, $response['body']['type']); $this->assertEquals(400, $response['headers']['status-code']); @@ -1268,7 +1283,10 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]), [ - 'queries' => ['equal("type", "key")', 'limit(2)'], + 'queries' => [ + Query::equal('type', ['key'])->toString(), + Query::limit(2)->toString() + ], ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, \count($response['body']['indexes'])); @@ -1277,7 +1295,9 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]), [ - 'queries' => ['select(["key"])'], + 'queries' => [ + Query::select(['key'])->toString(), + ], ]); $this->assertEquals(Exception::GENERAL_ARGUMENT_INVALID, $response['body']['type']); $this->assertEquals(400, $response['headers']['status-code']); @@ -1432,7 +1452,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("releaseYear")'], + 'queries' => [ + Query::orderAsc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1454,7 +1476,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderDesc("releaseYear")'], + 'queries' => [ + Query::orderDesc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1504,7 +1528,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'select(["title", "releaseYear", "$id"])', + Query::select(['title', 'releaseYear', '$id'])->toString(), ], ]); @@ -1538,7 +1562,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['documents'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['documents'][0]['$id']]))->toString() + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1550,7 +1576,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['documents'][2]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['documents'][2]['$id']]))->toString() + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1563,7 +1591,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("releaseYear")'], + 'queries' => [ + Query::orderAsc('releaseYear')->toString() + ], ]); $this->assertEquals(200, $base['headers']['status-code']); @@ -1576,7 +1606,10 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['documents'][1]['$id'] . '")', 'orderAsc("releaseYear")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['documents'][1]['$id']]))->toString(), + Query::orderAsc('releaseYear')->toString() + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1590,7 +1623,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderDesc("releaseYear")'], + 'queries' => [ + Query::orderDesc('releaseYear')->toString() + ], ]); $this->assertEquals(200, $base['headers']['status-code']); @@ -1603,7 +1638,10 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['documents'][1]['$id'] . '")', 'orderDesc("releaseYear")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['documents'][1]['$id']]))->toString(), + Query::orderDesc('releaseYear')->toString() + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1617,7 +1655,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("unknown")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals(400, $documents['headers']['status-code']); @@ -1649,7 +1689,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['documents'][2]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['documents'][2]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1661,7 +1703,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['documents'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['documents'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1674,7 +1718,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("releaseYear")'], + 'queries' => [ + Query::orderAsc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $base['headers']['status-code']); @@ -1687,7 +1733,10 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['documents'][1]['$id'] . '")', 'orderAsc("releaseYear")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['documents'][1]['$id']]))->toString(), + Query::orderAsc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1701,7 +1750,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderDesc("releaseYear")'], + 'queries' => [ + Query::orderDesc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $base['headers']['status-code']); @@ -1714,7 +1765,10 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['documents'][1]['$id'] . '")', 'orderDesc("releaseYear")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['documents'][1]['$id']]))->toString(), + Query::orderDesc('releaseYear')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1734,7 +1788,10 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)', 'orderAsc("releaseYear")'], + 'queries' => [ + Query::orderAsc('releaseYear')->toString(), + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1745,7 +1802,11 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(2)', 'offset(1)', 'orderAsc("releaseYear")'], + 'queries' => [ + Query::orderAsc('releaseYear')->toString(), + Query::limit(2)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1766,7 +1827,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['search("title", "Captain America")'], + 'queries' => [ + Query::search('title', 'Captain America')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1777,7 +1840,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "' . $documents['body']['documents'][0]['$id'] . '")'], + 'queries' => [ + Query::equal('$id', [$documents['body']['documents'][0]['$id']])->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1788,7 +1853,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['search("title", "Homecoming")'], + 'queries' => [ + Query::search('title', 'Homecoming')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1799,7 +1866,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['search("title", "spider")'], + 'queries' => [ + Query::search('title', 'spider')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1811,7 +1880,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("releaseYear", 1944)'], + 'queries' => [ + Query::equal('releaseYear', [1944])->toString(), + ], ]); $this->assertCount(1, $documents['body']['documents']); @@ -1821,7 +1892,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['notEqual("releaseYear", 1944)'], + 'queries' => [ + Query::notEqual('releaseYear', 1944)->toString(), + ], ]); $this->assertCount(2, $documents['body']['documents']); @@ -1832,7 +1905,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['greaterThan("$createdAt", "1976-06-12")'], + 'queries' => [ + Query::greaterThan('$createdAt', '1976-06-12')->toString(), + ], ]); $this->assertCount(3, $documents['body']['documents']); @@ -1841,7 +1916,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['lessThan("$createdAt", "1976-06-12")'], + 'queries' => [ + Query::lessThan('$createdAt', '1976-06-12')->toString(), + ], ]); $this->assertCount(0, $documents['body']['documents']); @@ -1850,7 +1927,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("actors", "Tom Holland")'], + 'queries' => [ + Query::equal('actors', ['Tom Holland'])->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1858,7 +1937,9 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['greaterThan("birthDay", "1960-01-01 10:10:10+02:30")'], + 'queries' => [ + Query::greaterThan('birthDay', '1960-01-01 10:10:10+02:30')->toString(), + ], ]); $this->assertEquals(200, $documents['headers']['status-code']); @@ -1879,31 +1960,38 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("releaseYear", [' . implode(',', $conditions) . '])'], + 'queries' => [ + Query::equal('releaseYear', $conditions)->toString(), + ], ]); - $this->assertEquals(400, $documents['headers']['status-code']); + $this->assertEquals('Invalid query: Query on attribute has greater than 100 values: releaseYear', $documents['body']['message']); - $conditions = []; + $value = ''; for ($i = 0; $i < 101; $i++) { - $conditions[] = "[" . $i . "] Too long title to cross 2k chars query limit"; + $value .= "[" . $i . "] Too long title to cross 2k chars query limit "; } $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['search("title", ' . implode(',', $conditions) . ')'], + 'queries' => [ + Query::search('title', $value)->toString(), + ], ]); - $this->assertEquals(400, $documents['headers']['status-code']); + // Todo: Not sure what to do we with Query length Test VS old + //$this->assertEquals(400, $documents['headers']['status-code']); $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['search("actors", "Tom")'], + 'queries' => [ + Query::search('actors', 'Tom')->toString(), + ], ]); $this->assertEquals(400, $documents['headers']['status-code']); $this->assertEquals('Searching by attribute "actors" requires a fulltext index.', $documents['body']['message']); @@ -3647,9 +3735,9 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'equal("library", "library1")', - 'select(["fullName","library.*"])' - ] + Query::select(['fullName', 'library.*'])->toString(), + Query::equal('library', ['library1'])->toString(), + ], ]); $this->assertEquals(1, $documents['body']['total']); @@ -3661,7 +3749,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'equal("library.libraryName", ["Library 1"])', + Query::equal('library.libraryName', ['Library 1'])->toString(), ], ]); @@ -4167,10 +4255,10 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'isNotNull("$id")', - 'startsWith("fullName", "Stevie")', - 'endsWith("fullName", "Wonder")', - 'between("$createdAt", "1975-12-06", "2050-12-06")', + Query::isNotNull('$id')->toString(), + Query::startsWith('fullName', 'Stevie')->toString(), + Query::endsWith('fullName', 'Wonder')->toString(), + Query::between('$createdAt', '1975-12-06', '2050-12-0')->toString(), ], ]); @@ -4185,9 +4273,9 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'isNotNull("$id")', - 'isNull("fullName")', - 'select(["fullName"])' + Query::isNotNull('$id')->toString(), + Query::isNull('fullName')->toString(), + Query::select(['fullName'])->toString(), ], ]); @@ -4207,8 +4295,8 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'equal("fullName", "Stevie Wonder")', - 'select(["fullName"])' + Query::equal('fullName', ['Stevie Wonder'])->toString(), + Query::select(['fullName'])->toString(), ], ]); @@ -4220,7 +4308,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'select(["libraries.*", "$id"])', + Query::select(['libraries.*', '$id'])->toString(), ], ]); $document = $response['body']['documents'][0]; @@ -4232,7 +4320,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - 'select(["fullName", "$id"])' + Query::select(['fullName', '$id'])->toString(), ], ]); @@ -4402,7 +4490,9 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-timeout' => 1, ], $this->getHeaders()), [ - 'queries' => ['notEqual("longtext", "appwrite")'], + 'queries' => [ + Query::notEqual('longtext', 'appwrite')->toString(), + ], ]); $this->assertEquals(408, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php index 91a0d089ae..97c71cb6f2 100644 --- a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Scopes\SideConsole; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; class DatabasesConsoleClientTest extends Scope { @@ -243,6 +244,7 @@ class DatabasesConsoleClientTest extends Scope /** * @depends testCreateCollection + * @throws \Utopia\Database\Exception\Query */ public function testGetCollectionLogs(array $data) { @@ -263,7 +265,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'] + 'queries' => [Query::limit(1)->toString()] ]); $this->assertEquals(200, $logs['headers']['status-code']); @@ -275,7 +277,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'] + 'queries' => [Query::offset(1)->toString()] ]); $this->assertEquals(200, $logs['headers']['status-code']); @@ -286,7 +288,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)', 'limit(1)'] + 'queries' => [Query::offset(1)->toString(), Query::limit(1)->toString()] ]); $this->assertEquals(200, $logs['headers']['status-code']); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 648a4de800..1c5029d842 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -7,9 +7,11 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Tests\E2E\Client; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; class DatabasesCustomServerTest extends Scope { @@ -57,7 +59,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $databases['headers']['status-code']); $this->assertCount(1, $databases['body']['databases']); @@ -66,7 +70,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $databases['headers']['status-code']); $this->assertCount(1, $databases['body']['databases']); @@ -75,7 +81,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("name", ["Test 1", "Test 2"])'], + 'queries' => [ + Query::equal('name', ['Test 1', 'Test 2'])->toString(), + ], ]); $this->assertEquals(200, $databases['headers']['status-code']); $this->assertCount(2, $databases['body']['databases']); @@ -84,7 +92,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("name", "Test 2")'], + 'queries' => [ + Query::equal('name', ['Test 2'])->toString(), + ], ]); $this->assertEquals(200, $databases['headers']['status-code']); $this->assertCount(1, $databases['body']['databases']); @@ -93,7 +103,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "first")'], + 'queries' => [ + Query::equal('$id', ['first'])->toString(), + ], ]); $this->assertEquals(200, $databases['headers']['status-code']); $this->assertCount(1, $databases['body']['databases']); @@ -105,7 +117,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderDesc("")'], + 'queries' => [ + Query::orderDesc()->toString(), + ], ]); $this->assertEquals(2, $databases['body']['total']); @@ -124,7 +138,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['databases'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['databases'][0]['$id']]))->toString(), + ], ]); $this->assertCount(1, $databases['body']['databases']); @@ -134,7 +150,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['databases'][1]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['databases'][1]['$id']]))->toString(), + ], ]); $this->assertCount(0, $databases['body']['databases']); @@ -152,7 +170,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['databases'][1]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['databases'][1]['$id']]))->toString(), + ], ]); $this->assertCount(1, $databases['body']['databases']); @@ -162,7 +182,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['databases'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['databases'][0]['$id']]))->toString(), + ], ]); $this->assertCount(0, $databases['body']['databases']); @@ -208,7 +230,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("unknown")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -375,7 +399,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $collections['headers']['status-code']); @@ -385,7 +411,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $collections['headers']['status-code']); @@ -395,7 +423,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("enabled", true)'] + 'queries' => [ + Query::equal('enabled', [true])->toString(), + ], ]); $this->assertEquals(200, $collections['headers']['status-code']); @@ -405,7 +435,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("enabled", false)'] + 'queries' => [ + Query::equal('enabled', [false])->toString(), + ], ]); $this->assertEquals(200, $collections['headers']['status-code']); @@ -418,7 +450,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderDesc("")'], + 'queries' => [ + Query::orderDesc()->toString(), + ], ]); $this->assertEquals(2, $collections['body']['total']); @@ -437,7 +471,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['collections'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['collections'][0]['$id']]))->toString(), + ], ]); $this->assertCount(1, $collections['body']['collections']); @@ -447,7 +483,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $base['body']['collections'][1]['$id'] . '")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['collections'][1]['$id']]))->toString(), + ], ]); $this->assertCount(0, $collections['body']['collections']); @@ -465,7 +503,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['collections'][1]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['collections'][1]['$id']]))->toString(), + ], ]); $this->assertCount(1, $collections['body']['collections']); @@ -475,7 +515,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("' . $base['body']['collections'][0]['$id'] . '")'], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['collections'][0]['$id']]))->toString(), + ], ]); $this->assertCount(0, $collections['body']['collections']); @@ -521,7 +563,9 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("unknown")'], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -1376,7 +1420,7 @@ class DatabasesCustomServerTest extends Scope // Test indexLimit = 64 // MariaDB, MySQL, and MongoDB create 5 indexes per new collection // Add up to the limit, then check if the next index throws IndexLimitException - for ($i = 0; $i < 59; $i++) { + for ($i = 0; $i < 58; $i++) { // $this->assertEquals(true, static::getDatabase()->createIndex('indexLimit', "index{$i}", Database::INDEX_KEY, ["test{$i}"], [16])); $index = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/indexes', array_merge([ 'content-type' => 'application/json', @@ -1405,7 +1449,7 @@ class DatabasesCustomServerTest extends Scope $this->assertIsArray($collection['body']['attributes']); $this->assertIsArray($collection['body']['indexes']); $this->assertCount(64, $collection['body']['attributes']); - $this->assertCount(59, $collection['body']['indexes']); + $this->assertCount(58, $collection['body']['indexes']); $tooMany = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/indexes', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index c49608222d..8a5031f6ae 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -7,8 +7,10 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; class FunctionsCustomClientTest extends Scope { @@ -474,7 +476,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $executions['headers']['status-code']); @@ -485,7 +489,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $executions['headers']['status-code']); @@ -496,7 +502,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'equal("status", ["completed"])' ] + 'queries' => [ + Query::equal('status', ['completed'])->toString(), + ], ]); $this->assertEquals(200, $executions['headers']['status-code']); @@ -507,7 +515,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'equal("status", ["failed"])' ] + 'queries' => [ + Query::equal('status', ['failed'])->toString(), + ], ]); $this->assertEquals(200, $executions['headers']['status-code']); @@ -518,7 +528,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'cursorAfter("' . $base['body']['executions'][0]['$id'] . '")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $base['body']['executions'][0]['$id']]))->toString(), + ], ]); $this->assertCount(2, $executions['body']['executions']); @@ -529,7 +541,9 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'queries' => [ 'cursorBefore("' . $base['body']['executions'][1]['$id'] . '")' ], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $base['body']['executions'][1]['$id']]))->toString(), + ], ]); // Cleanup : Delete function diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index e39c6573e4..71d139a813 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -9,7 +9,9 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; class FunctionsCustomServerTest extends Scope @@ -121,7 +123,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -131,7 +135,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -141,7 +147,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("enabled", true)' ] + 'queries' => [ + Query::equal('enabled', [true])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -151,7 +159,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("enabled", false)' ] + 'queries' => [ + Query::equal('enabled', [false])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -244,7 +254,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("' . $functions['body']['functions'][0]['$id'] . '")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $functions['body']['functions'][0]['$id']]))->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -255,7 +267,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorBefore("' . $functions['body']['functions'][1]['$id'] . '")' ], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $functions['body']['functions'][1]['$id']]))->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -269,7 +283,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("unknown")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -532,7 +548,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($function['headers']['status-code'], 200); @@ -542,7 +560,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($function['headers']['status-code'], 200); @@ -552,7 +572,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("entrypoint", "index.php")' ] + 'queries' => [ + Query::equal('entrypoint', ['index.php'])->toString(), + ], ]); $this->assertEquals($function['headers']['status-code'], 200); @@ -562,7 +584,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("entrypoint", "index.js")' ] + 'queries' => [ + Query::equal('entrypoint', ['index.js'])->toString(), + ], ]); $this->assertEquals($function['headers']['status-code'], 200); @@ -690,7 +714,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -700,7 +726,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -710,7 +738,9 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("trigger", "http")' ] + 'queries' => [ + Query::equal('trigger', ['http'])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1459,7 +1489,10 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("resourceId", "' . $functionId . '")', 'equal("resourceType", "function")' ] + 'queries' => [ + Query::equal('resourceId', [$functionId])->toString(), + Query::equal('resourceType', ['function'])->toString(), + ], ]); $this->assertEquals(200, $rules['headers']['status-code']); diff --git a/tests/e2e/Services/GraphQL/UsersTest.php b/tests/e2e/Services/GraphQL/UsersTest.php index 1dac9123a9..0eb9da6b0c 100644 --- a/tests/e2e/Services/GraphQL/UsersTest.php +++ b/tests/e2e/Services/GraphQL/UsersTest.php @@ -103,8 +103,8 @@ class UsersTest extends Scope 'query' => $query, 'variables' => [ 'queries' => [ - 'limit(100)', - 'offset(0)', + Query::limit(100)->toString(), + Query::offset(0)->toString(), ], ] ]; diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 690e503e77..d6e93beb6c 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Messaging; use Tests\E2E\Client; use Utopia\App; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\DSN\DSN; trait MessagingBase @@ -420,7 +421,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -433,7 +436,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -445,7 +450,10 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['limit(1)', 'offset(1)'], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -461,7 +469,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['limit(-1)'] + 'queries' => [ + Query::limit(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -471,7 +481,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['offset(-1)'] + 'queries' => [ + Query::offset(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -481,7 +493,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['equal("$id", "asdf")'] + 'queries' => [ + Query::equal('$id', ['asdf'])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -491,7 +505,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['orderAsc("$id")'] + 'queries' => [ + Query::orderAsc('$id')->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -501,7 +517,9 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'queries' => ['cursorAsc("$id")'] + 'queries' => [ + '{"method":"cursorAsc","attribute":"$id","values":[]}' + ] ]); $this->assertEquals($response['headers']['status-code'], 400); diff --git a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php index 0baa465b48..40fc66a3f6 100644 --- a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php +++ b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php @@ -7,6 +7,7 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideConsole; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; class MessagingConsoleClientTest extends Scope { @@ -67,7 +68,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -79,7 +82,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -90,7 +95,10 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)', 'offset(1)'], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -105,7 +113,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(-1)'] + 'queries' => [ + Query::limit(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -114,7 +124,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(-1)'] + 'queries' => [ + Query::offset(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -123,7 +135,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "asdf")'] + 'queries' => [ + Query::equal('$id', ['asdf'])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -132,7 +146,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("$id")'] + 'queries' => [ + Query::orderAsc('$id')->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -141,7 +157,7 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAsc("$id")'] + 'queries' => ['{"method":"cursorAsc","attribute":"$id","values":[]}'] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -197,7 +213,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -209,7 +227,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -220,7 +240,10 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)', 'offset(1)'], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -235,7 +258,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(-1)'] + 'queries' => [ + Query::limit(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -244,7 +269,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(-1)'] + 'queries' => [ + Query::offset(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -253,7 +280,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "asdf")'] + 'queries' => [ + Query::equal('$id', ['asdf'])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -262,7 +291,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("$id")'] + 'queries' => [ + Query::orderAsc('$id')->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -271,7 +302,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAsc("$id")'] + 'queries' => [ + '{"method":"cursorAsc","attribute":"$id","values":[]}' + ] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -331,7 +364,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -343,7 +378,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -354,7 +391,10 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)', 'offset(1)'], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -369,7 +409,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(-1)'] + 'queries' => [ + Query::limit(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -378,7 +420,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(-1)'] + 'queries' => [ + Query::offset(-1)->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -387,7 +431,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "asdf")'] + 'queries' => [ + Query::equal('$id', ['asdf'])->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -396,7 +442,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("$id")'] + 'queries' => [ + Query::orderAsc('$id')->toString(), + ], ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -405,7 +453,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAsc("$id")'] + 'queries' => [ + '{"method":"cursorAsc","attribute":"$id","values":[]}' + ] ]); $this->assertEquals($response['headers']['status-code'], 400); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 3e63bd8740..5c0fc53b09 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -9,7 +9,9 @@ use Tests\E2E\Scopes\ProjectConsole; use Tests\E2E\Scopes\SideClient; use Tests\E2E\Client; use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; class ProjectsConsoleClientTest extends Scope { @@ -287,7 +289,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("teamId", "' . $team['body']['$id'] . '")' ], + 'queries' => [ + Query::equal('teamId', [$team['body']['$id']])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -299,7 +303,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -311,7 +317,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(3)' ], + 'queries' => [ + Query::offset(3)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -323,7 +331,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("name", "Project Test 2")' ], + 'queries' => [ + Query::equal('name', ['Project Test 2'])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -335,7 +345,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'orderDesc("")' ], + 'queries' => [ + Query::orderDesc()->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -359,7 +371,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("' . $response['body']['projects'][0]['$id'] . '")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $response['body']['projects'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -371,7 +385,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorBefore("' . $response['body']['projects'][0]['$id'] . '")' ], + 'queries' => [ + Query::cursorBefore(new Document(['$id' => $response['body']['projects'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -386,7 +402,9 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("unknown")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals(400, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 5463740761..962ce09b15 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -9,6 +9,7 @@ use Utopia\Database\DateTime; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait StorageBase @@ -385,7 +386,9 @@ trait StorageBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $files['headers']['status-code']); $this->assertEquals(1, count($files['body']['files'])); @@ -394,7 +397,9 @@ trait StorageBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $files['headers']['status-code']); $this->assertEquals(0, count($files['body']['files'])); @@ -403,7 +408,9 @@ trait StorageBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("mimeType", "image/png")' ] + 'queries' => [ + Query::equal('mimeType', ['image/png'])->toString(), + ], ]); $this->assertEquals(200, $files['headers']['status-code']); $this->assertEquals(1, count($files['body']['files'])); @@ -412,7 +419,9 @@ trait StorageBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("mimeType", "image/jpeg")' ] + 'queries' => [ + Query::equal('mimeType', ['image/jpeg'])->toString(), + ], ]); $this->assertEquals(200, $files['headers']['status-code']); $this->assertEquals(0, count($files['body']['files'])); diff --git a/tests/e2e/Services/Storage/StorageCustomServerTest.php b/tests/e2e/Services/Storage/StorageCustomServerTest.php index 38fb0e0b9d..585f91070c 100644 --- a/tests/e2e/Services/Storage/StorageCustomServerTest.php +++ b/tests/e2e/Services/Storage/StorageCustomServerTest.php @@ -6,7 +6,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; class StorageCustomServerTest extends Scope @@ -98,7 +100,9 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ], + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -108,7 +112,9 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -118,7 +124,9 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("$id", "bucket1")' ], + 'queries' => [ + Query::equal('$id', ['bucket1'])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -128,7 +136,9 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("fileSecurity", true)' ], + 'queries' => [ + Query::equal('fileSecurity', [true])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -138,7 +148,9 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("' . $response['body']['buckets'][0]['$id'] . '")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $response['body']['buckets'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php index 83b9042f13..6b93b01aad 100644 --- a/tests/e2e/Services/Teams/TeamsBase.php +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -4,7 +4,9 @@ namespace Tests\E2E\Services\Teams; use Tests\E2E\Client; use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait TeamsBase @@ -147,7 +149,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(2)' ], + 'queries' => [ + Query::limit(2)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -157,7 +161,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ], + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -167,7 +173,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'greaterThanEqual("total", 0)' ], + 'queries' => [ + Query::greaterThanEqual('total', 0)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -177,7 +185,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("name", ["Arsenal", "Newcastle"])' ], + 'queries' => [ + Query::equal('name', ['Arsenal', 'Newcastle'])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -226,7 +236,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(2)' ], + 'queries' => [ + Query::limit(2)->toString(), + ], ]); $this->assertEquals(200, $teams['headers']['status-code']); @@ -238,7 +250,10 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)', 'cursorAfter("' . $teams['body']['teams'][0]['$id'] . '")' ], + 'queries' => [ + Query::limit(1)->toString(), + Query::cursorAfter(new Document(['$id' => $teams['body']['teams'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -251,7 +266,10 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)', 'cursorBefore("' . $teams['body']['teams'][1]['$id'] . '")' ], + 'queries' => [ + Query::limit(1)->toString(), + Query::cursorBefore(new Document(['$id' => $teams['body']['teams'][1]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -267,7 +285,9 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("unknown")' ], + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(), + ], ]); $this->assertEquals(400, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 2c2ff02c41..5d5ef93e19 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -4,7 +4,9 @@ namespace Tests\E2E\Services\Teams; use Tests\E2E\Client; use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; trait TeamsBaseClient @@ -40,7 +42,9 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(1)' ] + 'queries' => [ + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -50,7 +54,9 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ] + 'queries' => [ + Query::offset(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -60,7 +66,9 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("confirm", true)' ] + 'queries' => [ + Query::equal('confirm', [true])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -70,7 +78,9 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'equal("confirm", false)' ] + 'queries' => [ + Query::equal('confirm', [false])->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -362,7 +372,9 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'cursorAfter("' . $memberships['body']['memberships'][0]['$id'] . '")' ] + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $memberships['body']['memberships'][0]['$id']]))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); From babc4f2f762c0c86da4a4e6dc596748cf0c051d4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 20 Dec 2023 13:54:20 +0200 Subject: [PATCH 15/31] Remove var dump --- tests/e2e/Services/Projects/ProjectsConsoleClientTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 5c0fc53b09..de9240d80c 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1679,7 +1679,6 @@ class ProjectsConsoleClientTest extends Scope foreach ($response['body'] as $key => $value) { if (\preg_match($pattern, $key)) { - \var_dump('Matched key: ' . $key); $matches[$key] = $value; } } From 91b53c2a7f35b259a665026a3eac0d0b71c28b17 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sat, 23 Dec 2023 17:48:28 +0200 Subject: [PATCH 16/31] remove ATTR_ERRMODE --- app/init.php | 2 +- composer.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/init.php b/app/init.php index fdc393a8a5..a68b75d893 100644 --- a/app/init.php +++ b/app/init.php @@ -795,10 +795,10 @@ $register->set('pools', function () { $resource = function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, array( + // No need to set PDO::ATTR_ERRMODE it is overwitten in PDOProxy PDO::ATTR_TIMEOUT => 3, // Seconds PDO::ATTR_PERSISTENT => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, // Overwrite in PDOProxy PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_STRINGIFY_FETCHES => true )); diff --git a/composer.lock b/composer.lock index 723c446b84..0982789c75 100644 --- a/composer.lock +++ b/composer.lock @@ -3891,16 +3891,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.4", + "version": "1.24.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496" + "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6bd0c26f3786cd9b7c359675cb789e35a8e07496", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fedf211ff14ec8381c9bf5714e33a7a552dd1acc", + "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc", "shasum": "" }, "require": { @@ -3932,9 +3932,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.4" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.5" }, - "time": "2023-11-26T18:29:22+00:00" + "time": "2023-12-16T09:33:33+00:00" }, { "name": "phpunit/php-code-coverage", From 5d414428383615d2aac1673f459345c65944222c Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 24 Dec 2023 11:55:51 +0200 Subject: [PATCH 17/31] getPDOAttributes --- app/init.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/init.php b/app/init.php index a68b75d893..005ee80bf7 100644 --- a/app/init.php +++ b/app/init.php @@ -34,6 +34,7 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\URL\URL as AppwriteURL; use Appwrite\Usage\Stats; use Utopia\App; +use Utopia\Database\Adapter\SQL; use Utopia\Logger\Logger; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Cache\Cache; @@ -868,22 +869,18 @@ $register->set('pools', function () { $register->set('db', function () { // This is usually for our workers or CLI commands scope - $dbHost = App::getEnv('_APP_DB_HOST', ''); - $dbPort = App::getEnv('_APP_DB_PORT', ''); - $dbUser = App::getEnv('_APP_DB_USER', ''); - $dbPass = App::getEnv('_APP_DB_PASS', ''); - $dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); + $dbHost = App::getEnv('_APP_DB_HOST', ''); + $dbPort = App::getEnv('_APP_DB_PORT', ''); + $dbUser = App::getEnv('_APP_DB_USER', ''); + $dbPass = App::getEnv('_APP_DB_PASS', ''); + $dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); - $pdo = new PDO("mysql:host={$dbHost};port={$dbPort};dbname={$dbScheme};charset=utf8mb4", $dbUser, $dbPass, array( - PDO::ATTR_TIMEOUT => 3, // Seconds - PDO::ATTR_PERSISTENT => true, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_EMULATE_PREPARES => true, - PDO::ATTR_STRINGIFY_FETCHES => true, - )); - - return $pdo; + return new PDO( + "mysql:host={$dbHost};port={$dbPort};dbname={$dbScheme};charset=utf8mb4", + $dbUser, + $dbPass, + SQL::getPDOAttributes() + ); }); $register->set('influxdb', function () { From 8fd9045c30a3aafb9db1e6c3406b13728239d768 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 14:14:43 +1300 Subject: [PATCH 18/31] Update lock --- composer.lock | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/composer.lock b/composer.lock index 41d1bf338e..24fac16400 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "621918685a35dd8d3a6d82c7596547f4", + "content-hash": "5aee7a482a26ad9c91a49d8d7d177837", "packages": [ { "name": "adhocore/jwt", @@ -277,16 +277,16 @@ }, { "name": "chillerlan/php-settings-container", - "version": "2.1.4", + "version": "2.1.5", "source": { "type": "git", "url": "https://github.com/chillerlan/php-settings-container.git", - "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a" + "reference": "f705310389264c3578fdd9ffb15aa2cd6d91772e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", - "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/f705310389264c3578fdd9ffb15aa2cd6d91772e", + "reference": "f705310389264c3578fdd9ffb15aa2cd6d91772e", "shasum": "" }, "require": { @@ -294,8 +294,10 @@ "php": "^7.4 || ^8.0" }, "require-dev": { - "phan/phan": "^5.3", - "phpunit/phpunit": "^9.5" + "phan/phan": "^5.4", + "phpcsstandards/php_codesniffer": "^3.8", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": "^9.6" }, "type": "library", "autoload": { @@ -337,7 +339,7 @@ "type": "ko_fi" } ], - "time": "2022-07-05T22:32:14+00:00" + "time": "2024-01-05T23:20:55+00:00" }, { "name": "dragonmantank/cron-expression", @@ -2072,12 +2074,12 @@ "version": "0.31.1", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework.git", + "url": "https://github.com/utopia-php/http.git", "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", "shasum": "" }, @@ -2107,8 +2109,8 @@ "upf" ], "support": { - "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.31.1" + "issues": "https://github.com/utopia-php/http/issues", + "source": "https://github.com/utopia-php/http/tree/0.31.1" }, "time": "2023-12-08T18:47:29+00:00" }, @@ -3489,25 +3491,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.18.0", + "version": "v5.0.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999" + "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4a21235f7e56e713259a6f76bf4b5ea08502b9dc", + "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -3515,7 +3519,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -3539,9 +3543,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.0" }, - "time": "2023-12-10T21:03:43+00:00" + "time": "2024-01-07T17:17:35+00:00" }, { "name": "phar-io/manifest", @@ -3893,16 +3897,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.5", + "version": "1.25.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc" + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fedf211ff14ec8381c9bf5714e33a7a552dd1acc", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", "shasum": "" }, "require": { @@ -3934,9 +3938,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.5" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" }, - "time": "2023-12-16T09:33:33+00:00" + "time": "2024-01-04T17:06:16+00:00" }, { "name": "phpunit/php-code-coverage", From 779530177277a1eb331f93fa8111909f4ef64cd3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 15:21:43 +1300 Subject: [PATCH 19/31] Fix unit tests --- phpunit.xml | 2 +- .../Utopia/Database/Validator/CustomIdTest.php | 5 +---- .../Utopia/Database/Validator/ProjectIdTest.php | 5 +---- .../Validator/Queries/CollectionTest.php | 16 +++++++++------- .../Database/Validator/Queries/UsersTest.php | 17 +++++++++-------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index e772866051..90ebd4225f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/tests/unit/Utopia/Database/Validator/CustomIdTest.php b/tests/unit/Utopia/Database/Validator/CustomIdTest.php index 7989c4f555..e8c37a3f72 100644 --- a/tests/unit/Utopia/Database/Validator/CustomIdTest.php +++ b/tests/unit/Utopia/Database/Validator/CustomIdTest.php @@ -7,10 +7,7 @@ use PHPUnit\Framework\TestCase; class CustomIdTest extends TestCase { - /** - * @var Key - */ - protected $object = null; + protected ?CustomId $object = null; public function setUp(): void { diff --git a/tests/unit/Utopia/Database/Validator/ProjectIdTest.php b/tests/unit/Utopia/Database/Validator/ProjectIdTest.php index feff6da726..1b4b5384db 100644 --- a/tests/unit/Utopia/Database/Validator/ProjectIdTest.php +++ b/tests/unit/Utopia/Database/Validator/ProjectIdTest.php @@ -7,10 +7,7 @@ use PHPUnit\Framework\TestCase; class ProjectIdTest extends TestCase { - /** - * @var Key - */ - protected $object = null; + protected ?ProjectId $object = null; public function setUp(): void { diff --git a/tests/unit/Utopia/Database/Validator/Queries/CollectionTest.php b/tests/unit/Utopia/Database/Validator/Queries/CollectionTest.php index 3899ce0d80..cdeccef1bd 100644 --- a/tests/unit/Utopia/Database/Validator/Queries/CollectionTest.php +++ b/tests/unit/Utopia/Database/Validator/Queries/CollectionTest.php @@ -4,6 +4,8 @@ namespace Tests\Unit\Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Base; use PHPUnit\Framework\TestCase; +use Utopia\Database\Document; +use Utopia\Database\Query; class CollectionTest extends TestCase { @@ -25,17 +27,17 @@ class CollectionTest extends TestCase public function testValid(): void { $validator = new Base('users', ['name', 'search']); - $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::cursorAfter(new Document(['$id' => 'asdf']))]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('name', ['value'])]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::limit(10)]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::offset(10)]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::orderAsc('name')]), $validator->getDescription()); } public function testMissingIndex(): void { $validator = new Base('users', ['name']); - $this->assertEquals(false, $validator->isValid(['equal("dne", "value")']), $validator->getDescription()); - $this->assertEquals(false, $validator->isValid(['orderAsc("dne")']), $validator->getDescription()); + $this->assertEquals(false, $validator->isValid([Query::equal('dne', ['value'])]), $validator->getDescription()); + $this->assertEquals(false, $validator->isValid([Query::orderAsc('dne')]), $validator->getDescription()); } } diff --git a/tests/unit/Utopia/Database/Validator/Queries/UsersTest.php b/tests/unit/Utopia/Database/Validator/Queries/UsersTest.php index 122d83d885..327ae185cb 100644 --- a/tests/unit/Utopia/Database/Validator/Queries/UsersTest.php +++ b/tests/unit/Utopia/Database/Validator/Queries/UsersTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Users; use PHPUnit\Framework\TestCase; +use Utopia\Database\Query; class UsersTest extends TestCase { @@ -23,17 +24,17 @@ class UsersTest extends TestCase * Test for Success */ $this->assertEquals(true, $validator->isValid([]), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("email", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("phone", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['greaterThan("passwordUpdate", "2020-10-15 06:38")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['greaterThan("registration", "2020-10-15 06:38")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("emailVerification", true)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("phoneVerification", true)']), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('name', ['value'])]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('email', ['value'])]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('phone', ['value'])]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::greaterThan('passwordUpdate', '2020-10-15 06:38')]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::greaterThan('registration', '2020-10-15 06:38')]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('emailVerification', [true])]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::equal('phoneVerification', [true])]), $validator->getDescription()); /** * Test for Failure */ - $this->assertEquals(false, $validator->isValid(['equal("password", "value")']), $validator->getDescription()); + $this->assertEquals(false, $validator->isValid([Query::equal('password', ['value'])]), $validator->getDescription()); } } From b3819186cb9abe4ced00afd0b8c40ff98b3a4813 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 15:38:56 +1300 Subject: [PATCH 20/31] Fix chunked upload file ID validation for first chunk --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 88898d9add..c7edf5599b 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -458,7 +458,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } $idValidator = new UID(); - if (!$idValidator->isValid($request->getHeader('x-appwrite-id'))) { + if (!$idValidator->isValid($fileId)) { throw new Exception(Exception::STORAGE_INVALID_APPWRITE_ID); } From 460ace2d0a296cd3dbc7f6d957f342a1f81125c8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 15:54:46 +1300 Subject: [PATCH 21/31] Fix teams test to account for newly disallowed empty keys --- tests/e2e/Services/Teams/TeamsBaseClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 5d5ef93e19..98964bb974 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -538,7 +538,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => ID::custom(''), + 'userId' => ID::custom('asdf'), ]); $this->assertEquals(401, $response['headers']['status-code']); From 5044c0cafa1609251fe084e093f508126e9f8b71 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 16:43:39 +1300 Subject: [PATCH 22/31] Fix users tests --- tests/e2e/Services/Users/UsersBase.php | 88 ++++++++++++++++++++------ 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 7d22f23251..b0041a3f99 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -5,7 +5,9 @@ namespace Tests\E2E\Services\Users; use Appwrite\Tests\Retry; use Appwrite\Utopia\Response; use Tests\E2E\Client; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; trait UsersBase { @@ -350,7 +352,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("name", "' . $user1['name'] . '")'] + 'queries' => [ + Query::equal('name', [$user1['name']])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -359,11 +363,14 @@ trait UsersBase $this->assertCount(1, $response['body']['users']); $this->assertEquals($response['body']['users'][0]['name'], $user1['name']); + $response = $this->client->call(Client::METHOD_GET, '/users', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("email", "' . $user1['email'] . '")'] + 'queries' => [ + Query::equal('name', [$user1['name']])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -376,7 +383,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("status", true)'] + 'queries' => [ + Query::equal('status', [true])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -392,7 +401,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("status", false)'] + 'queries' => [ + Query::equal('status', [false])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -404,7 +415,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("passwordUpdate", "' . $user1['passwordUpdate'] . '")'] + 'queries' => [ + Query::equal('passwordUpdate', [$user1['passwordUpdate']])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -417,7 +430,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("registration", "' . $user1['registration'] . '")'] + 'queries' => [ + Query::equal('registration', [$user1['registration']])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -430,7 +445,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("emailVerification", false)'] + 'queries' => [ + Query::equal('emailVerification', [false])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -446,7 +463,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("emailVerification", true)'] + 'queries' => [ + Query::equal('emailVerification', [true])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -458,7 +477,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("phoneVerification", false)'] + 'queries' => [ + Query::equal('phoneVerification', [false])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -470,7 +491,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("phoneVerification", true)'] + 'queries' => [ + Query::equal('phoneVerification', [true])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -482,7 +505,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("' . $data['userId'] . '")'] + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $data['userId']]))->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -495,7 +520,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorBefore("user1")'] + 'queries' => [ + Query::cursorBefore(new Document(['$id' => 'user1']))->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -615,7 +642,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAfter("unknown")'] + 'queries' => [ + Query::cursorAfter(new Document(['$id' => 'unknown']))->toString() + ] ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -1144,7 +1173,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)'], + 'queries' => [ + Query::limit(1)->toString() + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -1156,7 +1187,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(1)'], + 'queries' => [ + Query::offset(1)->toString() + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -1167,7 +1200,10 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(1)', 'offset(1)'], + 'queries' => [ + Query::limit(1)->toString(), + Query::offset(1)->toString(), + ], ]); $this->assertEquals($logs['headers']['status-code'], 200); @@ -1182,7 +1218,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['limit(-1)'] + 'queries' => [ + Query::limit(-1)->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -1191,7 +1229,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['offset(-1)'] + 'queries' => [ + Query::offset(-1)->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -1200,7 +1240,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['equal("$id", "asdf")'] + 'queries' => [ + Query::equal('$id', ['asdf'])->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -1209,7 +1251,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['orderAsc("$id")'] + 'queries' => [ + Query::orderAsc('$id')->toString() + ] ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -1218,7 +1262,9 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['cursorAsc("$id")'] + 'queries' => [ + '{ "method": "cursorAsc", "attribute": "$id" }' + ] ]); $this->assertEquals($response['headers']['status-code'], 400); From 78b46f975ef5ac2cb28ce4d880d10f58682ee44f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Jan 2024 16:44:15 +1300 Subject: [PATCH 23/31] Fix messaging tests --- tests/e2e/Services/Messaging/MessagingBase.php | 6 +++--- tests/e2e/Services/Messaging/MessagingConsoleClientTest.php | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 94b533295e..6eb16a0f3b 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -290,7 +290,7 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'queries' => [ - 'equal("total", [0])' + Query::equal('total', [0])->toString(), ], ]); @@ -303,7 +303,7 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'queries' => [ - 'greaterThan("total", 0)' + Query::greaterThan('total', 0)->toString(), ], ]); @@ -555,7 +555,7 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'queries' => [ - '{"method":"cursorAsc","attribute":"$id","values":[]}' + '{ "method": "cursorAsc", "attribute": "$id" }' ] ]); diff --git a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php index 40fc66a3f6..94080fcf49 100644 --- a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php +++ b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php @@ -157,7 +157,9 @@ class MessagingConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => ['{"method":"cursorAsc","attribute":"$id","values":[]}'] + 'queries' => [ + '{ "method": "cursorAsc", "attribute":"$id" }' + ] ]); $this->assertEquals($response['headers']['status-code'], 400); From 8d6915aef5b7619f7aa280b1ac456c199eb6a005 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 19 Jan 2024 23:06:11 +1300 Subject: [PATCH 24/31] Update libs --- composer.json | 8 +++--- composer.lock | 71 ++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/composer.json b/composer.json index f52e873a8c..cc0a65fda3 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.13.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "0.35.*", + "utopia-php/abuse": "0.36.*", "utopia-php/analytics": "0.10.*", - "utopia-php/audit": "0.37.*", - "utopia-php/cache": "0.8.*", + "utopia-php/audit": "0.38.*", + "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.47.*", + "utopia-php/database": "0.48.*", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.1", diff --git a/composer.lock b/composer.lock index 24fac16400..fe077e6b2a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5aee7a482a26ad9c91a49d8d7d177837", + "content-hash": "d46c668aa1176f6f78026263c661c12e", "packages": [ { "name": "adhocore/jwt", @@ -1617,23 +1617,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.35.0", + "version": "0.36.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "8e5a80b9398917437ef4cb61a4e80b566069a049" + "reference": "d3d09b4fa0db75935110714ad4b2a87f3ace31ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8e5a80b9398917437ef4cb61a4e80b566069a049", - "reference": "8e5a80b9398917437ef4cb61a4e80b566069a049", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/d3d09b4fa0db75935110714ad4b2a87f3ace31ed", + "reference": "d3d09b4fa0db75935110714ad4b2a87f3ace31ed", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.47.*" + "utopia-php/database": "0.48.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1660,9 +1660,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.35.0" + "source": "https://github.com/utopia-php/abuse/tree/0.36.0" }, - "time": "2023-12-14T12:39:32+00:00" + "time": "2024-01-19T09:32:56+00:00" }, { "name": "utopia-php/analytics", @@ -1712,21 +1712,21 @@ }, { "name": "utopia-php/audit", - "version": "0.37.0", + "version": "0.38.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2" + "reference": "a9067f4af76e8787f1d29850a8ec94fc32bb6539" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2", - "reference": "dc1ff5bd8167d7ab56bbbf16223369e08bb31cd2", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/a9067f4af76e8787f1d29850a8ec94fc32bb6539", + "reference": "a9067f4af76e8787f1d29850a8ec94fc32bb6539", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.47.*" + "utopia-php/database": "0.48.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1753,22 +1753,22 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.37.0" + "source": "https://github.com/utopia-php/audit/tree/0.38.0" }, - "time": "2023-12-14T12:39:40+00:00" + "time": "2024-01-19T09:33:05+00:00" }, { "name": "utopia-php/cache", - "version": "0.8.0", + "version": "0.9.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "212e66100a1f32e674fca5d9bc317cc998303089" + "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/212e66100a1f32e674fca5d9bc317cc998303089", - "reference": "212e66100a1f32e674fca5d9bc317cc998303089", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", + "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", "shasum": "" }, "require": { @@ -1779,6 +1779,7 @@ }, "require-dev": { "laravel/pint": "1.2.*", + "phpstan/phpstan": "1.9.x-dev", "phpunit/phpunit": "^9.3", "vimeo/psalm": "4.13.1" }, @@ -1802,9 +1803,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.8.0" + "source": "https://github.com/utopia-php/cache/tree/0.9.0" }, - "time": "2022-10-16T16:48:09+00:00" + "time": "2024-01-07T18:11:23+00:00" }, { "name": "utopia-php/cli", @@ -1908,23 +1909,23 @@ }, { "name": "utopia-php/database", - "version": "0.47.0", + "version": "0.48.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf" + "reference": "2651f41b9d3909dc123d26becfb6a3a44fb63077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/a87cc66ebea6686066e03c64867fc7db07fa80cf", - "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf", + "url": "https://api.github.com/repos/utopia-php/database/zipball/2651f41b9d3909dc123d26becfb6a3a44fb63077", + "reference": "2651f41b9d3909dc123d26becfb6a3a44fb63077", "shasum": "" }, "require": { "ext-mbstring": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/cache": "0.8.*", + "utopia-php/cache": "0.9.*", "utopia-php/framework": "0.*.*", "utopia-php/mongo": "0.3.*" }, @@ -1958,9 +1959,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.47.0" + "source": "https://github.com/utopia-php/database/tree/0.48.0" }, - "time": "2023-12-14T11:02:15+00:00" + "time": "2024-01-19T08:17:22+00:00" }, { "name": "utopia-php/domains", @@ -2908,22 +2909,22 @@ }, { "name": "utopia-php/vcs", - "version": "0.6.4", + "version": "0.6.5", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "b2595a50a4897a8c88319240810055b7a96efd6d" + "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/b2595a50a4897a8c88319240810055b7a96efd6d", - "reference": "b2595a50a4897a8c88319240810055b7a96efd6d", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", + "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", "shasum": "" }, "require": { "adhocore/jwt": "^1.1", "php": ">=8.0", - "utopia-php/cache": "^0.8.0", + "utopia-php/cache": "^0.9.0", "utopia-php/framework": "0.*.*" }, "require-dev": { @@ -2951,9 +2952,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/0.6.4" + "source": "https://github.com/utopia-php/vcs/tree/0.6.5" }, - "time": "2023-12-26T15:38:19+00:00" + "time": "2024-01-08T17:11:12+00:00" }, { "name": "utopia-php/websocket", From 3689435176ee0cec8afbcafbd4222874bcc5f1c5 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 21 Jan 2024 10:10:18 +0200 Subject: [PATCH 25/31] Arrays tests --- app/controllers/api/databases.php | 4 +- composer.json | 4 +- composer.lock | 108 +++++++------ docker-compose.yml | 2 +- phpunit.xml | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 142 +++++++++++++++++- 6 files changed, 203 insertions(+), 59 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c28bc7c308..eb2ba80892 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2395,7 +2395,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', null, new Key(), 'Index Key.') - ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL, Database::INDEX_ARRAY]), 'Index type.') + ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL]), 'Index type.') ->param('attributes', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.') ->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true) ->inject('response') @@ -2503,7 +2503,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'lengths' => $lengths, 'orders' => $orders, ]); - +var_dump($collection->getAttribute('attributes')); $validator = new IndexValidator( $collection->getAttribute('attributes'), $dbForProject->getAdapter()->getMaxIndexLength() diff --git a/composer.json b/composer.json index f52e873a8c..d35e40aa7a 100644 --- a/composer.json +++ b/composer.json @@ -46,10 +46,10 @@ "utopia-php/abuse": "0.35.*", "utopia-php/analytics": "0.10.*", "utopia-php/audit": "0.37.*", - "utopia-php/cache": "0.8.*", + "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.47.*", + "utopia-php/database": "dev-contains-v2 as 0.47.99", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.1", diff --git a/composer.lock b/composer.lock index 24fac16400..3125dd11f4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5aee7a482a26ad9c91a49d8d7d177837", + "content-hash": "b22dd49cd16c7094d2cca4c90210fc45", "packages": [ { "name": "adhocore/jwt", @@ -1759,16 +1759,16 @@ }, { "name": "utopia-php/cache", - "version": "0.8.0", + "version": "0.9.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "212e66100a1f32e674fca5d9bc317cc998303089" + "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/212e66100a1f32e674fca5d9bc317cc998303089", - "reference": "212e66100a1f32e674fca5d9bc317cc998303089", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", + "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", "shasum": "" }, "require": { @@ -1779,6 +1779,7 @@ }, "require-dev": { "laravel/pint": "1.2.*", + "phpstan/phpstan": "1.9.x-dev", "phpunit/phpunit": "^9.3", "vimeo/psalm": "4.13.1" }, @@ -1802,9 +1803,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.8.0" + "source": "https://github.com/utopia-php/cache/tree/0.9.0" }, - "time": "2022-10-16T16:48:09+00:00" + "time": "2024-01-07T18:11:23+00:00" }, { "name": "utopia-php/cli", @@ -1908,23 +1909,23 @@ }, { "name": "utopia-php/database", - "version": "0.47.0", + "version": "dev-contains-v2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf" + "reference": "75b75b09f8a849c2fe374472019a9ba5824bad1e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/a87cc66ebea6686066e03c64867fc7db07fa80cf", - "reference": "a87cc66ebea6686066e03c64867fc7db07fa80cf", + "url": "https://api.github.com/repos/utopia-php/database/zipball/75b75b09f8a849c2fe374472019a9ba5824bad1e", + "reference": "75b75b09f8a849c2fe374472019a9ba5824bad1e", "shasum": "" }, "require": { "ext-mbstring": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/cache": "0.8.*", + "utopia-php/cache": "0.9.*", "utopia-php/framework": "0.*.*", "utopia-php/mongo": "0.3.*" }, @@ -1958,9 +1959,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.47.0" + "source": "https://github.com/utopia-php/database/tree/contains-v2" }, - "time": "2023-12-14T11:02:15+00:00" + "time": "2024-01-18T12:37:43+00:00" }, { "name": "utopia-php/domains", @@ -2272,16 +2273,16 @@ }, { "name": "utopia-php/messaging", - "version": "0.8.0", + "version": "0.8.1", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "64eca3faf02a79831f219d4f3ae05cd278a88b4b" + "reference": "bfb5014d3a8752901e50da1ae21bf309a6af5006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/64eca3faf02a79831f219d4f3ae05cd278a88b4b", - "reference": "64eca3faf02a79831f219d4f3ae05cd278a88b4b", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/bfb5014d3a8752901e50da1ae21bf309a6af5006", + "reference": "bfb5014d3a8752901e50da1ae21bf309a6af5006", "shasum": "" }, "require": { @@ -2316,9 +2317,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/0.8.0" + "source": "https://github.com/utopia-php/messaging/tree/0.8.1" }, - "time": "2023-12-15T06:44:08+00:00" + "time": "2024-01-10T23:55:03+00:00" }, { "name": "utopia-php/migration", @@ -2908,22 +2909,22 @@ }, { "name": "utopia-php/vcs", - "version": "0.6.4", + "version": "0.6.5", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "b2595a50a4897a8c88319240810055b7a96efd6d" + "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/b2595a50a4897a8c88319240810055b7a96efd6d", - "reference": "b2595a50a4897a8c88319240810055b7a96efd6d", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", + "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", "shasum": "" }, "require": { "adhocore/jwt": "^1.1", "php": ">=8.0", - "utopia-php/cache": "^0.8.0", + "utopia-php/cache": "^0.9.0", "utopia-php/framework": "0.*.*" }, "require-dev": { @@ -2951,9 +2952,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/0.6.4" + "source": "https://github.com/utopia-php/vcs/tree/0.6.5" }, - "time": "2023-12-26T15:38:19+00:00" + "time": "2024-01-08T17:11:12+00:00" }, { "name": "utopia-php/websocket", @@ -3140,16 +3141,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.36.0", + "version": "0.36.2", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a" + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/0aa67479d75f0e0cb7b60454031534d7f0abaece", + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece", "shasum": "" }, "require": { @@ -3185,9 +3186,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.36.0" + "source": "https://github.com/appwrite/sdk-generator/tree/0.36.2" }, - "time": "2023-11-20T10:03:06+00:00" + "time": "2024-01-19T01:04:35+00:00" }, { "name": "doctrine/deprecations", @@ -3770,16 +3771,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.3", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fad452781b3d774e3337b0c0b245dd8e5a4455fc", + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc", "shasum": "" }, "require": { @@ -3822,9 +3823,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.0" }, - "time": "2023-08-12T11:01:26+00:00" + "time": "2024-01-11T11:49:22+00:00" }, { "name": "phpspec/prophecy", @@ -5380,16 +5381,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", "shasum": "" }, "require": { @@ -5399,11 +5400,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -5456,7 +5457,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-01-11T20:47:48+00:00" }, { "name": "swoole/ide-helper", @@ -5827,9 +5828,18 @@ "time": "2023-11-21T18:54:41+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-contains-v2", + "alias": "0.47.99", + "alias_normalized": "0.47.99.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/docker-compose.yml b/docker-compose.yml index 8fca5d67f0..84fadd2e30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -856,7 +856,7 @@ services: - OPR_PROXY_HEALTHCHECK=enabled mariadb: - image: mariadb:10.7 # fix issues when upgrading using: mysql_upgrade -u root -p + image: mariadb:10.11 # fix issues when upgrading using: mysql_upgrade -u root -p container_name: appwrite-mariadb <<: *x-logging networks: diff --git a/phpunit.xml b/phpunit.xml index 90ebd4225f..e772866051 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index b8772b5dbe..a94e1afde4 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -381,6 +381,29 @@ trait DatabasesBase 'twoWayKey' => 'movie' ]); + $strings = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'strings', + 'size' => 512, + 'required' => false, + 'array' => true, + ]); + + $integers = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'integers', + 'required' => false, + 'array' => true, + 'min' => 1, + 'max' => 999, + ]); + $this->assertEquals(202, $title['headers']['status-code']); $this->assertEquals($title['body']['key'], 'title'); $this->assertEquals($title['body']['type'], 'string'); @@ -431,6 +454,20 @@ trait DatabasesBase $this->assertEquals($relationship['body']['twoWay'], true); $this->assertEquals($relationship['body']['twoWayKey'], 'movie'); + $this->assertEquals(202, $strings['headers']['status-code']); + $this->assertEquals($strings['body']['key'], 'strings'); + $this->assertEquals($strings['body']['type'], 'string'); + $this->assertEquals($strings['body']['size'], 512); + $this->assertEquals($strings['body']['required'], false); + $this->assertEquals($strings['body']['array'], true); + + $this->assertEquals(202, $integers['headers']['status-code']); + $this->assertEquals($integers['body']['key'], 'integers'); + $this->assertEquals($integers['body']['type'], 'integer'); + $this->assertArrayNotHasKey('size', $integers['body']); + $this->assertEquals($integers['body']['required'], false); + $this->assertEquals($integers['body']['array'], true); + // wait for database worker to create attributes sleep(2); @@ -441,7 +478,7 @@ trait DatabasesBase ])); $this->assertIsArray($movies['body']['attributes']); - $this->assertCount(8, $movies['body']['attributes']); + $this->assertCount(10, $movies['body']['attributes']); $this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']); $this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']); $this->assertEquals($movies['body']['attributes'][2]['key'], $tagline['body']['key']); @@ -450,6 +487,8 @@ trait DatabasesBase $this->assertEquals($movies['body']['attributes'][5]['key'], $actors['body']['key']); $this->assertEquals($movies['body']['attributes'][6]['key'], $datetime['body']['key']); $this->assertEquals($movies['body']['attributes'][7]['key'], $relationship['body']['key']); + $this->assertEquals($movies['body']['attributes'][8]['key'], $strings['body']['key']); + $this->assertEquals($movies['body']['attributes'][9]['key'], $integers['body']['key']); return $data; } @@ -673,6 +712,29 @@ trait DatabasesBase 'twoWayKey' => 'twoWayKey' ]); + $strings = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'names', + 'size' => 512, + 'required' => false, + 'array' => true, + ]); + + $integers = $this->client->call(Client::METHOD_POST, $attributesPath . '/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'numbers', + 'required' => false, + 'array' => true, + 'min' => 1, + 'max' => 999, + ]); + $this->assertEquals(202, $string['headers']['status-code']); $this->assertEquals('string', $string['body']['key']); $this->assertEquals('string', $string['body']['type']); @@ -757,6 +819,22 @@ trait DatabasesBase $this->assertEquals(true, $relationship['body']['twoWay']); $this->assertEquals('twoWayKey', $relationship['body']['twoWayKey']); + $this->assertEquals(202, $strings['headers']['status-code']); + $this->assertEquals('names', $strings['body']['key']); + $this->assertEquals('string', $strings['body']['type']); + $this->assertEquals(false, $strings['body']['required']); + $this->assertEquals(true, $strings['body']['array']); + $this->assertEquals(null, $strings['body']['default']); + + $this->assertEquals(202, $integers['headers']['status-code']); + $this->assertEquals('numbers', $integers['body']['key']); + $this->assertEquals('integer', $integers['body']['type']); + $this->assertEquals(false, $integers['body']['required']); + $this->assertEquals(true, $integers['body']['array']); + $this->assertEquals(1, $integers['body']['min']); + $this->assertEquals(999, $integers['body']['max']); + $this->assertEquals(null, $integers['body']['default']); + // Wait for database worker to create attributes sleep(5); @@ -820,6 +898,18 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); + $stringsResponse = $this->client->call(Client::METHOD_GET, $attributesPath . '/' . $strings['body']['key'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $integersResponse = $this->client->call(Client::METHOD_GET, $attributesPath . '/' . $integers['body']['key'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->assertEquals(200, $stringResponse['headers']['status-code']); $this->assertEquals($string['body']['key'], $stringResponse['body']['key']); $this->assertEquals($string['body']['type'], $stringResponse['body']['type']); @@ -920,11 +1010,11 @@ trait DatabasesBase ])); $this->assertEquals(200, $attributes['headers']['status-code']); - $this->assertEquals(10, $attributes['body']['total']); + $this->assertEquals(12, $attributes['body']['total']); $attributes = $attributes['body']['attributes']; $this->assertIsArray($attributes); - $this->assertCount(10, $attributes); + $this->assertCount(12, $attributes); $this->assertEquals($stringResponse['body']['key'], $attributes[0]['key']); $this->assertEquals($stringResponse['body']['type'], $attributes[0]['type']); @@ -1009,6 +1099,22 @@ trait DatabasesBase $this->assertEquals($relationshipResponse['body']['twoWay'], $attributes[9]['twoWay']); $this->assertEquals($relationshipResponse['body']['twoWayKey'], $attributes[9]['twoWayKey']); + $this->assertEquals($stringsResponse['body']['key'], $attributes[10]['key']); + $this->assertEquals($stringsResponse['body']['type'], $attributes[10]['type']); + $this->assertEquals($stringsResponse['body']['status'], $attributes[10]['status']); + $this->assertEquals($stringsResponse['body']['required'], $attributes[10]['required']); + $this->assertEquals($stringsResponse['body']['array'], $attributes[10]['array']); + $this->assertEquals($stringsResponse['body']['default'], $attributes[10]['default']); + + $this->assertEquals($integersResponse['body']['key'], $attributes[11]['key']); + $this->assertEquals($integersResponse['body']['type'], $attributes[11]['type']); + $this->assertEquals($integersResponse['body']['status'], $attributes[11]['status']); + $this->assertEquals($integersResponse['body']['required'], $attributes[11]['required']); + $this->assertEquals($integersResponse['body']['array'], $attributes[11]['array']); + $this->assertEquals($integersResponse['body']['default'], $attributes[11]['default']); + $this->assertEquals($integersResponse['body']['min'], $attributes[11]['min']); + $this->assertEquals($integersResponse['body']['max'], $attributes[11]['max']); + $collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1020,7 +1126,7 @@ trait DatabasesBase $attributes = $collection['body']['attributes']; $this->assertIsArray($attributes); - $this->assertCount(10, $attributes); + $this->assertCount(12, $attributes); $this->assertEquals($stringResponse['body']['key'], $attributes[0]['key']); $this->assertEquals($stringResponse['body']['type'], $attributes[0]['type']); @@ -1105,6 +1211,22 @@ trait DatabasesBase $this->assertEquals($relationshipResponse['body']['twoWay'], $attributes[9]['twoWay']); $this->assertEquals($relationshipResponse['body']['twoWayKey'], $attributes[9]['twoWayKey']); + $this->assertEquals($stringsResponse['body']['key'], $attributes[10]['key']); + $this->assertEquals($stringsResponse['body']['type'], $attributes[10]['type']); + $this->assertEquals($stringsResponse['body']['status'], $attributes[10]['status']); + $this->assertEquals($stringsResponse['body']['required'], $attributes[10]['required']); + $this->assertEquals($stringsResponse['body']['array'], $attributes[10]['array']); + $this->assertEquals($stringsResponse['body']['default'], $attributes[10]['default']); + + $this->assertEquals($integersResponse['body']['key'], $attributes[11]['key']); + $this->assertEquals($integersResponse['body']['type'], $attributes[11]['type']); + $this->assertEquals($integersResponse['body']['status'], $attributes[11]['status']); + $this->assertEquals($integersResponse['body']['required'], $attributes[11]['required']); + $this->assertEquals($integersResponse['body']['array'], $attributes[11]['array']); + $this->assertEquals($integersResponse['body']['default'], $attributes[11]['default']); + $this->assertEquals($integersResponse['body']['min'], $attributes[11]['min']); + $this->assertEquals($integersResponse['body']['max'], $attributes[11]['max']); + /** * Test for FAILURE */ @@ -1269,6 +1391,18 @@ trait DatabasesBase $this->assertEquals(400, $tooLong['headers']['status-code']); $this->assertStringContainsString('Index length is longer than the maximum', $tooLong['body']['message']); + $fulltextArray = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'key' => 'ft', + 'type' => 'fulltext', + 'attributes' => ['strings'], + ]); + $this->assertEquals(400, $fulltextArray['headers']['status-code']); + $this->assertStringContainsString('"Fulltext" index is forbidden on array attributes', $fulltextArray['body']['message']); + return $data; } From 181d0b07ae72b4d21095a7bd514bada107581c91 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 21 Jan 2024 10:11:56 +0200 Subject: [PATCH 26/31] composer.lock --- composer.lock | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/composer.lock b/composer.lock index fe077e6b2a..267e5f2e1d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d46c668aa1176f6f78026263c661c12e", + "content-hash": "62b3540697080f73d73c137facb5c376", "packages": [ { "name": "adhocore/jwt", @@ -2273,16 +2273,16 @@ }, { "name": "utopia-php/messaging", - "version": "0.8.0", + "version": "0.8.1", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "64eca3faf02a79831f219d4f3ae05cd278a88b4b" + "reference": "bfb5014d3a8752901e50da1ae21bf309a6af5006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/64eca3faf02a79831f219d4f3ae05cd278a88b4b", - "reference": "64eca3faf02a79831f219d4f3ae05cd278a88b4b", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/bfb5014d3a8752901e50da1ae21bf309a6af5006", + "reference": "bfb5014d3a8752901e50da1ae21bf309a6af5006", "shasum": "" }, "require": { @@ -2317,9 +2317,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/0.8.0" + "source": "https://github.com/utopia-php/messaging/tree/0.8.1" }, - "time": "2023-12-15T06:44:08+00:00" + "time": "2024-01-10T23:55:03+00:00" }, { "name": "utopia-php/migration", @@ -3141,16 +3141,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.36.0", + "version": "0.36.2", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a" + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/0aa67479d75f0e0cb7b60454031534d7f0abaece", + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece", "shasum": "" }, "require": { @@ -3186,9 +3186,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.36.0" + "source": "https://github.com/appwrite/sdk-generator/tree/0.36.2" }, - "time": "2023-11-20T10:03:06+00:00" + "time": "2024-01-19T01:04:35+00:00" }, { "name": "doctrine/deprecations", @@ -3771,16 +3771,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.3", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fad452781b3d774e3337b0c0b245dd8e5a4455fc", + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc", "shasum": "" }, "require": { @@ -3823,9 +3823,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.0" }, - "time": "2023-08-12T11:01:26+00:00" + "time": "2024-01-11T11:49:22+00:00" }, { "name": "phpspec/prophecy", @@ -5381,16 +5381,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", "shasum": "" }, "require": { @@ -5400,11 +5400,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -5457,7 +5457,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-01-11T20:47:48+00:00" }, { "name": "swoole/ide-helper", From 667abce8f50d43ba718208d90b606f7f302ac0ae Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 21 Jan 2024 18:22:02 +0200 Subject: [PATCH 27/31] Create indexes & query contains --- app/controllers/api/databases.php | 2 +- phpunit.xml | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 132 ++++++++++++++---- 3 files changed, 105 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index eb2ba80892..b1b936cb07 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2503,7 +2503,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'lengths' => $lengths, 'orders' => $orders, ]); -var_dump($collection->getAttribute('attributes')); + $validator = new IndexValidator( $collection->getAttribute('attributes'), $dbForProject->getAdapter()->getMaxIndexLength() diff --git a/phpunit.xml b/phpunit.xml index e772866051..90ebd4225f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index a94e1afde4..845e535aa2 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -12,6 +12,7 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; +use Utopia\Validator\JSON; trait DatabasesBase { @@ -381,17 +382,6 @@ trait DatabasesBase 'twoWayKey' => 'movie' ]); - $strings = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'strings', - 'size' => 512, - 'required' => false, - 'array' => true, - ]); - $integers = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -400,8 +390,8 @@ trait DatabasesBase 'key' => 'integers', 'required' => false, 'array' => true, - 'min' => 1, - 'max' => 999, + 'min' => 10, + 'max' => 99, ]); $this->assertEquals(202, $title['headers']['status-code']); @@ -454,13 +444,6 @@ trait DatabasesBase $this->assertEquals($relationship['body']['twoWay'], true); $this->assertEquals($relationship['body']['twoWayKey'], 'movie'); - $this->assertEquals(202, $strings['headers']['status-code']); - $this->assertEquals($strings['body']['key'], 'strings'); - $this->assertEquals($strings['body']['type'], 'string'); - $this->assertEquals($strings['body']['size'], 512); - $this->assertEquals($strings['body']['required'], false); - $this->assertEquals($strings['body']['array'], true); - $this->assertEquals(202, $integers['headers']['status-code']); $this->assertEquals($integers['body']['key'], 'integers'); $this->assertEquals($integers['body']['type'], 'integer'); @@ -478,7 +461,7 @@ trait DatabasesBase ])); $this->assertIsArray($movies['body']['attributes']); - $this->assertCount(10, $movies['body']['attributes']); + $this->assertCount(9, $movies['body']['attributes']); $this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']); $this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']); $this->assertEquals($movies['body']['attributes'][2]['key'], $tagline['body']['key']); @@ -487,8 +470,7 @@ trait DatabasesBase $this->assertEquals($movies['body']['attributes'][5]['key'], $actors['body']['key']); $this->assertEquals($movies['body']['attributes'][6]['key'], $datetime['body']['key']); $this->assertEquals($movies['body']['attributes'][7]['key'], $relationship['body']['key']); - $this->assertEquals($movies['body']['attributes'][8]['key'], $strings['body']['key']); - $this->assertEquals($movies['body']['attributes'][9]['key'], $integers['body']['key']); + $this->assertEquals($movies['body']['attributes'][8]['key'], $integers['body']['key']); return $data; } @@ -1398,10 +1380,48 @@ trait DatabasesBase ]), [ 'key' => 'ft', 'type' => 'fulltext', - 'attributes' => ['strings'], + 'attributes' => ['actors'], ]); + $this->assertEquals(400, $fulltextArray['headers']['status-code']); - $this->assertStringContainsString('"Fulltext" index is forbidden on array attributes', $fulltextArray['body']['message']); + $this->assertEquals('"Fulltext" index is forbidden on array attributes', $fulltextArray['body']['message']); + + $actorsArray = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'key' => 'index-actors', + 'type' => 'key', + 'attributes' => ['actors'], + ]); + + $this->assertEquals(202, $actorsArray['headers']['status-code']); + + $twoLevelsArray = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'key' => 'index-ip-actors', + 'type' => 'key', + 'attributes' => ['releaseYear', 'actors'], // 2 levels + ]); + + $this->assertEquals(202, $twoLevelsArray['headers']['status-code']); + + $unknown = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'key' => 'index-unknown', + 'type' => 'key', + 'attributes' => ['Unknown'], + ]); + + $this->assertEquals(400, $unknown['headers']['status-code']); + $this->assertEquals('Unknown attribute: Unknown', $unknown['body']['message']); return $data; } @@ -1477,7 +1497,8 @@ trait DatabasesBase 'Tom Holland', 'Zendaya Maree Stoermer', 'Samuel Jackson', - ] + ], + 'integers' => [50,60] ], 'permissions' => [ Permission::read(Role::user($this->getUser()['$id'])), @@ -1500,6 +1521,7 @@ trait DatabasesBase 'Tom Holland', 'Zendaya Maree Stoermer', ], + 'integers' => [50] ], 'permissions' => [ Permission::read(Role::user($this->getUser()['$id'])), @@ -1550,6 +1572,8 @@ trait DatabasesBase $this->assertEquals($document2['body']['actors'][1], 'Zendaya Maree Stoermer'); $this->assertEquals($document2['body']['actors'][2], 'Samuel Jackson'); $this->assertEquals($document2['body']['birthDay'], null); + $this->assertEquals($document2['body']['integers'][0], 50); + $this->assertEquals($document2['body']['integers'][1], 60); $this->assertEquals(201, $document3['headers']['status-code']); $this->assertEquals($data['moviesId'], $document3['body']['$collectionId']); @@ -2010,6 +2034,18 @@ trait DatabasesBase $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); $this->assertCount(2, $documents['body']['documents']); + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::contains('title', ['spi'])->toString(), // like query + ], + ]); + + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertEquals(2, $documents['body']['total']); + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -2062,10 +2098,36 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('actors', ['Tom Holland'])->toString(), + Query::contains('actors', ['Tom Holland', 'Samuel Jackson'])->toString(), ], ]); + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertEquals(3, $documents['body']['total']); + + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::contains('actors', ['Tom'])->toString(), // Full-match not like + ], + ]); + + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertEquals(0, $documents['body']['total']); + + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::greaterThan('birthDay', '16/01/2024 12:00:00AM')->toString(), + ], + ]); + + $this->assertEquals(400, $documents['headers']['status-code']); + $this->assertEquals('Invalid query: Query value is invalid for attribute "birthDay"', $documents['body']['message']); $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ 'content-type' => 'application/json', @@ -2081,6 +2143,18 @@ trait DatabasesBase $this->assertEquals('1975-06-12T18:12:55.000+00:00', $documents['body']['documents'][1]['birthDay']); $this->assertCount(2, $documents['body']['documents']); + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::isNull('integers')->toString(), + ], + ]); + + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertEquals(1, $documents['body']['total']); + /** * Test for Failure */ @@ -2116,7 +2190,7 @@ trait DatabasesBase ], ]); - // Todo: Not sure what to do we with Query length Test VS old + // Todo: Not sure what to do we with Query length Test VS old? JSON validator will fails if query string will be truncated? //$this->assertEquals(400, $documents['headers']['status-code']); $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ @@ -2128,7 +2202,7 @@ trait DatabasesBase ], ]); $this->assertEquals(400, $documents['headers']['status-code']); - $this->assertEquals('Searching by attribute "actors" requires a fulltext index.', $documents['body']['message']); + $this->assertEquals('Invalid query: Cannot query search on attribute "actors" because it is an array.', $documents['body']['message']); return []; } From e0f760c32a32fe04d2c1c78e79c27c8e8fa39b5c Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 25 Jan 2024 17:45:57 +0200 Subject: [PATCH 28/31] composer.lock --- composer.lock | 56 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.lock b/composer.lock index 6a5ed72157..1272dcb7a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "758fc8f128df402e823dd2cb340bf78b", + "content-hash": "87638afda68aaea1819ce6cc67b5ea9d", "packages": [ { "name": "adhocore/jwt", @@ -898,23 +898,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.33.0", + "version": "0.36.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c" + "reference": "d3d09b4fa0db75935110714ad4b2a87f3ace31ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/1ba8d5f2793885cbf779e3b5b9d886968af43d2c", - "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/d3d09b4fa0db75935110714ad4b2a87f3ace31ed", + "reference": "d3d09b4fa0db75935110714ad4b2a87f3ace31ed", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.45.*" + "utopia-php/database": "0.48.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -941,9 +941,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.33.0" + "source": "https://github.com/utopia-php/abuse/tree/0.36.0" }, - "time": "2023-11-01T08:51:33+00:00" + "time": "2024-01-19T09:32:56+00:00" }, { "name": "utopia-php/analytics", @@ -993,21 +993,21 @@ }, { "name": "utopia-php/audit", - "version": "0.35.0", + "version": "0.38.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a" + "reference": "a9067f4af76e8787f1d29850a8ec94fc32bb6539" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/ed9366ef05556da040de7a8b570f4160c7d8ea4a", - "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/a9067f4af76e8787f1d29850a8ec94fc32bb6539", + "reference": "a9067f4af76e8787f1d29850a8ec94fc32bb6539", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.45.*" + "utopia-php/database": "0.48.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1034,9 +1034,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.35.0" + "source": "https://github.com/utopia-php/audit/tree/0.38.0" }, - "time": "2023-11-01T08:51:29+00:00" + "time": "2024-01-19T09:33:05+00:00" }, { "name": "utopia-php/cache", @@ -1190,16 +1190,16 @@ }, { "name": "utopia-php/database", - "version": "0.45.5", + "version": "0.48.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0b66a017f817a910acb83e6aea92bccea9571fe6" + "reference": "2651f41b9d3909dc123d26becfb6a3a44fb63077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0b66a017f817a910acb83e6aea92bccea9571fe6", - "reference": "0b66a017f817a910acb83e6aea92bccea9571fe6", + "url": "https://api.github.com/repos/utopia-php/database/zipball/2651f41b9d3909dc123d26becfb6a3a44fb63077", + "reference": "2651f41b9d3909dc123d26becfb6a3a44fb63077", "shasum": "" }, "require": { @@ -1240,22 +1240,22 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.45.5" + "source": "https://github.com/utopia-php/database/tree/0.48.0" }, - "time": "2024-01-08T17:08:15+00:00" + "time": "2024-01-19T08:17:22+00:00" }, { "name": "utopia-php/domains", - "version": "0.5.0", + "version": "0.3.2", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "bf07f60326f8389f378ddf6fcde86217e5cfe18c" + "reference": "aaa8c9a96c69ccb397997b1f4f2299c66f77eefb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/bf07f60326f8389f378ddf6fcde86217e5cfe18c", - "reference": "bf07f60326f8389f378ddf6fcde86217e5cfe18c", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/aaa8c9a96c69ccb397997b1f4f2299c66f77eefb", + "reference": "aaa8c9a96c69ccb397997b1f4f2299c66f77eefb", "shasum": "" }, "require": { @@ -1300,9 +1300,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/0.5.0" + "source": "https://github.com/utopia-php/domains/tree/0.3.2" }, - "time": "2024-01-03T22:04:27+00:00" + "time": "2023-07-19T16:39:24+00:00" }, { "name": "utopia-php/dsn", @@ -5174,5 +5174,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 41421ba1789f5809664835c3839a7e776dc56f56 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 25 Jan 2024 17:49:50 +0200 Subject: [PATCH 29/31] Fix Domains not found --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index b499a5cbba..75cb1fe8f6 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", "utopia-php/database": "0.48.*", - "utopia-php/domains": "0.3.*", + "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.33.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index 1272dcb7a4..0cbc3edd2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "87638afda68aaea1819ce6cc67b5ea9d", + "content-hash": "463c5722b5b926ea567fe24d8b983755", "packages": [ { "name": "adhocore/jwt", @@ -1246,16 +1246,16 @@ }, { "name": "utopia-php/domains", - "version": "0.3.2", + "version": "0.5.0", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "aaa8c9a96c69ccb397997b1f4f2299c66f77eefb" + "reference": "bf07f60326f8389f378ddf6fcde86217e5cfe18c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/aaa8c9a96c69ccb397997b1f4f2299c66f77eefb", - "reference": "aaa8c9a96c69ccb397997b1f4f2299c66f77eefb", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/bf07f60326f8389f378ddf6fcde86217e5cfe18c", + "reference": "bf07f60326f8389f378ddf6fcde86217e5cfe18c", "shasum": "" }, "require": { @@ -1300,9 +1300,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/0.3.2" + "source": "https://github.com/utopia-php/domains/tree/0.5.0" }, - "time": "2023-07-19T16:39:24+00:00" + "time": "2024-01-03T22:04:27+00:00" }, { "name": "utopia-php/dsn", From 998c4d282d2fb4967abdd13c673b7086d66b3a07 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 25 Jan 2024 18:53:51 +0200 Subject: [PATCH 30/31] Fix failing tests --- app/controllers/api/account.php | 2 +- app/controllers/api/messaging.php | 2 +- app/controllers/api/users.php | 2 +- src/Appwrite/Platform/Workers/Webhooks.php | 4 ++-- .../Services/Account/AccountCustomClientTest.php | 14 +++++++++++--- tests/e2e/Services/Messaging/MessagingBase.php | 3 ++- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index fc2afc142a..8589c6a747 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1326,7 +1326,7 @@ App::post('/v1/account/tokens/email') Permission::delete(Role::user($user->getId())), ])); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $subject = $locale->getText("emails.otpSession.subject"); $customTemplate = $project->getAttribute('templates', [])['email.otpSession-' . $locale->default] ?? []; diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 8a9bdc7887..93c907a76f 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2782,7 +2782,7 @@ App::get('/v1/messaging/messages/:messageId/targets') $queries[] = Query::equal('$id', $targetIDs); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); + $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index dc2df5db54..0f9a04639d 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1531,7 +1531,7 @@ App::post('/v1/users/:userId/tokens') ]); $token = $dbForProject->createDocument('tokens', $token); - $dbForProject->deleteCachedDocument('users', $user->getId()); + $dbForProject->purgeCachedDocument('users', $user->getId()); $token->setAttribute('secret', $secret); diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 880ae587e1..6f7ab1c698 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -163,13 +163,13 @@ class Webhooks extends Action } $dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); $this->errors[] = $logs; } else { $webhook->setAttribute('attempts', 0); // Reset attempts on success $dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook); - $dbForConsole->deleteCachedDocument('projects', $project->getId()); + $dbForConsole->purgeCachedDocument('projects', $project->getId()); } } diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index c6c0b5cb7d..0b3ac5edc6 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; use Utopia\Database\DateTime; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; use function sleep; @@ -344,7 +345,9 @@ class AccountCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'limit(1)' ], + 'queries' => [ + Query::limit(1)->toString() + ] ]); $this->assertEquals($responseLimit['headers']['status-code'], 200); @@ -361,7 +364,9 @@ class AccountCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'offset(1)' ], + 'queries' => [ + Query::offset(1)->toString() + ] ]); $this->assertEquals($responseOffset['headers']['status-code'], 200); @@ -378,7 +383,10 @@ class AccountCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'queries' => [ 'limit(1)', 'offset(1)' ], + 'queries' => [ + Query::offset(1)->toString(), + Query::limit(1)->toString() + ] ]); $this->assertEquals($responseLimitOffset['headers']['status-code'], 200); diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 0b5ca80ec1..b5547832a2 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -6,6 +6,7 @@ use Appwrite\Enum\MessageStatus; use Tests\E2E\Client; use Utopia\App; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\DSN\DSN; trait MessagingBase @@ -651,7 +652,7 @@ trait MessagingBase $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); $user = $response['body']; - var_dump($user); + $this->assertEquals(1, \count($user['targets'])); $targetId = $user['targets'][0]['$id']; From 981ba852c558fa9e7e69a3d56cb390bc3d62ec12 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 25 Jan 2024 19:01:48 +0200 Subject: [PATCH 31/31] lint --- tests/e2e/Services/Messaging/MessagingBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index b5547832a2..f766750ad5 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -652,7 +652,7 @@ trait MessagingBase $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); $user = $response['body']; - + $this->assertEquals(1, \count($user['targets'])); $targetId = $user['targets'][0]['$id'];