From bbd1fd9c5ff7fa90720e4e3ecc2cfec0c503ac4d Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Tue, 3 Aug 2021 16:21:37 -0400 Subject: [PATCH 1/4] Update utopia-php/database from 0.5 to 0.6 --- composer.json | 2 +- composer.lock | 45 ++++++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 8ab33521c9..1c9b75e832 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "utopia-php/cache": "0.4.*", "utopia-php/cli": "0.11.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.5.*", + "utopia-php/database": "0.6.*", "utopia-php/locale": "0.3.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", diff --git a/composer.lock b/composer.lock index 5ce06b40ea..93211445d4 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": "58102c809e5d82ce2c41dfca515a18dc", + "content-hash": "0247f77dbdda25ccaeef2d9ae9671325", "packages": [ { "name": "adhocore/jwt", @@ -1666,22 +1666,22 @@ }, { "name": "utopia-php/abuse", - "version": "0.6.0", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "f568f97467eca66450af6fba18038ddeb8e8d05a" + "reference": "c9078aa3a87750d66060f0ed7642e03e5815da17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/f568f97467eca66450af6fba18038ddeb8e8d05a", - "reference": "f568f97467eca66450af6fba18038ddeb8e8d05a", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/c9078aa3a87750d66060f0ed7642e03e5815da17", + "reference": "c9078aa3a87750d66060f0ed7642e03e5815da17", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=7.4", - "utopia-php/database": "0.5.*" + "utopia-php/database": "0.6.*" }, "require-dev": { "phpunit/phpunit": "^9.4", @@ -1713,9 +1713,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.6.0" + "source": "https://github.com/utopia-php/abuse/tree/0.6.1" }, - "time": "2021-08-01T11:16:50+00:00" + "time": "2021-08-03T19:31:07+00:00" }, { "name": "utopia-php/analytics", @@ -1774,22 +1774,22 @@ }, { "name": "utopia-php/audit", - "version": "0.6.0", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "f81bbe0bf64d74c9668ca7ab90d0b6eb3df4d47e" + "reference": "971dcd5c88309656df31ac20f326d3ac8b555594" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/f81bbe0bf64d74c9668ca7ab90d0b6eb3df4d47e", - "reference": "f81bbe0bf64d74c9668ca7ab90d0b6eb3df4d47e", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/971dcd5c88309656df31ac20f326d3ac8b555594", + "reference": "971dcd5c88309656df31ac20f326d3ac8b555594", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=7.4", - "utopia-php/database": "0.5.*" + "utopia-php/database": "0.6.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -1821,9 +1821,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.6.0" + "source": "https://github.com/utopia-php/audit/tree/0.6.1" }, - "time": "2021-08-01T11:14:31+00:00" + "time": "2021-08-03T19:29:34+00:00" }, { "name": "utopia-php/cache", @@ -1984,16 +1984,16 @@ }, { "name": "utopia-php/database", - "version": "0.5.0", + "version": "0.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "e050e51060df72eff3af9fc24fc95a41ca9a2096" + "reference": "561adc215fce3bd3b8c3ebb971ca354fb1526f26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/e050e51060df72eff3af9fc24fc95a41ca9a2096", - "reference": "e050e51060df72eff3af9fc24fc95a41ca9a2096", + "url": "https://api.github.com/repos/utopia-php/database/zipball/561adc215fce3bd3b8c3ebb971ca354fb1526f26", + "reference": "561adc215fce3bd3b8c3ebb971ca354fb1526f26", "shasum": "" }, "require": { @@ -2041,9 +2041,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.5.0" + "source": "https://github.com/utopia-php/database/tree/0.6.0" }, - "time": "2021-07-03T16:49:44+00:00" + "time": "2021-08-03T15:13:48+00:00" }, { "name": "utopia-php/domains", @@ -5154,7 +5154,6 @@ "type": "github" } ], - "abandoned": true, "time": "2020-09-28T06:45:17+00:00" }, { @@ -6279,5 +6278,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } From 1766be331a9f4f73b843567de2c301512779f8ba Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Tue, 3 Aug 2021 16:22:03 -0400 Subject: [PATCH 2/4] Change findFirst to findOne --- app/controllers/api/account.php | 12 ++++++------ app/controllers/api/teams.php | 2 +- app/controllers/general.php | 4 ++-- app/workers/certificates.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 8c173844fe..8a6f951645 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -156,7 +156,7 @@ App::post('/v1/account/sessions') $email = \strtolower($email); $protocol = $request->getProtocol(); - $profile = $dbForInternal->findFirst('users', [new Query('email', Query::TYPE_EQUAL, [$email])], 1); // Get user by email address + $profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [$email])]); // Get user by email address if (!$profile || !Auth::passwordVerify($password, $profile->getAttribute('password'))) { $audits @@ -442,16 +442,16 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') } } - $user = ($user->isEmpty()) ? $dbForInternal->findFirst('sessions', [ // Get user by provider id + $user = ($user->isEmpty()) ? $dbForInternal->findOne('sessions', [ // Get user by provider id new Query('provider', QUERY::TYPE_EQUAL, [$provider]), new Query('providerUid', QUERY::TYPE_EQUAL, [$oauth2ID]), - ], 1) : $user; + ]) : $user; if ($user === false || $user->isEmpty()) { // No user logged in or with OAuth2 provider ID, create new one or connect with account with same email $name = $oauth2->getUserName($accessToken); $email = $oauth2->getUserEmail($accessToken); - $user = $dbForInternal->findFirst('users', [new Query('email', Query::TYPE_EQUAL, [$email])], 1); // Get user by email address + $user = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [$email])]); // Get user by email address if ($user === false || $user->isEmpty()) { // Last option -> create the user, generate random password $limit = $project->getAttribute('usersAuthLimit', 0); @@ -1074,7 +1074,7 @@ App::patch('/v1/account/email') } $email = \strtolower($email); - $profile = $dbForInternal->findFirst('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])], 1); // Get user by email address + $profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])]); // Get user by email address if ($profile) { throw new Exception('User already registered', 400); @@ -1379,7 +1379,7 @@ App::post('/v1/account/recovery') $isAppUser = Auth::isAppUser(Authorization::$roles); $email = \strtolower($email); - $profile = $dbForInternal->findFirst('users', [new Query('email', Query::TYPE_EQUAL, [$email])], 1); // Get user by email address + $profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [$email])]); // Get user by email address if (!$profile) { throw new Exception('User not found', 404); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b143be9b5c..921ef4163c 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -273,7 +273,7 @@ App::post('/v1/teams/:teamId/memberships') throw new Exception('Team not found', 404); } - $invitee = $dbForInternal->findFirst('users', [new Query('email', Query::TYPE_EQUAL, [$email])], 1); // Get user by email address + $invitee = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [$email])]); // Get user by email address if (empty($invitee)) { // Create new user if no user with same email found diff --git a/app/controllers/general.php b/app/controllers/general.php index af2147e4db..91b96edb83 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -44,9 +44,9 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons } else { Authorization::disable(); - $certificate = $dbForConsole->findFirst('certificates', [ + $certificate = $dbForConsole->findOne('certificates', [ new Query('domain', QUERY::TYPE_EQUAL, [$domain->get()]) - ], /*limit*/ 1); + ]); if (empty($certificate)) { $certificate = new Document([ diff --git a/app/workers/certificates.php b/app/workers/certificates.php index 1720d6adb9..96148b9e71 100644 --- a/app/workers/certificates.php +++ b/app/workers/certificates.php @@ -78,9 +78,9 @@ class CertificatesV1 extends Worker } } - $certificate = $dbForConsole->findFirst('certificates', [ + $certificate = $dbForConsole->findOne('certificates', [ new Query('domain', QUERY::TYPE_EQUAL, [$domain->get()]) - ], /*limit*/ 1); + ]); // $condition = ($certificate // && $certificate instanceof Document From 1b0a59d14aff7deb4e9ae2a6f805e34857e8bc19 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Tue, 3 Aug 2021 16:22:12 -0400 Subject: [PATCH 3/4] Use new format param for attributes --- app/controllers/api/database.php | 2 +- app/workers/database.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 46904fbd62..f1acd69194 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -266,7 +266,7 @@ App::post('/v1/database/collections/:collectionId/attributes') $signed = true; $filters = []; - $success = $dbForExternal->addAttributeInQueue($collectionId, $id, $type, $size, $required, $default, $signed, $array, $filters); + $success = $dbForExternal->addAttributeInQueue($collectionId, $id, $type, $size, $required, $default, $signed, $array, /*format*/ null, $filters); // Database->addAttributeInQueue() does not return a document // So we need to create one for the response diff --git a/app/workers/database.php b/app/workers/database.php index 544ffe1060..42df89e1b5 100644 --- a/app/workers/database.php +++ b/app/workers/database.php @@ -71,9 +71,10 @@ class DatabaseV1 extends Worker $default = $attribute->getAttribute('default', null); $signed = $attribute->getAttribute('signed', true); $array = $attribute->getAttribute('array', false); + $format = $attribute->getAttribute('format', null); $filters = $attribute->getAttribute('filters', []); - $success = $dbForExternal->createAttribute($collectionId, $id, $type, $size, $required, $default, $signed, $array, $filters); + $success = $dbForExternal->createAttribute($collectionId, $id, $type, $size, $required, $default, $signed, $array, $format, $filters); if ($success) { $removed = $dbForExternal->removeAttributeInQueue($collectionId, $id); } From dfd6d743a0a191576514e6882b5c18458c3ff7d7 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Tue, 3 Aug 2021 16:22:31 -0400 Subject: [PATCH 4/4] Key index constant renamed to key --- tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 2f254b0e6d..4de19f3876 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -64,7 +64,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'id' => 'fullname', - 'type' => 'text', + 'type' => 'key', 'attributes' => ['lastName', 'firstName'], 'orders' => ['ASC', 'ASC'], ]);