From 185b2060768d4199dfc8628601784a2c6455940a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Oct 2022 11:23:20 +0000 Subject: [PATCH 1/8] fix moved constant --- src/Appwrite/Auth/Auth.php | 9 +++++---- tests/unit/Auth/AuthTest.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index dbe74af0d2..adde25a7a3 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -14,6 +14,7 @@ use Utopia\Database\Document; use Utopia\Database\DateTime; use Utopia\Database\Role; use Utopia\Database\Validator\Authorization; +use Utopia\Database\Validator\Roles; class Auth { @@ -427,11 +428,11 @@ class Auth $phoneVerified = $user->getAttribute('phoneVerification', false); if ($emailVerified || $phoneVerified) { - $roles[] = Role::user($user->getId(), Database::DIMENSION_VERIFIED)->toString(); - $roles[] = Role::users(Database::DIMENSION_VERIFIED)->toString(); + $roles[] = Role::user($user->getId(), Roles::DIMENSION_VERIFIED)->toString(); + $roles[] = Role::users(Roles::DIMENSION_VERIFIED)->toString(); } else { - $roles[] = Role::user($user->getId(), Database::DIMENSION_UNVERIFIED)->toString(); - $roles[] = Role::users(Database::DIMENSION_UNVERIFIED)->toString(); + $roles[] = Role::user($user->getId(), Roles::DIMENSION_UNVERIFIED)->toString(); + $roles[] = Role::users(Roles::DIMENSION_UNVERIFIED)->toString(); } } else { return [Role::guests()->toString()]; diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 43a2bef8ed..951039b98c 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -379,8 +379,8 @@ class AuthTest extends TestCase $this->assertCount(11, $roles); $this->assertContains(Role::users()->toString(), $roles); $this->assertContains(Role::user(ID::custom('123'))->toString(), $roles); - $this->assertContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles); @@ -394,15 +394,15 @@ class AuthTest extends TestCase $user['phoneVerification'] = false; $roles = Auth::getRoles($user); - $this->assertContains(Role::users(Database::DIMENSION_UNVERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_UNVERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_UNVERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_UNVERIFIED)->toString(), $roles); // Enable single verification type $user['emailVerification'] = true; $roles = Auth::getRoles($user); - $this->assertContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); } public function testPrivilegedUserRoles(): void @@ -438,8 +438,8 @@ class AuthTest extends TestCase $this->assertCount(7, $roles); $this->assertNotContains(Role::users()->toString(), $roles); $this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles); - $this->assertNotContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertNotContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertNotContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertNotContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles); From be3743e227aed00d1209018c9fc0c83a749ae55c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Oct 2022 11:24:37 +0000 Subject: [PATCH 2/8] fix renamed function --- app/controllers/api/databases.php | 2 +- app/init.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5278abae3e..19264454e0 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1574,7 +1574,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') Query::equal('databaseInternalId', [$db->getInternalId()]) ], 61); - $limit = 64 - MariaDB::getNumberOfDefaultIndexes(); + $limit = 64 - MariaDB::getCountOfDefaultIndexes(); if ($count >= $limit) { throw new Exception(Exception::INDEX_LIMIT_EXCEEDED, 'Index limit exceeded'); diff --git a/app/init.php b/app/init.php index a19492394b..054721d439 100644 --- a/app/init.php +++ b/app/init.php @@ -282,7 +282,7 @@ Database::addFilter( ->find('attributes', [ Query::equal('collectionInternalId', [$document->getInternalId()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), - Query::limit($database->getAttributeLimit()), + Query::limit($database->getLimitForAttributes()), ]); } ); From e2555e244870eee77848fd97f410f920dfd8bbdb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Oct 2022 11:25:22 +0000 Subject: [PATCH 3/8] fix metadata creation --- app/http.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/app/http.php b/app/http.php index afda7053b4..e35626db6d 100644 --- a/app/http.php +++ b/app/http.php @@ -91,20 +91,9 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { /** @var array $collections */ $collections = Config::getParam('collections', []); - if (!$dbForConsole->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'))) { - $redis->flushAll(); - - Console::success('[Setup] - Creating database: appwrite...'); - - $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); - } - - try { - Console::success('[Setup] - Creating metadata table: appwrite...'); - $dbForConsole->createMetadata(); - } catch (\Throwable $th) { - Console::success('[Setup] - Skip: metadata table already exists'); - } + $redis->flushAll(); + Console::success('[Setup] - Creating database: appwrite...'); + $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); if ($dbForConsole->getCollection(Audit::COLLECTION)->isEmpty()) { $audit = new Audit($dbForConsole); From 51cbc653afb21b63eaea2c9f7b22159bd62de793 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Oct 2022 11:26:33 +0000 Subject: [PATCH 4/8] use metadata constant --- src/Appwrite/Resque/Worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index 40adc3e52e..dd7cebd084 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -229,7 +229,7 @@ abstract class Worker throw new \Exception("Project does not exist: {$projectId}"); } - if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), '_metadata')) { + if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), Database::METADATA)) { throw new \Exception('Console project not ready'); } From f27ccf4212606c737772f833cf27212281151ed8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Oct 2022 11:40:59 +0000 Subject: [PATCH 5/8] upgrade database version --- composer.json | 6 +++--- composer.lock | 50 ++++++++++++++++++++++---------------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 973aec8539..47317ed5e2 100644 --- a/composer.json +++ b/composer.json @@ -45,13 +45,13 @@ "appwrite/php-runtimes": "0.11.*", "utopia-php/framework": "0.21.*", "utopia-php/logger": "0.3.*", - "utopia-php/abuse": "0.13.*", + "utopia-php/abuse": "0.14.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.14.*", + "utopia-php/audit": "0.15.*", "utopia-php/cache": "0.6.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.25.*", + "utopia-php/database": "0.26.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", diff --git a/composer.lock b/composer.lock index cd2040eb1a..b4bbda3cef 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": "568151395a8877f87d9bdce048adc2dc", + "content-hash": "08fdd139ad1285b02c4b4e555679e7de", "packages": [ { "name": "adhocore/jwt", @@ -1741,23 +1741,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.13.1", + "version": "0.14.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "4c1b8fe742f17158c59550cdfd9074a94bf474ac" + "reference": "1a5da248e74c1bfc39bc440fa949de6935acceeb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/4c1b8fe742f17158c59550cdfd9074a94bf474ac", - "reference": "4c1b8fe742f17158c59550cdfd9074a94bf474ac", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/1a5da248e74c1bfc39bc440fa949de6935acceeb", + "reference": "1a5da248e74c1bfc39bc440fa949de6935acceeb", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.25.*" + "utopia-php/database": "0.26.*" }, "require-dev": { "phpunit/phpunit": "^9.4", @@ -1789,9 +1789,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.13.1" + "source": "https://github.com/utopia-php/abuse/tree/0.14.0" }, - "time": "2022-09-07T16:02:58+00:00" + "time": "2022-10-14T11:26:39+00:00" }, { "name": "utopia-php/analytics", @@ -1850,22 +1850,22 @@ }, { "name": "utopia-php/audit", - "version": "0.14.1", + "version": "0.15.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "b011224ed9bfef7e5c849938e65619af28f7cf41" + "reference": "937ffd13e7a5ac9ad220b329247569ef2a4881d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/b011224ed9bfef7e5c849938e65619af28f7cf41", - "reference": "b011224ed9bfef7e5c849938e65619af28f7cf41", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/937ffd13e7a5ac9ad220b329247569ef2a4881d9", + "reference": "937ffd13e7a5ac9ad220b329247569ef2a4881d9", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.25.*" + "utopia-php/database": "0.26.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -1881,12 +1881,6 @@ "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - } - ], "description": "A simple audit library to manage application users logs", "keywords": [ "Audit", @@ -1897,9 +1891,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.14.1" + "source": "https://github.com/utopia-php/audit/tree/0.15.0" }, - "time": "2022-09-07T16:03:16+00:00" + "time": "2022-10-14T11:39:18+00:00" }, { "name": "utopia-php/cache", @@ -2060,16 +2054,16 @@ }, { "name": "utopia-php/database", - "version": "0.25.5", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "6d1c1d46d66553154975a3e8e72d30b5bd2413d9" + "reference": "d172af2541137c83a86d066f82f48914b5a3a610" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/6d1c1d46d66553154975a3e8e72d30b5bd2413d9", - "reference": "6d1c1d46d66553154975a3e8e72d30b5bd2413d9", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d172af2541137c83a86d066f82f48914b5a3a610", + "reference": "d172af2541137c83a86d066f82f48914b5a3a610", "shasum": "" }, "require": { @@ -2118,9 +2112,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.25.5" + "source": "https://github.com/utopia-php/database/tree/0.26.0" }, - "time": "2022-09-30T15:01:32+00:00" + "time": "2022-10-03T17:12:01+00:00" }, { "name": "utopia-php/domains", @@ -5384,5 +5378,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } From c635846dba41ef17198069afdc2d1f43b003dcf0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 16 Oct 2022 01:47:38 +0000 Subject: [PATCH 6/8] fix missing import --- tests/unit/Auth/AuthTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 951039b98c..822b612db8 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -10,6 +10,7 @@ use Utopia\Database\Role; use Utopia\Database\Validator\Authorization; use PHPUnit\Framework\TestCase; use Utopia\Database\Database; +use Utopia\Database\Validator\Roles; class AuthTest extends TestCase { From 00973d4a145a0f86fd66aaa46d6859419a2ae666 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 16 Oct 2022 05:58:25 +0000 Subject: [PATCH 7/8] add try catch --- app/http.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/http.php b/app/http.php index e35626db6d..87a2fccd29 100644 --- a/app/http.php +++ b/app/http.php @@ -91,9 +91,13 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { /** @var array $collections */ $collections = Config::getParam('collections', []); - $redis->flushAll(); - Console::success('[Setup] - Creating database: appwrite...'); - $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); + try { + $redis->flushAll(); + Console::success('[Setup] - Creating database: appwrite...'); + $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); + } catch (\Exception $e) { + Console::error('Failed to create database: ' . $e->getMessage()); + } if ($dbForConsole->getCollection(Audit::COLLECTION)->isEmpty()) { $audit = new Audit($dbForConsole); From 90e9e5e7fd8a0f19d3c72eeafe05ba1e65e1f036 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 16 Oct 2022 11:49:12 +0545 Subject: [PATCH 8/8] Update app/http.php Co-authored-by: Eldad A. Fux --- app/http.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/http.php b/app/http.php index 87a2fccd29..fe0778bb15 100644 --- a/app/http.php +++ b/app/http.php @@ -96,7 +96,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { Console::success('[Setup] - Creating database: appwrite...'); $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); } catch (\Exception $e) { - Console::error('Failed to create database: ' . $e->getMessage()); + Console::success('[Setup] - Skip: metadata table already exists'); } if ($dbForConsole->getCollection(Audit::COLLECTION)->isEmpty()) {