From 9b0a2fdc73407c3d6fec2c7cef240212e1153869 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Tue, 3 Oct 2023 15:10:09 -0400 Subject: [PATCH 01/19] Fix docs links CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1341c9f133..90c6497281 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,7 +84,7 @@ $ git push origin [name_of_your_new_branch] To set up a working **development environment**, just fork the project git repository and install the backend and frontend dependencies using the proper package manager and create run the docker-compose stack. -> If you just want to install Appwrite for day-to-day use and not as a contributor, you can reference the [installation guide](https://github.com/appwrite/appwrite#installation), the [getting started guide](https://appwrite.io/docs/getting-started-for-web), or the main [README](README.md) file. +> If you just want to install Appwrite for day-to-day use and not as a contributor, you can reference the [installation guide](https://github.com/appwrite/appwrite#installation), the [getting started guide](https://appwrite.io/docs/quick-starts), or the main [README](README.md) file. ```bash git clone git@github.com:[YOUR_FORK_HERE]/appwrite.git @@ -451,7 +451,7 @@ From time to time, our team will add tutorials that will help contributors find - [Adding Support for a New OAuth2 Provider](./docs/tutorials/add-oauth2-provider.md) - [Appwrite Environment Variables](./docs/tutorials/add-environment-variable.md) -- [Running in Production](https://appwrite.io/docs/production) +- [Running in Production](https://appwrite.io/docs/advanced/self-hosting/production) - [Adding Storage Adapter](./docs/tutorials/add-storage-adapter.md) ## Other Ways to Help From 31466c44d8c8ab4087380b2e26371e980a977707 Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 8 Oct 2023 16:44:14 +0300 Subject: [PATCH 02/19] update projects database --- app/controllers/api/projects.php | 10 ++++++++++ composer.lock | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c0ce213789..a59803972d 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -100,6 +100,7 @@ App::post('/v1/projects') $databases = Config::getParam('pools-database', []); + /** * Extract db from list while backing */ @@ -167,6 +168,15 @@ App::post('/v1/projects') throw new Exception(Exception::PROJECT_ALREADY_EXISTS); } + /** + * Update database with self-managed db every $mod projects + */ + $mod = 2; + if ($index = array_search('db_fra1_sm1_0', $databases) && $project->getInternalId() % $mod === 0) { + $project->setAttribute('database', $databases[$index]); + $dbForConsole->updateDocument('projects', $project); + } + $dbForProject = new Database($pools->get($database)->pop()->getResource(), $cache); $dbForProject->setNamespace("_{$project->getInternalId()}"); $dbForProject->create(); diff --git a/composer.lock b/composer.lock index 288a17101f..546c1000d0 100644 --- a/composer.lock +++ b/composer.lock @@ -1050,16 +1050,16 @@ }, { "name": "matomo/device-detector", - "version": "6.1.5", + "version": "6.1.6", "source": { "type": "git", "url": "https://github.com/matomo-org/device-detector.git", - "reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4" + "reference": "5cbea85106e561c7138d03603eb6e05128480409" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/40ca2990dba2c1719e5c62168e822e0b86c167d4", - "reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4", + "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/5cbea85106e561c7138d03603eb6e05128480409", + "reference": "5cbea85106e561c7138d03603eb6e05128480409", "shasum": "" }, "require": { @@ -1115,7 +1115,7 @@ "source": "https://github.com/matomo-org/matomo", "wiki": "https://dev.matomo.org/" }, - "time": "2023-08-17T16:17:41+00:00" + "time": "2023-10-02T10:01:54+00:00" }, { "name": "mongodb/mongodb", @@ -6017,5 +6017,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.2.0" } From 00d2a5ffcd4491dcb9cb32acd6761b5c660f6125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Sun, 22 Oct 2023 18:33:15 +0000 Subject: [PATCH 03/19] chore: update create projects endpoints --- app/controllers/api/projects.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 10669af3d8..eb657c116d 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -92,12 +92,12 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups['database_db_fra1_v14x_02'] = ['from' => '03:00', 'to' => '04:00']; - $backups['database_db_fra1_v14x_03'] = ['from' => '00:00', 'to' => '01:00']; - $backups['database_db_fra1_v14x_04'] = ['from' => '00:00', 'to' => '01:00']; - $backups['database_db_fra1_v14x_05'] = ['from' => '00:00', 'to' => '01:00']; - $backups['database_db_fra1_v14x_06'] = ['from' => '00:00', 'to' => '01:00']; - $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '01:00']; + $backups['database_db_fra1_v14x_02'] = ['from' => '03:00', 'to' => '05:00']; + $backups['database_db_fra1_v14x_03'] = ['from' => '00:00', 'to' => '02:00']; + $backups['database_db_fra1_v14x_04'] = ['from' => '00:00', 'to' => '02:00']; + $backups['database_db_fra1_v14x_05'] = ['from' => '00:00', 'to' => '02:00']; + $backups['database_db_fra1_v14x_06'] = ['from' => '00:00', 'to' => '02:00']; + $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '02:00']; $databases = Config::getParam('pools-database', []); @@ -174,8 +174,8 @@ App::post('/v1/projects') /** * Update database with self-managed db every $mod projects */ - $mod = 2; - if ($index = array_search('db_fra1_sm1_0', $databases) && $project->getInternalId() % $mod === 0) { + $mod = 20; + if ($index = array_search('database_db_fra1_self_hosted_0_0', $databases) && $project->getInternalId() % $mod === 0) { $project->setAttribute('database', $databases[$index]); $dbForConsole->updateDocument('projects', $project); } From 0d5127d90b2b3da9909a6f980bd4980ad0185905 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 00:08:55 +0300 Subject: [PATCH 04/19] fix mod condition --- app/controllers/api/projects.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index eb657c116d..6f2f4f40e3 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -175,7 +175,8 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - if ($index = array_search('database_db_fra1_self_hosted_0_0', $databases) && $project->getInternalId() % $mod === 0) { + $index = array_search('database_db_fra1_self_hosted_0_0', $databases); + if ($index !== false && ($project->getInternalId() % $mod === 0)) { $project->setAttribute('database', $databases[$index]); $dbForConsole->updateDocument('projects', $project); } From ac231914d4048688100f028003ba9626dd3c10ec Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 00:55:57 +0300 Subject: [PATCH 05/19] fix mod condition --- app/controllers/api/projects.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6f2f4f40e3..a4a96b49a5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -100,7 +100,10 @@ App::post('/v1/projects') $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '02:00']; $databases = Config::getParam('pools-database', []); - + $index = array_search('database_db_fra1_self_hosted_0_0', $databases); + if ($index !== false) { + unset($databases[$index]); + } /** * Remove databases from the list that are currently undergoing an backup @@ -124,7 +127,7 @@ App::post('/v1/projects') $databaseOverride = App::getEnv('_APP_DATABASE_OVERRIDE', null); $index = array_search($databaseOverride, $databases); - if ($index) { + if ($index !== false) { $database = $databases[$index]; } else { $database = $databases[array_rand($databases)]; @@ -175,9 +178,9 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - $index = array_search('database_db_fra1_self_hosted_0_0', $databases); - if ($index !== false && ($project->getInternalId() % $mod === 0)) { - $project->setAttribute('database', $databases[$index]); + if ($project->getInternalId() % $mod === 0) { + $database = 'database_db_fra1_self_hosted_0_0'; + $project->setAttribute('database', $database); $dbForConsole->updateDocument('projects', $project); } From a841734d50ee0681ec217eb2a511116de5009a64 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 01:05:10 +0300 Subject: [PATCH 06/19] fix mod condition --- app/controllers/api/projects.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a4a96b49a5..43fbd43b74 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -100,7 +100,8 @@ App::post('/v1/projects') $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '02:00']; $databases = Config::getParam('pools-database', []); - $index = array_search('database_db_fra1_self_hosted_0_0', $databases); + $databaseSelfHosted = 'database_db_fra1_self_hosted_0_0'; + $index = array_search($databaseSelfHosted, $databases); if ($index !== false) { unset($databases[$index]); } @@ -178,9 +179,9 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - if ($project->getInternalId() % $mod === 0) { - $database = 'database_db_fra1_self_hosted_0_0'; - $project->setAttribute('database', $database); + $index = in_array($databaseSelfHosted, $databases); + if ($project->getInternalId() % $mod === 0 && $index !== false) { + $project->setAttribute('database', $databaseSelfHosted); $dbForConsole->updateDocument('projects', $project); } From b09a254d3c3424af9b2ef5cc92c6f5b8e7e2845b Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 10:46:15 +0300 Subject: [PATCH 07/19] fix mod condition --- app/controllers/api/projects.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 43fbd43b74..b1ab7d5743 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -101,9 +101,9 @@ App::post('/v1/projects') $databases = Config::getParam('pools-database', []); $databaseSelfHosted = 'database_db_fra1_self_hosted_0_0'; - $index = array_search($databaseSelfHosted, $databases); - if ($index !== false) { - unset($databases[$index]); + $SelfHostedIndex = array_search($databaseSelfHosted, $databases); + if ($SelfHostedIndex !== false) { + unset($databases[$SelfHostedIndex]); } /** @@ -179,8 +179,7 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - $index = in_array($databaseSelfHosted, $databases); - if ($project->getInternalId() % $mod === 0 && $index !== false) { + if ($project->getInternalId() % $mod === 0 && $SelfHostedIndex !== false) { $project->setAttribute('database', $databaseSelfHosted); $dbForConsole->updateDocument('projects', $project); } From 2ef8490691117254154c71a365ac58cf84df422d Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 11:22:28 +0300 Subject: [PATCH 08/19] fix mod condition --- app/controllers/api/projects.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index b1ab7d5743..dd152683a1 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -101,9 +101,9 @@ App::post('/v1/projects') $databases = Config::getParam('pools-database', []); $databaseSelfHosted = 'database_db_fra1_self_hosted_0_0'; - $SelfHostedIndex = array_search($databaseSelfHosted, $databases); - if ($SelfHostedIndex !== false) { - unset($databases[$SelfHostedIndex]); + $selfHostedIndex = array_search($databaseSelfHosted, $databases); + if ($selfHostedIndex !== false) { + unset($databases[$selfHostedIndex]); } /** @@ -179,7 +179,7 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - if ($project->getInternalId() % $mod === 0 && $SelfHostedIndex !== false) { + if ($project->getInternalId() % $mod === 0 && $selfHostedIndex !== false) { $project->setAttribute('database', $databaseSelfHosted); $dbForConsole->updateDocument('projects', $project); } From 808f682fa721c09540f2976f256e7729f187ff2e Mon Sep 17 00:00:00 2001 From: Shimon Newman Date: Mon, 23 Oct 2023 11:25:31 +0300 Subject: [PATCH 09/19] Update app/controllers/api/projects.php Co-authored-by: Christy Jacob --- app/controllers/api/projects.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index dd152683a1..4ae6d7b6cb 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -180,6 +180,7 @@ App::post('/v1/projects') */ $mod = 20; if ($project->getInternalId() % $mod === 0 && $selfHostedIndex !== false) { + $database = $databaseSelfHosted; $project->setAttribute('database', $databaseSelfHosted); $dbForConsole->updateDocument('projects', $project); } From 3dee8d6ecd3dbaea289f2a55bb404769ce0ce380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Mon, 23 Oct 2023 08:34:57 +0000 Subject: [PATCH 10/19] fix: update incorrect method call --- app/controllers/api/projects.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 4ae6d7b6cb..fe7759a6df 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -180,9 +180,9 @@ App::post('/v1/projects') */ $mod = 20; if ($project->getInternalId() % $mod === 0 && $selfHostedIndex !== false) { - $database = $databaseSelfHosted; - $project->setAttribute('database', $databaseSelfHosted); - $dbForConsole->updateDocument('projects', $project); + $database = $databaseSelfHosted; + $project->setAttribute('database', $database); + $dbForConsole->updateDocument('projects', $project->getId(), $project); } $dbForProject = new Database($pools->get($database)->pop()->getResource(), $cache); From 0411f9f5305117d1a1ea464e71b91c9d59d0743d Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 16:33:26 +0300 Subject: [PATCH 11/19] fix function-worker body param typo --- src/Appwrite/Platform/Workers/Functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 6b7b5efe03..7a6cfe115f 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -77,7 +77,7 @@ class Functions extends Action $type = $payload['type'] ?? ''; $events = $payload['events'] ?? []; - $data = $payload['data'] ?? ''; + $data = $payload['body'] ?? ''; $eventData = $payload['payload'] ?? ''; $project = new Document($payload['project'] ?? []); $function = new Document($payload['function'] ?? []); From 3addf76a2a1b5a7986fe744e155a2fe4bdca3bc5 Mon Sep 17 00:00:00 2001 From: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:53:40 +0000 Subject: [PATCH 12/19] Bump appwrite version to 1.4.7 --- README-CN.md | 6 +++--- README.md | 6 +++--- app/init.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README-CN.md b/README-CN.md index 1328ef5cf4..1df799f7ef 100644 --- a/README-CN.md +++ b/README-CN.md @@ -66,7 +66,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` ### Windows @@ -78,7 +78,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` #### PowerShell @@ -88,7 +88,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index 40a4248d59..b4980d0e61 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` ### Windows @@ -88,7 +88,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` #### PowerShell @@ -98,7 +98,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.6 + appwrite/appwrite:1.4.7 ``` Once the Docker installation is complete, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after completing the installation. diff --git a/app/init.php b/app/init.php index 16eceb1eaf..86e4790a30 100644 --- a/app/init.php +++ b/app/init.php @@ -110,7 +110,7 @@ const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours const APP_USER_ACCCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 514; -const APP_VERSION_STABLE = '1.4.6'; +const APP_VERSION_STABLE = '1.4.7'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 15098793a9..964aef66e5 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -71,6 +71,7 @@ abstract class Migration '1.4.4' => 'V19', '1.4.5' => 'V19', '1.4.6' => 'V19', + '1.4.7' => 'V19', ]; /** From 84ea81f56d34a4fb2fc046120cfb342173ee0ec6 Mon Sep 17 00:00:00 2001 From: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:54:33 +0000 Subject: [PATCH 13/19] Add 1.4.7 to CHANGES.md --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 33b41d35fa..ac405184df 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# Version 1.4.7 + +## Fixes +- Fix missing body in async function execution in [#6988](https://github.com/appwrite/appwrite/pull/6988) + # Version 1.4.6 ## Changes From fbcbd0d430a59eaf3bfbe13548dc1229ee9be362 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 24 Oct 2023 14:32:22 +0200 Subject: [PATCH 14/19] feat: realtime error handling --- app/config/errors.php | 17 +++++++++++ app/realtime.php | 51 +++++++++++++++++-------------- src/Appwrite/Extend/Exception.php | 9 ++++-- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 159c806175..78c633ee7a 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -732,4 +732,21 @@ return [ 'description' => 'Migration is already in progress. You can check the status of the migration in your Appwrite Console\'s "Settings" > "Migrations".', 'code' => 409, ], + + /** Realtime */ + Exception::REALTIME_MESSAGE_FORMAT_INVALID => [ + 'name' => Exception::REALTIME_MESSAGE_FORMAT_INVALID, + 'description' => 'Message format is not valid.', + 'code' => 1003, + ], + Exception::REALTIME_POLICY_VIOLATION => [ + 'name' => Exception::REALTIME_POLICY_VIOLATION, + 'description' => 'Policy violation.', + 'code' => 1008, + ], + Exception::REALTIME_TOO_MANY_MESSAGES => [ + 'name' => Exception::REALTIME_TOO_MANY_MESSAGES, + 'description' => 'Too many messages.', + 'code' => 1013, + ], ]; diff --git a/app/realtime.php b/app/realtime.php index 25b0532b42..42fa43f575 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -1,8 +1,10 @@ get('logger'); - if ($logger) { + if ($logger && !$error instanceof Exception) { $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); $log = new Log(); $log->setNamespace("realtime"); - $log->setServer(\gethostname()); + $log->setServer(gethostname()); $log->setVersion($version); $log->setType(Log::TYPE_ERROR); $log->setMessage($error->getMessage()); @@ -182,7 +186,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume $statsDocument = Authorization::skip(fn () => $database->createDocument('realtime', $document)); break; - } catch (\Throwable $th) { + } catch (Throwable) { Console::warning("Collection not ready. Retrying connection ({$attempts})..."); sleep(DATABASE_RECONNECT_SLEEP); } @@ -210,7 +214,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume ->setAttribute('value', json_encode($payload)); Authorization::skip(fn () => $database->updateDocument('realtime', $statsDocument->getId(), $statsDocument)); - } catch (\Throwable $th) { + } catch (Throwable $th) { call_user_func($logError, $th, "updateWorkerDocument"); } finally { $register->get('pools')->reclaim(); @@ -362,7 +366,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $stats->incr($event['project'], 'messages', $num); } }); - } catch (\Throwable $th) { + } catch (Throwable $th) { call_user_func($logError, $th, "pubSubConnection"); Console::error('Pub/sub error: ' . $th->getMessage()); @@ -389,19 +393,19 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, App::setResource('response', fn() => $response); try { - /** @var \Utopia\Database\Document $project */ + /** @var Document $project */ $project = $app->getResource('project'); /* * Project Check */ if (empty($project->getId())) { - throw new Exception('Missing or unknown project ID', 1008); + throw new Exception(Exception::REALTIME_POLICY_VIOLATION, 'Missing or unknown project ID'); } $dbForProject = getProjectDB($project); - $console = $app->getResource('console'); /** @var \Utopia\Database\Document $console */ - $user = $app->getResource('user'); /** @var \Utopia\Database\Document $user */ + $console = $app->getResource('console'); /** @var Document $console */ + $user = $app->getResource('user'); /** @var Document $user */ /* * Abuse Check @@ -416,7 +420,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $abuse = new Abuse($timeLimit); if (App::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled' && $abuse->check()) { - throw new Exception('Too many requests', 1013); + throw new Exception(Exception::REALTIME_TOO_MANY_MESSAGES, 'Too many requests'); } /* @@ -425,10 +429,10 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, * Skip this check for non-web platforms which are not required to send an origin header. */ $origin = $request->getOrigin(); - $originValidator = new Origin(\array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', []))); + $originValidator = new Origin(array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', []))); if (!$originValidator->isValid($origin) && $project->getId() !== 'console') { - throw new Exception($originValidator->getDescription(), 1008); + throw new Exception(Exception::REALTIME_POLICY_VIOLATION, $originValidator->getDescription()); } $roles = Auth::getRoles($user); @@ -439,7 +443,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, * Channels Check */ if (empty($channels)) { - throw new Exception('Missing channels', 1008); + throw new Exception(Exception::REALTIME_POLICY_VIOLATION, 'Missing channels'); } $realtime->subscribe($project->getId(), $connection, $roles, $channels); @@ -460,7 +464,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, ]); $stats->incr($project->getId(), 'connections'); $stats->incr($project->getId(), 'connectionsTotal'); - } catch (\Throwable $th) { + } catch (Throwable $th) { call_user_func($logError, $th, "initServer"); $response = [ @@ -486,7 +490,6 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $server->onMessage(function (int $connection, string $message) use ($server, $register, $realtime, $containerId) { try { - $app = new App('UTC'); $response = new Response(new SwooleResponse()); $projectId = $realtime->connections[$connection]['projectId']; $database = getConsoleDB(); @@ -494,6 +497,8 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re if ($projectId !== 'console') { $project = Authorization::skip(fn() => $database->getDocument('projects', $projectId)); $database = getProjectDB($project); + } else { + $project = null; } /* @@ -510,22 +515,22 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re $abuse = new Abuse($timeLimit); if ($abuse->check() && App::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled') { - throw new Exception('Too many messages', 1013); + throw new Exception(Exception::REALTIME_TOO_MANY_MESSAGES, 'Too many messages.'); } $message = json_decode($message, true); if (is_null($message) || (!array_key_exists('type', $message) && !array_key_exists('data', $message))) { - throw new Exception('Message format is not valid.', 1003); + throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Message format is not valid.'); } switch ($message['type']) { - /** + /** * This type is used to authenticate. */ case 'authentication': if (!array_key_exists('session', $message['data'])) { - throw new Exception('Payload is not valid.', 1003); + throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Payload is not valid.'); } $session = Auth::decodeSession($message['data']['session']); @@ -540,7 +545,7 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re || !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret, $authDuration) // Validate user has valid login token ) { // cookie not valid - throw new Exception('Session is not valid.', 1003); + throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Session is not valid.'); } $roles = Auth::getRoles($user); @@ -560,9 +565,9 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re break; default: - throw new Exception('Message type is not valid.', 1003); + throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Message type is not valid.'); } - } catch (\Throwable $th) { + } catch (Throwable $th) { $response = [ 'type' => 'error', 'data' => [ diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index c7ff2e73c0..dc56932cde 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -225,8 +225,13 @@ class Exception extends \Exception public const MIGRATION_ALREADY_EXISTS = 'migration_already_exists'; public const MIGRATION_IN_PROGRESS = 'migration_in_progress'; - protected $type = ''; - protected $errors = []; + /** Realtime */ + public const REALTIME_MESSAGE_FORMAT_INVALID = 'realtime_message_format_invalid'; + public const REALTIME_TOO_MANY_MESSAGES = 'realtime_too_many_messages'; + public const REALTIME_POLICY_VIOLATION = 'realtime_policy_violation'; + + protected string $type = ''; + protected array $errors = []; public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null) { From 8db372a7d3b14406719d697ac4131c7de3669296 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 25 Oct 2023 13:55:32 +1300 Subject: [PATCH 15/19] Update dependencies --- composer.json | 2 +- composer.lock | 115 +++++++++++--------------------------------------- 2 files changed, 25 insertions(+), 92 deletions(-) diff --git a/composer.json b/composer.json index f73fc02584..ef10f99a17 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "utopia-php/preloader": "0.2.*", "utopia-php/queue": "0.5.*", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "0.17.*", + "utopia-php/storage": "0.18.*", "utopia-php/swoole": "0.5.*", "utopia-php/vcs": "0.5.*", "utopia-php/websocket": "0.1.*", diff --git a/composer.lock b/composer.lock index 7823864bd6..a9121a6dcf 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": "6ff937a260c3e0c09de9eb5e073d830d", + "content-hash": "06c2610579f319495ea7d2d28f42d376", "packages": [ { "name": "adhocore/jwt", @@ -851,72 +851,6 @@ }, "time": "2021-10-08T21:21:46+00:00" }, - { - "name": "laravel/pint", - "version": "v1.2.1", - "source": { - "type": "git", - "url": "https://github.com/laravel/pint.git", - "reference": "e60e2112ee779ce60f253695b273d1646a17d6f1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/e60e2112ee779ce60f253695b273d1646a17d6f1", - "reference": "e60e2112ee779ce60f253695b273d1646a17d6f1", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "ext-tokenizer": "*", - "ext-xml": "*", - "php": "^8.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", - "illuminate/view": "^9.32.0", - "laravel-zero/framework": "^9.2.0", - "mockery/mockery": "^1.5.1", - "nunomaduro/larastan": "^2.2.0", - "nunomaduro/termwind": "^1.14.0", - "pestphp/pest": "^1.22.1" - }, - "bin": [ - "builds/pint" - ], - "type": "project", - "autoload": { - "psr-4": { - "App\\": "app/", - "Database\\Seeders\\": "database/seeders/", - "Database\\Factories\\": "database/factories/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "An opinionated code formatter for PHP.", - "homepage": "https://laravel.com", - "keywords": [ - "format", - "formatter", - "lint", - "linter", - "php" - ], - "support": { - "issues": "https://github.com/laravel/pint/issues", - "source": "https://github.com/laravel/pint" - }, - "time": "2022-11-29T16:25:20+00:00" - }, { "name": "league/csv", "version": "9.7.1", @@ -1972,16 +1906,16 @@ }, { "name": "utopia-php/database", - "version": "0.44.2", + "version": "0.44.3", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "591cadbc2c622a3304aae9a16ebfdbe75ef33a06" + "reference": "b2d403c25a77506e03db5736335b0cae52bcc18a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/591cadbc2c622a3304aae9a16ebfdbe75ef33a06", - "reference": "591cadbc2c622a3304aae9a16ebfdbe75ef33a06", + "url": "https://api.github.com/repos/utopia-php/database/zipball/b2d403c25a77506e03db5736335b0cae52bcc18a", + "reference": "b2d403c25a77506e03db5736335b0cae52bcc18a", "shasum": "" }, "require": { @@ -1994,7 +1928,7 @@ }, "require-dev": { "fakerphp/faker": "^1.14", - "laravel/pint": "1.4.*", + "laravel/pint": "1.13.*", "pcov/clobber": "^2.0", "phpstan/phpstan": "1.10.*", "phpunit/phpunit": "^9.4", @@ -2022,9 +1956,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.44.2" + "source": "https://github.com/utopia-php/database/tree/0.44.3" }, - "time": "2023-10-19T07:39:00+00:00" + "time": "2023-10-24T10:13:48+00:00" }, { "name": "utopia-php/domains", @@ -2808,16 +2742,16 @@ }, { "name": "utopia-php/storage", - "version": "0.17.0", + "version": "0.18.1", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "efec5376c02d3d8330f1beb1469e6d6e313e21ee" + "reference": "983e6dee137012f9f57f126d3c79aab54e4e8824" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/efec5376c02d3d8330f1beb1469e6d6e313e21ee", - "reference": "efec5376c02d3d8330f1beb1469e6d6e313e21ee", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/983e6dee137012f9f57f126d3c79aab54e4e8824", + "reference": "983e6dee137012f9f57f126d3c79aab54e4e8824", "shasum": "" }, "require": { @@ -2857,9 +2791,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.17.0" + "source": "https://github.com/utopia-php/storage/tree/0.18.1" }, - "time": "2023-08-21T11:28:36+00:00" + "time": "2023-10-24T14:44:19+00:00" }, { "name": "utopia-php/swoole", @@ -2914,26 +2848,25 @@ }, { "name": "utopia-php/system", - "version": "0.7.1", + "version": "0.7.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "01bf0d283aded0ee0a7a6e5ff540acf64270ab27" + "reference": "4593d4d334b0c15879c4744a826e0362924c5d66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/01bf0d283aded0ee0a7a6e5ff540acf64270ab27", - "reference": "01bf0d283aded0ee0a7a6e5ff540acf64270ab27", + "url": "https://api.github.com/repos/utopia-php/system/zipball/4593d4d334b0c15879c4744a826e0362924c5d66", + "reference": "4593d4d334b0c15879c4744a826e0362924c5d66", "shasum": "" }, "require": { - "laravel/pint": "1.2.*", "php": ">=8.0.0" }, "require-dev": { - "phpunit/phpunit": "^9.3", - "squizlabs/php_codesniffer": "^3.6", - "vimeo/psalm": "4.0.1" + "laravel/pint": "1.13.*", + "phpstan/phpstan": "1.10.*", + "phpunit/phpunit": "9.6.*" }, "type": "library", "autoload": { @@ -2965,9 +2898,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.7.1" + "source": "https://github.com/utopia-php/system/tree/0.7.2" }, - "time": "2023-08-30T09:14:37+00:00" + "time": "2023-10-20T01:39:17+00:00" }, { "name": "utopia-php/vcs", @@ -5889,5 +5822,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } From 17de0d1ea702cada2bb959c360a4f8dcd6270675 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:55:46 +0530 Subject: [PATCH 16/19] Updated the error code for unsupported protocol --- app/config/errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 78c633ee7a..28fb69d118 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -86,7 +86,7 @@ return [ Exception::GENERAL_PROTOCOL_UNSUPPORTED => [ 'name' => Exception::GENERAL_PROTOCOL_UNSUPPORTED, 'description' => 'The request cannot be fulfilled with the current protocol. Please check the value of the _APP_OPTIONS_FORCE_HTTPS environment variable.', - 'code' => 500, + 'code' => 426, ], Exception::GENERAL_CODES_DISABLED => [ 'name' => Exception::GENERAL_CODES_DISABLED, From f9a3ae142187a8d1e11a7e11b41d1026b024d175 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 25 Oct 2023 13:35:14 +0200 Subject: [PATCH 17/19] chore: bump console version --- .gitmodules | 2 +- app/console | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 754fa9f80e..6570e2a620 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "app/console"] path = app/console url = https://github.com/appwrite/console - branch = 3.2.3 + branch = 3.2.4 diff --git a/app/console b/app/console index e965738987..fe835e5032 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit e9657389879c8d76a9b3a0d3486c1d86f43c3bb9 +Subproject commit fe835e50328ed80f67c66d2d449c0f7b51ade544 From 404ad8653d9a152e666d5ce2b2c3bc7a407693f1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 25 Oct 2023 19:23:55 +0200 Subject: [PATCH 18/19] fix: worker permissions reset --- app/worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/worker.php b/app/worker.php index 8aa52ab931..f1f19e3cca 100644 --- a/app/worker.php +++ b/app/worker.php @@ -33,7 +33,7 @@ use Utopia\Logger\Logger; use Utopia\Pools\Group; use Utopia\Queue\Connection; -Authorization::disable(); +Authorization::setDefaultStatus(false); Runtime::enableCoroutine(SWOOLE_HOOK_ALL); From 995c404f352ff40a9fbf89de3820b8ebc465482b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 26 Oct 2023 21:24:30 +1300 Subject: [PATCH 19/19] Update db --- app/worker.php | 3 +-- composer.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/worker.php b/app/worker.php index f1f19e3cca..32a8b9804e 100644 --- a/app/worker.php +++ b/app/worker.php @@ -33,10 +33,9 @@ use Utopia\Logger\Logger; use Utopia\Pools\Group; use Utopia\Queue\Connection; -Authorization::setDefaultStatus(false); +Authorization::disable(); Runtime::enableCoroutine(SWOOLE_HOOK_ALL); - Server::setResource('register', fn () => $register); Server::setResource('dbForConsole', function (Cache $cache, Registry $register) { diff --git a/composer.lock b/composer.lock index a9121a6dcf..cb467be2de 100644 --- a/composer.lock +++ b/composer.lock @@ -1906,16 +1906,16 @@ }, { "name": "utopia-php/database", - "version": "0.44.3", + "version": "0.44.4", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "b2d403c25a77506e03db5736335b0cae52bcc18a" + "reference": "b0c3fd8ecfedc3646d7780f2d6b38955a66baf48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/b2d403c25a77506e03db5736335b0cae52bcc18a", - "reference": "b2d403c25a77506e03db5736335b0cae52bcc18a", + "url": "https://api.github.com/repos/utopia-php/database/zipball/b0c3fd8ecfedc3646d7780f2d6b38955a66baf48", + "reference": "b0c3fd8ecfedc3646d7780f2d6b38955a66baf48", "shasum": "" }, "require": { @@ -1956,9 +1956,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.44.3" + "source": "https://github.com/utopia-php/database/tree/0.44.4" }, - "time": "2023-10-24T10:13:48+00:00" + "time": "2023-10-26T07:08:12+00:00" }, { "name": "utopia-php/domains",