From be3e3790c9ffcc2f6c1bf30bee13710e06cfffaf Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 18 Sep 2024 14:47:36 +0900 Subject: [PATCH 1/8] Update Database lib, update instances where findOne is used to ensure we check document is empty. --- app/controllers/api/account.php | 10 ++--- app/controllers/api/teams.php | 4 +- app/controllers/api/users.php | 4 +- app/controllers/general.php | 4 +- composer.json | 6 +-- composer.lock | 42 +++++++++---------- .../Platform/Workers/Certificates.php | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a76b9dbea5..2e780f1c87 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -395,7 +395,7 @@ Http::post('/v1/account') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if ($existingTarget) { + if ($existingTarget !== false && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -840,7 +840,7 @@ Http::post('/v1/account/sessions/email') Query::equal('email', [$email]), ]); - if (!$profile || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { + if ($profile === false || $profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { throw new Exception(Exception::USER_INVALID_CREDENTIALS); } @@ -1386,7 +1386,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('providerEmail', [$email]), Query::notEqual('userInternalId', $user->getInternalId()), ]); - if (!empty($identityWithMatchingEmail)) { + if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -2406,7 +2406,7 @@ Http::post('/v1/account/tokens/phone') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); + $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget->isEmpty() ? false : $existingTarget]); } $dbForProject->purgeCachedDocument('users', $user->getId()); } @@ -3026,7 +3026,7 @@ Http::post('/v1/account/recovery') Query::equal('email', [$email]), ]); - if (!$profile) { + if ($profile === false || $profile->isEmpty()) { throw new Exception(Exception::USER_NOT_FOUND); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 16529d3dbd..3641b79ba5 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -452,12 +452,12 @@ Http::post('/v1/teams/:teamId/memberships') $name = empty($name) ? $invitee->getAttribute('name', '') : $name; } elseif (!empty($email)) { $invitee = $dbForProject->findOne('users', [Query::equal('email', [$email])]); // Get user by email address - if (!empty($invitee) && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) { + if (!empty($invitee) && !$invitee->isEmpty() && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) { throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given email and phone doesn\'t match', 409); } } elseif (!empty($phone)) { $invitee = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); - if (!empty($invitee) && !empty($email) && $invitee->getAttribute('email', '') !== $email) { + if (!empty($invitee) && !$invitee->isEmpty() && !empty($email) && $invitee->getAttribute('email', '') !== $email) { throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given phone and email doesn\'t match', 409); } } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d3ac1b75e5..fdf4eea265 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if ($existingTarget) { + if ($existingTarget !== false && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - if ($existingTarget) { + if ($existingTarget !== false && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } diff --git a/app/controllers/general.php b/app/controllers/general.php index fb258182d3..42882e6012 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -520,7 +520,7 @@ Http::init() $mainDomain = $envDomain; } else { $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); - $mainDomain = $domainDocument ? $domainDocument->getAttribute('domain') : $domain->get(); + $mainDomain = ($domainDocument !== false && !$domainDocument->isEmpty()) ? $domainDocument->getAttribute('domain') : $domain->get(); } if ($mainDomain !== $domain->get()) { @@ -530,7 +530,7 @@ Http::init() Query::equal('domain', [$domain->get()]) ]); - if (!$domainDocument) { + if ($domainDocument === false || $domainDocument->isEmpty()) { $domainDocument = new Document([ 'domain' => $domain->get(), 'resourceType' => 'api', diff --git a/composer.json b/composer.json index e23806adc9..479770ffbd 100644 --- a/composer.json +++ b/composer.json @@ -47,13 +47,13 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.15.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "0.44.*", + "utopia-php/abuse": "0.45.*", "utopia-php/analytics": "0.13.*", - "utopia-php/audit": "0.44.*", + "utopia-php/audit": "0.45.*", "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.19.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.54.*", + "utopia-php/database": "0.55.*", "utopia-php/domains": "0.6.*", "utopia-php/dsn": "0.2.*", "utopia-php/framework": "1.0.*", diff --git a/composer.lock b/composer.lock index cff13d28a1..a44c08de01 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": "6017f815da50b7d4dabad66386e013e3", + "content-hash": "2244ee2e6eb7e953f40be5e58d4dd7ff", "packages": [ { "name": "adhocore/jwt", @@ -1429,16 +1429,16 @@ }, { "name": "utopia-php/abuse", - "version": "0.44.0", + "version": "0.45.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "cd37bba23778f3a0dc54b4ba6ffb36d4d91ed8f1" + "reference": "9e5edb302db9aa88279272de00271d3cebcb3c7a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/cd37bba23778f3a0dc54b4ba6ffb36d4d91ed8f1", - "reference": "cd37bba23778f3a0dc54b4ba6ffb36d4d91ed8f1", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/9e5edb302db9aa88279272de00271d3cebcb3c7a", + "reference": "9e5edb302db9aa88279272de00271d3cebcb3c7a", "shasum": "" }, "require": { @@ -1446,7 +1446,7 @@ "ext-pdo": "*", "ext-redis": "*", "php": ">=8.0", - "utopia-php/database": "0.54.*" + "utopia-php/database": "0.55.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1474,9 +1474,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.44.0" + "source": "https://github.com/utopia-php/abuse/tree/0.45.0" }, - "time": "2024-09-05T16:09:32+00:00" + "time": "2024-09-18T04:39:25+00:00" }, { "name": "utopia-php/analytics", @@ -1527,21 +1527,21 @@ }, { "name": "utopia-php/audit", - "version": "0.44.0", + "version": "0.45.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "69eee24e4d6cb8fdae31235d80b9a46b18092139" + "reference": "7269c5378fcc36d2c3d07cb98bea160236aab805" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/69eee24e4d6cb8fdae31235d80b9a46b18092139", - "reference": "69eee24e4d6cb8fdae31235d80b9a46b18092139", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/7269c5378fcc36d2c3d07cb98bea160236aab805", + "reference": "7269c5378fcc36d2c3d07cb98bea160236aab805", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.54.*" + "utopia-php/database": "0.55.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1568,9 +1568,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.44.0" + "source": "https://github.com/utopia-php/audit/tree/0.45.0" }, - "time": "2024-09-05T16:12:41+00:00" + "time": "2024-09-18T04:40:00+00:00" }, { "name": "utopia-php/cache", @@ -1726,16 +1726,16 @@ }, { "name": "utopia-php/database", - "version": "0.54.1", + "version": "0.55", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "c32d6eab5992c927cbf6fb4aad51d76fc5f64946" + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/c32d6eab5992c927cbf6fb4aad51d76fc5f64946", - "reference": "c32d6eab5992c927cbf6fb4aad51d76fc5f64946", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0ad2eb1c163196cd79253c59f1896c5b03d6ba91", + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91", "shasum": "" }, "require": { @@ -1776,9 +1776,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.54.1" + "source": "https://github.com/utopia-php/database/tree/0.55" }, - "time": "2024-09-10T10:08:37+00:00" + "time": "2024-09-18T04:00:12+00:00" }, { "name": "utopia-php/di", diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 4a8d928ba2..fdfe4ce8a9 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -126,7 +126,7 @@ class Certificates extends Action $certificate = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain->get()])]); // If we don't have certificate for domain yet, let's create new document. At the end we save it - if (!$certificate) { + if (!$certificate || $certificate->isEmpty()) { $certificate = new Document(); $certificate->setAttribute('domain', $domain->get()); } From e88cfed03a5bafd82dd598dda4700fb772f2fb08 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 18 Sep 2024 16:30:02 +0900 Subject: [PATCH 2/8] Normalize algorithm being used --- app/controllers/api/account.php | 10 +++++----- app/controllers/api/teams.php | 2 +- app/controllers/api/users.php | 4 ++-- app/controllers/general.php | 4 ++-- src/Appwrite/Platform/Workers/Certificates.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 2e780f1c87..879695db3e 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -395,7 +395,7 @@ Http::post('/v1/account') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if ($existingTarget !== false && !$existingTarget->isEmpty()) { + if (!empty($existingTarget) && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -840,7 +840,7 @@ Http::post('/v1/account/sessions/email') Query::equal('email', [$email]), ]); - if ($profile === false || $profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { + if (empty($profile) || $profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { throw new Exception(Exception::USER_INVALID_CREDENTIALS); } @@ -1386,7 +1386,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('providerEmail', [$email]), Query::notEqual('userInternalId', $user->getInternalId()), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!empty($identityWithMatchingEmail) && !$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -2406,7 +2406,7 @@ Http::post('/v1/account/tokens/phone') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget->isEmpty() ? false : $existingTarget]); + $user->setAttribute('targets', [...$user->getAttribute('targets', []), (empty($existingTarget) || $existingTarget->isEmpty()) ? false : $existingTarget]); } $dbForProject->purgeCachedDocument('users', $user->getId()); } @@ -3026,7 +3026,7 @@ Http::post('/v1/account/recovery') Query::equal('email', [$email]), ]); - if ($profile === false || $profile->isEmpty()) { + if (empty($profile) || $profile->isEmpty()) { throw new Exception(Exception::USER_NOT_FOUND); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 3641b79ba5..d6b8889de5 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -462,7 +462,7 @@ Http::post('/v1/teams/:teamId/memberships') } } - if (empty($invitee)) { // Create new user if no user with same email found + if (empty($invitee) || $invitee->isEmpty()) { // Create new user if no user with same email found $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if (!$isPrivilegedUser && !$isAppUser && $limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed. diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index fdf4eea265..525a7287e2 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if ($existingTarget !== false && !$existingTarget->isEmpty()) { + if (!empty($existingTarget) && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - if ($existingTarget !== false && !$existingTarget->isEmpty()) { + if (!empty($existingTarget) && !$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } diff --git a/app/controllers/general.php b/app/controllers/general.php index 42882e6012..e4a245abd3 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -520,7 +520,7 @@ Http::init() $mainDomain = $envDomain; } else { $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); - $mainDomain = ($domainDocument !== false && !$domainDocument->isEmpty()) ? $domainDocument->getAttribute('domain') : $domain->get(); + $mainDomain = (!empty($domainDocument) && !$domainDocument->isEmpty()) ? $domainDocument->getAttribute('domain') : $domain->get(); } if ($mainDomain !== $domain->get()) { @@ -530,7 +530,7 @@ Http::init() Query::equal('domain', [$domain->get()]) ]); - if ($domainDocument === false || $domainDocument->isEmpty()) { + if (empty($domainDocument) || $domainDocument->isEmpty()) { $domainDocument = new Document([ 'domain' => $domain->get(), 'resourceType' => 'api', diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index fdfe4ce8a9..468bfd4c99 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -126,7 +126,7 @@ class Certificates extends Action $certificate = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain->get()])]); // If we don't have certificate for domain yet, let's create new document. At the end we save it - if (!$certificate || $certificate->isEmpty()) { + if (empty($certificate) || $certificate->isEmpty()) { $certificate = new Document(); $certificate->setAttribute('domain', $domain->get()); } From 1e7c51cf04223762518d2b22ae797e950d1c8fac Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 27 Sep 2024 12:50:32 +0900 Subject: [PATCH 3/8] Update lockfile --- composer.lock | 82 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/composer.lock b/composer.lock index a44c08de01..ee5e483d1f 100644 --- a/composer.lock +++ b/composer.lock @@ -2126,16 +2126,16 @@ }, { "name": "utopia-php/logger", - "version": "0.6.0", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/logger.git", - "reference": "a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9" + "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/logger/zipball/a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9", - "reference": "a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9", + "url": "https://api.github.com/repos/utopia-php/logger/zipball/7e8ff512c6f04577aba1df67c7b9628971946f9c", + "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c", "shasum": "" }, "require": { @@ -2174,9 +2174,9 @@ ], "support": { "issues": "https://github.com/utopia-php/logger/issues", - "source": "https://github.com/utopia-php/logger/tree/0.6.0" + "source": "https://github.com/utopia-php/logger/tree/0.6.1" }, - "time": "2024-05-23T13:37:54+00:00" + "time": "2024-09-20T14:02:12+00:00" }, { "name": "utopia-php/messaging", @@ -3410,16 +3410,16 @@ }, { "name": "laravel/pint", - "version": "v1.17.3", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "9d77be916e145864f10788bb94531d03e1f7b482" + "reference": "35c00c05ec43e6b46d295efc0f4386ceb30d50d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/9d77be916e145864f10788bb94531d03e1f7b482", - "reference": "9d77be916e145864f10788bb94531d03e1f7b482", + "url": "https://api.github.com/repos/laravel/pint/zipball/35c00c05ec43e6b46d295efc0f4386ceb30d50d9", + "reference": "35c00c05ec43e6b46d295efc0f4386ceb30d50d9", "shasum": "" }, "require": { @@ -3472,7 +3472,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-09-03T15:00:28+00:00" + "time": "2024-09-24T17:22:50+00:00" }, { "name": "matthiasmullie/minify", @@ -4281,16 +4281,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.30.1", + "version": "1.32.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "51b95ec8670af41009e2b2b56873bad96682413e" + "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/51b95ec8670af41009e2b2b56873bad96682413e", - "reference": "51b95ec8670af41009e2b2b56873bad96682413e", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6ca22b154efdd9e3c68c56f5d94670920a1c19a4", + "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4", "shasum": "" }, "require": { @@ -4322,9 +4322,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.30.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.32.0" }, - "time": "2024-09-07T20:13:05+00:00" + "time": "2024-09-26T07:23:32+00:00" }, { "name": "phpstan/phpstan", @@ -6020,16 +6020,16 @@ }, { "name": "symfony/console", - "version": "v7.1.4", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" + "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "url": "https://api.github.com/repos/symfony/console/zipball/0fa539d12b3ccf068a722bbbffa07ca7079af9ee", + "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee", "shasum": "" }, "require": { @@ -6093,7 +6093,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.4" + "source": "https://github.com/symfony/console/tree/v7.1.5" }, "funding": [ { @@ -6109,7 +6109,7 @@ "type": "tidelift" } ], - "time": "2024-08-15T22:48:53+00:00" + "time": "2024-09-20T08:28:38+00:00" }, { "name": "symfony/deprecation-contracts", @@ -6180,16 +6180,16 @@ }, { "name": "symfony/filesystem", - "version": "v7.1.2", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "92a91985250c251de9b947a14bb2c9390b1a562c" + "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/92a91985250c251de9b947a14bb2c9390b1a562c", - "reference": "92a91985250c251de9b947a14bb2c9390b1a562c", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/61fe0566189bf32e8cfee78335d8776f64a66f5a", + "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a", "shasum": "" }, "require": { @@ -6226,7 +6226,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.1.2" + "source": "https://github.com/symfony/filesystem/tree/v7.1.5" }, "funding": [ { @@ -6242,7 +6242,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T10:03:55+00:00" + "time": "2024-09-17T09:16:35+00:00" }, { "name": "symfony/finder", @@ -6691,16 +6691,16 @@ }, { "name": "symfony/process", - "version": "v7.1.3", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca" + "reference": "5c03ee6369281177f07f7c68252a280beccba847" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca", - "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca", + "url": "https://api.github.com/repos/symfony/process/zipball/5c03ee6369281177f07f7c68252a280beccba847", + "reference": "5c03ee6369281177f07f7c68252a280beccba847", "shasum": "" }, "require": { @@ -6732,7 +6732,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.3" + "source": "https://github.com/symfony/process/tree/v7.1.5" }, "funding": [ { @@ -6748,7 +6748,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:44:47+00:00" + "time": "2024-09-19T21:48:23+00:00" }, { "name": "symfony/service-contracts", @@ -6835,16 +6835,16 @@ }, { "name": "symfony/string", - "version": "v7.1.4", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" + "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "url": "https://api.github.com/repos/symfony/string/zipball/d66f9c343fa894ec2037cc928381df90a7ad4306", + "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306", "shasum": "" }, "require": { @@ -6902,7 +6902,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.4" + "source": "https://github.com/symfony/string/tree/v7.1.5" }, "funding": [ { @@ -6918,7 +6918,7 @@ "type": "tidelift" } ], - "time": "2024-08-12T09:59:40+00:00" + "time": "2024-09-20T08:28:38+00:00" }, { "name": "textalk/websocket", From 91b78a70aeeeb233b21143fabbbf88c9995dc8fd Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 7 Oct 2024 11:40:01 +0900 Subject: [PATCH 4/8] Remove redundancy --- app/controllers/api/account.php | 10 +++++----- app/controllers/api/teams.php | 6 +++--- app/controllers/api/users.php | 4 ++-- app/controllers/general.php | 4 ++-- src/Appwrite/Platform/Workers/Certificates.php | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 879695db3e..a0d5bf717f 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -395,7 +395,7 @@ Http::post('/v1/account') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if (!empty($existingTarget) && !$existingTarget->isEmpty()) { + if (!$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -840,7 +840,7 @@ Http::post('/v1/account/sessions/email') Query::equal('email', [$email]), ]); - if (empty($profile) || $profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { + if ($profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { throw new Exception(Exception::USER_INVALID_CREDENTIALS); } @@ -1386,7 +1386,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('providerEmail', [$email]), Query::notEqual('userInternalId', $user->getInternalId()), ]); - if (!empty($identityWithMatchingEmail) && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -2406,7 +2406,7 @@ Http::post('/v1/account/tokens/phone') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - $user->setAttribute('targets', [...$user->getAttribute('targets', []), (empty($existingTarget) || $existingTarget->isEmpty()) ? false : $existingTarget]); + $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget->isEmpty() ? false : $existingTarget]); } $dbForProject->purgeCachedDocument('users', $user->getId()); } @@ -3026,7 +3026,7 @@ Http::post('/v1/account/recovery') Query::equal('email', [$email]), ]); - if (empty($profile) || $profile->isEmpty()) { + if ($profile->isEmpty()) { throw new Exception(Exception::USER_NOT_FOUND); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index d6b8889de5..ed49ba012f 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -452,17 +452,17 @@ Http::post('/v1/teams/:teamId/memberships') $name = empty($name) ? $invitee->getAttribute('name', '') : $name; } elseif (!empty($email)) { $invitee = $dbForProject->findOne('users', [Query::equal('email', [$email])]); // Get user by email address - if (!empty($invitee) && !$invitee->isEmpty() && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) { + if (!$invitee->isEmpty() && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) { throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given email and phone doesn\'t match', 409); } } elseif (!empty($phone)) { $invitee = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); - if (!empty($invitee) && !$invitee->isEmpty() && !empty($email) && $invitee->getAttribute('email', '') !== $email) { + if (!$invitee->isEmpty() && !empty($email) && $invitee->getAttribute('email', '') !== $email) { throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given phone and email doesn\'t match', 409); } } - if (empty($invitee) || $invitee->isEmpty()) { // Create new user if no user with same email found + if ($invitee->isEmpty()) { // Create new user if no user with same email found $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if (!$isPrivilegedUser && !$isAppUser && $limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed. diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 525a7287e2..e9b2bb5024 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if (!empty($existingTarget) && !$existingTarget->isEmpty()) { + if (!$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - if (!empty($existingTarget) && !$existingTarget->isEmpty()) { + if (!$existingTarget->isEmpty()) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } diff --git a/app/controllers/general.php b/app/controllers/general.php index e4a245abd3..9df5088666 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -520,7 +520,7 @@ Http::init() $mainDomain = $envDomain; } else { $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); - $mainDomain = (!empty($domainDocument) && !$domainDocument->isEmpty()) ? $domainDocument->getAttribute('domain') : $domain->get(); + $mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get(); } if ($mainDomain !== $domain->get()) { @@ -530,7 +530,7 @@ Http::init() Query::equal('domain', [$domain->get()]) ]); - if (empty($domainDocument) || $domainDocument->isEmpty()) { + if ($domainDocument->isEmpty()) { $domainDocument = new Document([ 'domain' => $domain->get(), 'resourceType' => 'api', diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 468bfd4c99..396977f1ba 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -126,7 +126,7 @@ class Certificates extends Action $certificate = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain->get()])]); // If we don't have certificate for domain yet, let's create new document. At the end we save it - if (empty($certificate) || $certificate->isEmpty()) { + if ($certificate->isEmpty()) { $certificate = new Document(); $certificate->setAttribute('domain', $domain->get()); } From 1a903efc06a2f11fb85dfaa35aa9173b8023411a Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 8 Oct 2024 11:34:27 +0900 Subject: [PATCH 5/8] Use repository temporarily to check tests --- composer.json | 10 ++++-- composer.lock | 86 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index c176d383f3..e3f412de20 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.5", + "utopia-php/database": "dev-feat-findone-update-0.53.x as 0.53.6", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", @@ -97,5 +97,11 @@ "platform": { "php": "8.3" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/database.git" + } + ] } diff --git a/composer.lock b/composer.lock index 4281d45493..a6aafebe40 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": "1884e3a2966762c4a955842426b64f6c", + "content-hash": "be975bb1dc68125e005eba8ac5de635c", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.5", + "version": "dev-feat-findone-update-0.53.x", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "689ba22063bf46def385da8695ba7a921e81e38d" + "reference": "923260ac25780b3e60c255a5529da4cc440ae174" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/689ba22063bf46def385da8695ba7a921e81e38d", - "reference": "689ba22063bf46def385da8695ba7a921e81e38d", + "url": "https://api.github.com/repos/utopia-php/database/zipball/923260ac25780b3e60c255a5529da4cc440ae174", + "reference": "923260ac25780b3e60c255a5529da4cc440ae174", "shasum": "" }, "require": { @@ -1760,7 +1760,38 @@ "Utopia\\Database\\": "src/Database" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Tests\\E2E\\": "tests/e2e", + "Tests\\Unit\\": "tests/unit" + } + }, + "scripts": { + "build": [ + "Composer\\Config::disableProcessTimeout", + "docker compose build" + ], + "start": [ + "Composer\\Config::disableProcessTimeout", + "docker compose up -d" + ], + "test": [ + "Composer\\Config::disableProcessTimeout", + "docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml" + ], + "lint": [ + "./vendor/bin/pint --test" + ], + "format": [ + "./vendor/bin/pint" + ], + "check": [ + "./vendor/bin/phpstan analyse --level 7 src tests --memory-limit 512M" + ], + "coverage": [ + "./vendor/bin/coverage-check ./tmp/clover.xml 90" + ] + }, "license": [ "MIT" ], @@ -1773,10 +1804,10 @@ "utopia" ], "support": { - "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.5" + "source": "https://github.com/utopia-php/database/tree/feat-findone-update-0.53.x", + "issues": "https://github.com/utopia-php/database/issues" }, - "time": "2024-09-24T08:43:10+00:00" + "time": "2024-10-07T02:09:46+00:00" }, { "name": "utopia-php/domains", @@ -2175,16 +2206,16 @@ }, { "name": "utopia-php/migration", - "version": "0.6.4", + "version": "0.6.5", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "e43ef283f1386084e11d1ffe093fb6c6d7a6ce6c" + "reference": "7b2d40d526b82e9b92a17ea681b8103222e3c86a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/e43ef283f1386084e11d1ffe093fb6c6d7a6ce6c", - "reference": "e43ef283f1386084e11d1ffe093fb6c6d7a6ce6c", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/7b2d40d526b82e9b92a17ea681b8103222e3c86a", + "reference": "7b2d40d526b82e9b92a17ea681b8103222e3c86a", "shasum": "" }, "require": { @@ -2225,9 +2256,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.6.4" + "source": "https://github.com/utopia-php/migration/tree/0.6.5" }, - "time": "2024-10-02T15:16:36+00:00" + "time": "2024-10-07T08:54:05+00:00" }, { "name": "utopia-php/mongo", @@ -3002,16 +3033,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.39.22", + "version": "0.39.23", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "bdbb1607527550e67283ff0533522d1410c2c0df" + "reference": "0acceabb7593c9c07c5db85a84a5ebac60896763" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/bdbb1607527550e67283ff0533522d1410c2c0df", - "reference": "bdbb1607527550e67283ff0533522d1410c2c0df", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/0acceabb7593c9c07c5db85a84a5ebac60896763", + "reference": "0acceabb7593c9c07c5db85a84a5ebac60896763", "shasum": "" }, "require": { @@ -3047,9 +3078,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.39.22" + "source": "https://github.com/appwrite/sdk-generator/tree/0.39.23" }, - "time": "2024-10-01T16:16:26+00:00" + "time": "2024-10-08T00:38:57+00:00" }, { "name": "doctrine/annotations", @@ -7002,9 +7033,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-feat-findone-update-0.53.x", + "alias": "0.53.6", + "alias_normalized": "0.53.6.0" + } + ], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 40b8af0671a0620bbc4898d57fa92d801ed1c8d6 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 31 Oct 2024 17:13:23 +0900 Subject: [PATCH 6/8] Further cleanup code now findOne returns empty doc --- app/controllers/api/account.php | 28 +++++++++---------- app/controllers/api/functions.php | 2 +- app/controllers/api/migrations.php | 12 ++++---- app/controllers/api/projects.php | 20 ++++++------- app/controllers/api/proxy.php | 2 +- app/controllers/api/teams.php | 2 +- app/controllers/api/users.php | 4 +-- app/controllers/api/vcs.php | 10 +++---- app/init.php | 3 -- .../Platform/Workers/Certificates.php | 4 +-- src/Appwrite/Platform/Workers/Messaging.php | 2 +- 11 files changed, 42 insertions(+), 47 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 82c2f092ee..f764c4c3ea 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -332,7 +332,7 @@ App::post('/v1/account') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ } @@ -1405,7 +1405,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('provider', [$provider]), Query::equal('providerUid', [$oauth2ID]), ]); - if ($session !== false && !$session->isEmpty()) { + if (!$session->isEmpty()) { $user->setAttributes($dbForProject->getDocument('users', $session->getAttribute('userId'))->getArrayCopy()); } } @@ -1423,7 +1423,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $userWithEmail = $dbForProject->findOne('users', [ Query::equal('email', [$email]), ]); - if ($userWithEmail !== false && !$userWithEmail->isEmpty()) { + if (!$userWithEmail->isEmpty()) { $user->setAttributes($userWithEmail->getArrayCopy()); } @@ -1434,7 +1434,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('providerUid', [$oauth2ID]), ]); - if ($identity !== false && !$identity->isEmpty()) { + if (!$identity->isEmpty()) { $user = $dbForProject->getDocument('users', $identity->getAttribute('userId')); } } @@ -1454,7 +1454,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ } @@ -1517,7 +1517,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Query::equal('provider', [$provider]), Query::equal('providerUid', [$oauth2ID]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { // Before creating the identity, check if the email is already associated with another user $userId = $user->getId(); @@ -1801,7 +1801,7 @@ App::post('/v1/account/tokens/magic-url') $isAppUser = Auth::isAppUser($roles); $result = $dbForProject->findOne('users', [Query::equal('email', [$email])]); - if ($result !== false && !$result->isEmpty()) { + if (!$result->isEmpty()) { $user->setAttributes($result->getArrayCopy()); } else { $limit = $project->getAttribute('auths', [])['limit'] ?? 0; @@ -1818,7 +1818,7 @@ App::post('/v1/account/tokens/magic-url') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } @@ -2042,7 +2042,7 @@ App::post('/v1/account/tokens/email') $isAppUser = Auth::isAppUser($roles); $result = $dbForProject->findOne('users', [Query::equal('email', [$email])]); - if ($result !== false && !$result->isEmpty()) { + if (!$result->isEmpty()) { $user->setAttributes($result->getArrayCopy()); } else { $limit = $project->getAttribute('auths', [])['limit'] ?? 0; @@ -2059,7 +2059,7 @@ App::post('/v1/account/tokens/email') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ } @@ -2329,7 +2329,7 @@ App::post('/v1/account/tokens/phone') $isAppUser = Auth::isAppUser($roles); $result = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); - if ($result !== false && !$result->isEmpty()) { + if (!$result->isEmpty()) { $user->setAttributes($result->getArrayCopy()); } else { $limit = $project->getAttribute('auths', [])['limit'] ?? 0; @@ -2753,7 +2753,7 @@ App::patch('/v1/account/email') Query::equal('providerEmail', [$email]), Query::notEqual('userInternalId', $user->getInternalId()), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ } @@ -2774,7 +2774,7 @@ App::patch('/v1/account/email') Query::equal('identifier', [$email]), ])); - if ($target instanceof Document && !$target->isEmpty()) { + if (!$target->isEmpty()) { throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); } @@ -2840,7 +2840,7 @@ App::patch('/v1/account/phone') Query::equal('identifier', [$phone]), ])); - if ($target instanceof Document && !$target->isEmpty()) { + if (!$target->isEmpty()) { throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); } diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 290eed8651..8815611021 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -2324,7 +2324,7 @@ App::delete('/v1/functions/:functionId/executions/:executionId') Query::equal('active', [true]), ]); - if ($schedule && !$schedule->isEmpty()) { + if (!$schedule->isEmpty()) { $schedule ->setAttribute('resourceUpdatedAt', DateTime::now()) ->setAttribute('active', false); diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index a4880cef86..bebb6ebaea 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -121,7 +121,7 @@ App::post('/v1/migrations/firebase/oauth') Query::equal('provider', ['firebase']), Query::equal('userInternalId', [$user->getInternalId()]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); } @@ -576,7 +576,7 @@ App::get('/v1/migrations/firebase/report/oauth') Query::equal('userInternalId', [$user->getInternalId()]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); } @@ -751,13 +751,13 @@ App::get('/v1/migrations/firebase/redirect') Query::equal('providerEmail', [$email]), ]); - if ($identity !== false && !$identity->isEmpty()) { + if (!$identity->isEmpty()) { if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } } - if ($identity !== false && !$identity->isEmpty()) { + if (!$identity->isEmpty()) { $identity = $identity ->setAttribute('providerAccessToken', $accessToken) ->setAttribute('providerRefreshToken', $refreshToken) @@ -820,7 +820,7 @@ App::get('/v1/migrations/firebase/projects') Query::equal('userInternalId', [$user->getInternalId()]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); } @@ -900,7 +900,7 @@ App::get('/v1/migrations/firebase/deauthorize') Query::equal('userInternalId', [$user->getInternalId()]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Not authenticated with Firebase'); //TODO: Replace with USER_IDENTITY_NOT_FOUND } diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 3bfa416bd8..5705e7576b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1060,7 +1060,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($webhook === false || $webhook->isEmpty()) { + if ($webhook->isEmpty()) { throw new Exception(Exception::WEBHOOK_NOT_FOUND); } @@ -1103,7 +1103,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($webhook === false || $webhook->isEmpty()) { + if ($webhook->isEmpty()) { throw new Exception(Exception::WEBHOOK_NOT_FOUND); } @@ -1153,7 +1153,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($webhook === false || $webhook->isEmpty()) { + if ($webhook->isEmpty()) { throw new Exception(Exception::WEBHOOK_NOT_FOUND); } @@ -1191,7 +1191,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($webhook === false || $webhook->isEmpty()) { + if ($webhook->isEmpty()) { throw new Exception(Exception::WEBHOOK_NOT_FOUND); } @@ -1313,7 +1313,7 @@ App::get('/v1/projects/:projectId/keys/:keyId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($key === false || $key->isEmpty()) { + if ($key->isEmpty()) { throw new Exception(Exception::KEY_NOT_FOUND); } @@ -1350,7 +1350,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($key === false || $key->isEmpty()) { + if ($key->isEmpty()) { throw new Exception(Exception::KEY_NOT_FOUND); } @@ -1392,7 +1392,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($key === false || $key->isEmpty()) { + if ($key->isEmpty()) { throw new Exception(Exception::KEY_NOT_FOUND); } @@ -1550,7 +1550,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($platform === false || $platform->isEmpty()) { + if ($platform->isEmpty()) { throw new Exception(Exception::PLATFORM_NOT_FOUND); } @@ -1587,7 +1587,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($platform === false || $platform->isEmpty()) { + if ($platform->isEmpty()) { throw new Exception(Exception::PLATFORM_NOT_FOUND); } @@ -1631,7 +1631,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') Query::equal('projectInternalId', [$project->getInternalId()]), ]); - if ($platform === false || $platform->isEmpty()) { + if ($platform->isEmpty()) { throw new Exception(Exception::PLATFORM_NOT_FOUND); } diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 984a9fb974..02a3ec8e9d 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -64,7 +64,7 @@ App::post('/v1/proxy/rules') Query::equal('domain', [$domain]), ]); - if ($document && !$document->isEmpty()) { + if (!$document->isEmpty()) { if ($document->getAttribute('projectId') === $project->getId()) { $resourceType = $document->getAttribute('resourceType'); $resourceId = $document->getAttribute('resourceId'); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 3d0955ad2b..0b97be0e55 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -492,7 +492,7 @@ App::post('/v1/teams/:teamId/memberships') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index af45c6c3ab..314e298d6b 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -64,7 +64,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } } @@ -1232,7 +1232,7 @@ App::patch('/v1/users/:userId/email') Query::equal('providerEmail', [$email]), Query::notEqual('userInternalId', $user->getInternalId()), ]); - if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { + if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index e79eb67936..bbb1d9c3f8 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -110,7 +110,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId Query::orderDesc('$createdAt'), ])); - if ($latestComment !== false && !$latestComment->isEmpty()) { + if (!$latestComment->isEmpty()) { $latestCommentId = $latestComment->getAttribute('providerCommentId', ''); $comment = new Comment(); $comment->parseComment($github->getComment($owner, $repositoryName, $latestCommentId)); @@ -371,13 +371,11 @@ App::get('/v1/vcs/github/callback') $identity = $dbForConsole->findOne('identities', [ Query::equal('providerEmail', [$email]), ]); - if ($identity !== false && !$identity->isEmpty()) { + if (!$identity->isEmpty()) { if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } - } - if ($identity !== false && !$identity->isEmpty()) { $identity = $identity ->setAttribute('providerAccessToken', $accessToken) ->setAttribute('providerRefreshToken', $refreshToken) @@ -418,7 +416,7 @@ App::get('/v1/vcs/github/callback') Query::equal('projectInternalId', [$projectInternalId]) ]); - if ($installation === false || $installation->isEmpty()) { + if ($installation->isEmpty()) { $teamId = $project->getAttribute('teamId', ''); $installation = new Document([ @@ -726,7 +724,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories') Query::equal('provider', ['github']), Query::equal('userInternalId', [$user->getInternalId()]), ]); - if ($identity === false || $identity->isEmpty()) { + if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); } diff --git a/app/init.php b/app/init.php index a558c0fa25..e962c58b67 100644 --- a/app/init.php +++ b/app/init.php @@ -1812,9 +1812,6 @@ App::setResource('team', function (Document $project, Database $dbForConsole, Ap ]); }); - if (!$team) { - $team = new Document([]); - } return $team; }, ['project', 'dbForConsole', 'utopia', 'request']); diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index f25a85fb10..a14f164295 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -216,7 +216,7 @@ class Certificates extends Action { // Check if update or insert required $certificateDocument = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain])]); - if (!empty($certificateDocument) && !$certificateDocument->isEmpty()) { + if (!$certificateDocument->isEmpty()) { // Merge new data with current data $certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy())); $certificate = $dbForConsole->updateDocument('certificates', $certificate->getId(), $certificate); @@ -482,7 +482,7 @@ class Certificates extends Action Query::equal('domain', [$domain]), ]); - if ($rule !== false && !$rule->isEmpty()) { + if (!$rule->isEmpty()) { $rule->setAttribute('certificateId', $certificateId); $rule->setAttribute('status', $success ? 'verified' : 'unverified'); $dbForConsole->updateDocument('rules', $rule->getId(), $rule); diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 510fec0431..58f6265ff4 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -178,7 +178,7 @@ class Messaging extends Action Query::equal('type', [$providerType]), ]); - if ($default === false || $default->isEmpty()) { + if ($default->isEmpty()) { $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([ 'status' => MessageStatus::FAILED, 'deliveryErrors' => ['No enabled provider found.'] From 2f64620cb5184248462fdcf2efcdcd51c4d31cd8 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 31 Oct 2024 17:27:13 +0900 Subject: [PATCH 7/8] Use actual package --- composer.json | 2 +- composer.lock | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 7e03dd0836..2f3cda37d1 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-feat-findone-update-0.53.x as 0.53.8", + "utopia-php/database": "0.53.9", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 8f02830a90..8baec7be7f 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": "5fd3d4a7e4dd44e74bda31a0087c40d1", + "content-hash": "a2e4cb8d1757400071b4545cfbd3f805", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "dev-feat-findone-update-0.53.x", + "version": "0.53.9", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "b6ddececdcca36920d6791311affb0b0856a178b" + "reference": "19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/b6ddececdcca36920d6791311affb0b0856a178b", - "reference": "b6ddececdcca36920d6791311affb0b0856a178b", + "url": "https://api.github.com/repos/utopia-php/database/zipball/19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3", + "reference": "19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3", "shasum": "" }, "require": { @@ -1804,10 +1804,10 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/database/tree/feat-findone-update-0.53.x", + "source": "https://github.com/utopia-php/database/tree/0.53.9", "issues": "https://github.com/utopia-php/database/issues" }, - "time": "2024-10-31T07:55:39+00:00" + "time": "2024-10-31T08:18:52+00:00" }, { "name": "utopia-php/domains", @@ -7034,18 +7034,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-feat-findone-update-0.53.x", - "alias": "0.53.8", - "alias_normalized": "0.53.8.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { From a30dd72b0f654c32067ed51227dba0e2c90bc4f4 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 31 Oct 2024 18:06:07 +0900 Subject: [PATCH 8/8] Remove unnecessary repo in composer.json --- composer.json | 8 +------- composer.lock | 39 ++++----------------------------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 2f3cda37d1..04a6af2415 100644 --- a/composer.json +++ b/composer.json @@ -97,11 +97,5 @@ "platform": { "php": "8.3" } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/utopia-php/database.git" - } - ] + } } diff --git a/composer.lock b/composer.lock index 8baec7be7f..314ec397f5 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": "a2e4cb8d1757400071b4545cfbd3f805", + "content-hash": "1529d4abfe0432b2d9c838705220ed4a", "packages": [ { "name": "adhocore/jwt", @@ -1760,38 +1760,7 @@ "Utopia\\Database\\": "src/Database" } }, - "autoload-dev": { - "psr-4": { - "Tests\\E2E\\": "tests/e2e", - "Tests\\Unit\\": "tests/unit" - } - }, - "scripts": { - "build": [ - "Composer\\Config::disableProcessTimeout", - "docker compose build" - ], - "start": [ - "Composer\\Config::disableProcessTimeout", - "docker compose up -d" - ], - "test": [ - "Composer\\Config::disableProcessTimeout", - "docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml" - ], - "lint": [ - "./vendor/bin/pint --test" - ], - "format": [ - "./vendor/bin/pint" - ], - "check": [ - "./vendor/bin/phpstan analyse --level 7 src tests --memory-limit 512M" - ], - "coverage": [ - "./vendor/bin/coverage-check ./tmp/clover.xml 90" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1804,8 +1773,8 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/database/tree/0.53.9", - "issues": "https://github.com/utopia-php/database/issues" + "issues": "https://github.com/utopia-php/database/issues", + "source": "https://github.com/utopia-php/database/tree/0.53.9" }, "time": "2024-10-31T08:18:52+00:00" },