Update Database lib, update instances where findOne is used to ensure we check document is empty.

This commit is contained in:
Bradley Schofield 2024-09-18 14:47:36 +09:00
parent de95bf677e
commit be3e3790c9
7 changed files with 36 additions and 36 deletions

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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',

View file

@ -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.*",

42
composer.lock generated
View file

@ -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",

View file

@ -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());
}