From e8754111b971067b97f33dcd6411f64263704f12 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 10 Jul 2021 21:06:46 +0545 Subject: [PATCH 01/13] install and enable yasd if testing is true --- Dockerfile | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b450b6a6d9..3987f998d5 100755 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,9 @@ RUN composer update --ignore-platform-reqs --optimize-autoloader \ FROM php:8.0-cli-alpine as step1 +ARG TESTING=false +ENV TESTING=$TESTING + ENV PHP_REDIS_VERSION=5.3.4 \ PHP_SWOOLE_VERSION=v4.6.7 \ PHP_IMAGICK_VERSION=3.5.0 \ @@ -75,11 +78,25 @@ RUN \ make && make install && \ cd ../.. +## Swoole Debugger setup +RUN if [ "$TESTING" == "true" ]; then \ + cd /tmp && \ + apk add boost-dev && \ + git clone --depth 1 https://github.com/swoole/yasd && \ + cd yasd && \ + phpize && \ + ./configure && \ + make && make install && \ + cd ..;\ + fi + FROM php:8.0-cli-alpine as final LABEL maintainer="team@appwrite.io" ARG VERSION=dev +ARG TESTING=false +ENV TESTING=$TESTING ENV _APP_SERVER=swoole \ _APP_ENV=production \ @@ -160,10 +177,15 @@ RUN \ && apk del .deps \ && rm -rf /var/cache/apk/* +RUN \ + if [ "$TESTING" == "true" ]; then \ + apk add boost boost-dev; \ + fi + WORKDIR /usr/src/code COPY --from=step0 /usr/local/src/vendor /usr/src/code/vendor -COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ +COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/yasd.so* /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/imagick.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/yaml.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ @@ -218,7 +240,9 @@ RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini RUN echo extension=imagick.so >> /usr/local/etc/php/conf.d/imagick.ini RUN echo extension=yaml.so >> /usr/local/etc/php/conf.d/yaml.ini RUN echo extension=maxminddb.so >> /usr/local/etc/php/conf.d/maxminddb.ini +RUN if [ "$TESTING" == "true" ]; then printf 'zend_extension=yasd \nyasd.debug_mode=remote \nyasd.remote_host=192.168.1.64 \nyasd.remote_port=9005 \nyasd.log_level=0 \nyasd.breakpoints_file="yasd.log"' >> /usr/local/etc/php/conf.d/yasd.ini; fi +RUN if [ "$TESTING" == "true" ]; then echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/appwrite.ini; fi RUN echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.preload=/usr/src/code/app/preload.php" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/appwrite.ini From 5073c264b73f46666783db1a97b389ae0cc39fe8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 11 Jul 2021 15:49:31 +0545 Subject: [PATCH 02/13] modified entrypoint to support debugger --- docker-compose.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index fb8a8355f9..0117887fd2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -72,6 +72,13 @@ services: - redis # - clamav - influxdb + entrypoint: + - php + - -e + - app/http.php + - -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php + + environment: - _APP_ENV - _APP_LOCALE From 74b24dfe6917babd58bad0de9c9a60a3687c5afb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 11 Jul 2021 17:20:03 +0545 Subject: [PATCH 03/13] properly setup debugger for everyone and contribution guide --- .gitignore | 3 ++- CONTRIBUTING.md | 24 ++++++++++++++++++++++++ Dockerfile | 2 +- dev/yasd_init.php.stub | 4 ++++ docker-compose.yml | 3 +-- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 dev/yasd_init.php.stub diff --git a/.gitignore b/.gitignore index c7d23a9df8..33974acbe2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ .DS_Store .php_cs.cache debug/ -app/sdks \ No newline at end of file +app/sdks +dev/yasd_init.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e1d2cd3ec4..69d4e047c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -282,6 +282,30 @@ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 The Runtimes for all supported cloud functions (multicore builds) can be found at the [appwrite/php-runtimes](https://github.com/appwrite/php-runtimes) repository. +## Debug + +Appwrite uses [yasd](https://github.com/swoole/yasd) debugger, which is available by default in debug build of Appwrite. You can connect to the debugger using VS Code [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension or if you are in PHP Storm you don't need any plugin. Below are the settings required for remote debugger connection. + +Finally you need to create an init file. Duplicate **dev/yasd_init.php.stub** file and name it **dev/yasd_init.php** and there change the IP address to your development machine's IP. Without the proper IP address debugger wont connect. + +### VS Code Launch Configuration + +```json +{ + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9005, + "pathMappings": { + "/usr/src/code": "${workspaceRoot}" + }, +} +``` + +### PHPStorm Setup + +In settings, go to **Languages & Frameworks** > **PHP** > **Debug**, there under **Xdebug** set the debug port to **9005** and enable **can accept external connections** checkbox. + ## Tests To run all tests manually, use the Appwrite Docker CLI from your terminal: diff --git a/Dockerfile b/Dockerfile index 3987f998d5..15cbcd107b 100755 --- a/Dockerfile +++ b/Dockerfile @@ -240,7 +240,7 @@ RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini RUN echo extension=imagick.so >> /usr/local/etc/php/conf.d/imagick.ini RUN echo extension=yaml.so >> /usr/local/etc/php/conf.d/yaml.ini RUN echo extension=maxminddb.so >> /usr/local/etc/php/conf.d/maxminddb.ini -RUN if [ "$TESTING" == "true" ]; then printf 'zend_extension=yasd \nyasd.debug_mode=remote \nyasd.remote_host=192.168.1.64 \nyasd.remote_port=9005 \nyasd.log_level=0 \nyasd.breakpoints_file="yasd.log"' >> /usr/local/etc/php/conf.d/yasd.ini; fi +RUN if [ "$TESTING" == "true" ]; then printf "zend_extension=yasd \nyasd.debug_mode=remote \nyasd.init_file=/usr/local/dev/yasd_init.php \nyasd.remote_port=9005 \nyasd.log_level=-1" >> /usr/local/etc/php/conf.d/yasd.ini; fi RUN if [ "$TESTING" == "true" ]; then echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/appwrite.ini; fi RUN echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/appwrite.ini diff --git a/dev/yasd_init.php.stub b/dev/yasd_init.php.stub new file mode 100644 index 0000000000..a7d977fbf7 --- /dev/null +++ b/dev/yasd_init.php.stub @@ -0,0 +1,4 @@ + Date: Sun, 11 Jul 2021 18:10:39 +0545 Subject: [PATCH 04/13] update with DEBUG build args --- CONTRIBUTING.md | 4 ++-- Dockerfile | 16 ++++++++-------- docker-compose.yml | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69d4e047c4..552ff05612 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -284,9 +284,9 @@ The Runtimes for all supported cloud functions (multicore builds) can be found a ## Debug -Appwrite uses [yasd](https://github.com/swoole/yasd) debugger, which is available by default in debug build of Appwrite. You can connect to the debugger using VS Code [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension or if you are in PHP Storm you don't need any plugin. Below are the settings required for remote debugger connection. +Appwrite uses [yasd](https://github.com/swoole/yasd) debugger, which can be made available during build of Appwrite. You can connect to the debugger using VS Code [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension or if you are in PHP Storm you don't need any plugin. Below are the settings required for remote debugger connection. -Finally you need to create an init file. Duplicate **dev/yasd_init.php.stub** file and name it **dev/yasd_init.php** and there change the IP address to your development machine's IP. Without the proper IP address debugger wont connect. +First, you need to create an init file. Duplicate **dev/yasd_init.php.stub** file and name it **dev/yasd_init.php** and there change the IP address to your development machine's IP. Without the proper IP address debugger wont connect. And you also need to set **DEBUG** build arg in **appwrite** service in **docker-compose.yml** file. ### VS Code Launch Configuration diff --git a/Dockerfile b/Dockerfile index 15cbcd107b..d15dbf508e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,8 @@ RUN composer update --ignore-platform-reqs --optimize-autoloader \ FROM php:8.0-cli-alpine as step1 -ARG TESTING=false -ENV TESTING=$TESTING +ARG DEBUG=false +ENV DEBUG=$DEBUG ENV PHP_REDIS_VERSION=5.3.4 \ PHP_SWOOLE_VERSION=v4.6.7 \ @@ -79,7 +79,7 @@ RUN \ cd ../.. ## Swoole Debugger setup -RUN if [ "$TESTING" == "true" ]; then \ +RUN if [ "$DEBUG" == "true" ]; then \ cd /tmp && \ apk add boost-dev && \ git clone --depth 1 https://github.com/swoole/yasd && \ @@ -95,8 +95,8 @@ FROM php:8.0-cli-alpine as final LABEL maintainer="team@appwrite.io" ARG VERSION=dev -ARG TESTING=false -ENV TESTING=$TESTING +ARG DEBUG=false +ENV DEBUG=$DEBUG ENV _APP_SERVER=swoole \ _APP_ENV=production \ @@ -178,7 +178,7 @@ RUN \ && rm -rf /var/cache/apk/* RUN \ - if [ "$TESTING" == "true" ]; then \ + if [ "$DEBUG" == "true" ]; then \ apk add boost boost-dev; \ fi @@ -240,9 +240,9 @@ RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini RUN echo extension=imagick.so >> /usr/local/etc/php/conf.d/imagick.ini RUN echo extension=yaml.so >> /usr/local/etc/php/conf.d/yaml.ini RUN echo extension=maxminddb.so >> /usr/local/etc/php/conf.d/maxminddb.ini -RUN if [ "$TESTING" == "true" ]; then printf "zend_extension=yasd \nyasd.debug_mode=remote \nyasd.init_file=/usr/local/dev/yasd_init.php \nyasd.remote_port=9005 \nyasd.log_level=-1" >> /usr/local/etc/php/conf.d/yasd.ini; fi +RUN if [ "$DEBUG" == "true" ]; then printf "zend_extension=yasd \nyasd.debug_mode=remote \nyasd.init_file=/usr/local/dev/yasd_init.php \nyasd.remote_port=9005 \nyasd.log_level=-1" >> /usr/local/etc/php/conf.d/yasd.ini; fi -RUN if [ "$TESTING" == "true" ]; then echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/appwrite.ini; fi +RUN if [ "$DEBUG" == "true" ]; then echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/appwrite.ini; fi RUN echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.preload=/usr/src/code/app/preload.php" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/appwrite.ini diff --git a/docker-compose.yml b/docker-compose.yml index 4845e827e1..1037cf8557 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,7 @@ services: build: context: . args: + - DEBUG=false - TESTING=true - VERSION=dev ports: From 18d4a0def0e6812e6c14e698ab50334cb518537f Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 11:51:58 +0200 Subject: [PATCH 05/13] fix(app): remove app resource and replace with utopia --- app/controllers/api/account.php | 8 ++++---- app/controllers/api/health.php | 16 ++++++++-------- app/controllers/api/users.php | 8 ++++---- app/http.php | 4 ---- composer.lock | 20 +++++++++----------- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 850f42af58..37ab46166d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -918,16 +918,16 @@ App::get('/v1/account/logs') ->inject('user') ->inject('locale') ->inject('geodb') - ->inject('app') - ->action(function ($response, $project, $user, $locale, $geodb, $app) { + ->inject('utopia') + ->action(function ($response, $project, $user, $locale, $geodb, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ - /** @var Utopia\App $app */ + /** @var Utopia\App $utopia */ - $adapter = new AuditAdapter($app->getResource('db')); + $adapter = new AuditAdapter($utopia->getResource('db')); $adapter->setNamespace('app_'.$project->getId()); $audit = new Audit($adapter); diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index a161b2bdea..cbccb8f59c 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -42,11 +42,11 @@ App::get('/v1/health/db') ->label('sdk.method', 'getDB') ->label('sdk.description', '/docs/references/health/get-db.md') ->inject('response') - ->inject('app') - ->action(function ($response, $app) { + ->inject('utopia') + ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\App $app */ - $app->getResource('db'); + /** @var Utopia\App $utopia */ + $utopia->getResource('db'); $response->json(['status' => 'OK']); }); @@ -60,11 +60,11 @@ App::get('/v1/health/cache') ->label('sdk.method', 'getCache') ->label('sdk.description', '/docs/references/health/get-cache.md') ->inject('response') - ->inject('app') - ->action(function ($response, $app) { + ->inject('utopia') + ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\App $register */ - $app->getResource('cache'); + /** @var Utopia\App $utopia */ + $utopia->getResource('cache'); $response->json(['status' => 'OK']); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index a11c65edc5..e73a0a2f74 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -236,14 +236,14 @@ App::get('/v1/users/:userId/logs') ->inject('projectDB') ->inject('locale') ->inject('geodb') - ->inject('app') - ->action(function ($userId, $response, $project, $projectDB, $locale, $geodb, $app) { + ->inject('utopia') + ->action(function ($userId, $response, $project, $projectDB, $locale, $geodb, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ - /** @var Utopia\App $app */ + /** @var Utopia\App $utopia */ $user = $projectDB->getDocument($userId); @@ -251,7 +251,7 @@ App::get('/v1/users/:userId/logs') throw new Exception('User not found', 404); } - $adapter = new AuditAdapter($app->getResource('db')); + $adapter = new AuditAdapter($utopia->getResource('db')); $adapter->setNamespace('app_'.$project->getId()); $audit = new Audit($adapter); diff --git a/app/http.php b/app/http.php index 6b216da802..baf069324d 100644 --- a/app/http.php +++ b/app/http.php @@ -87,10 +87,6 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo App::setResource('cache', function () use (&$redis) { return $redis; }); - - App::setResource('app', function() use (&$app) { - return $app; - }); try { Authorization::cleanRoles(); diff --git a/composer.lock b/composer.lock index 4bb236099e..fba3b66cee 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": "7983e9fe8946a99fbf818b79ff202486", + "content-hash": "e24aacead283e33130051470bb4312e6", "packages": [ { "name": "adhocore/jwt", @@ -2403,16 +2403,16 @@ }, { "name": "appwrite/sdk-generator", - "version": "dev-feat-kotlin-java-docs", + "version": "0.12.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "966d464728b41a8c449e99d7df4bd4ddca591a25" + "reference": "ca8e34f091b3a66f94a8972cb94b0b8e1161dada" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/966d464728b41a8c449e99d7df4bd4ddca591a25", - "reference": "966d464728b41a8c449e99d7df4bd4ddca591a25", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/ca8e34f091b3a66f94a8972cb94b0b8e1161dada", + "reference": "ca8e34f091b3a66f94a8972cb94b0b8e1161dada", "shasum": "" }, "require": { @@ -2446,9 +2446,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/feat-kotlin-java-docs" + "source": "https://github.com/appwrite/sdk-generator/tree/0.12.0" }, - "time": "2021-07-06T09:26:45+00:00" + "time": "2021-07-06T16:20:51+00:00" }, { "name": "composer/package-versions-deprecated", @@ -6066,9 +6066,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "appwrite/sdk-generator": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -6090,5 +6088,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.0.0" } From df24011d8b8366a193baf8d40f7bbd1465205f53 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 12:04:00 +0200 Subject: [PATCH 06/13] fix(http): reset pdo connection if broken --- app/http.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/http.php b/app/http.php index 6b216da802..1329814d9c 100644 --- a/app/http.php +++ b/app/http.php @@ -98,11 +98,20 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $app->run($request, $response); } catch (\Throwable $th) { - Console::error('[Error] Type: '.get_class($th)); + $type = get_class($th); + + Console::error('[Error] Type: '.$type); Console::error('[Error] Message: '.$th->getMessage()); Console::error('[Error] File: '.$th->getFile()); Console::error('[Error] Line: '.$th->getLine()); + /** + * Reset Database connection if PDOException was thrown. + */ + if ($type === 'PDOException') { + $db = null; + } + if(App::isDevelopment()) { $swooleResponse->end('error: '.$th->getMessage()); } From 76af58c646ce8e0564afff66f1a78f9f24726ee1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 17:27:26 +0200 Subject: [PATCH 07/13] fix(pdo): throw on general to parent --- app/controllers/general.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index cd95b74a0c..2a0dd7021d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -304,6 +304,10 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) { /** @var Utopia\View $layout */ /** @var Appwrite\Database\Document $project */ + if (get_class($error) == 'PDOException') { + throw $error; + } + $route = $utopia->match($request); $template = ($route) ? $route->getLabel('error', null) : null; From cff517a2ab1ed2702db5c30022ca321e57869e0e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 18:15:21 +0200 Subject: [PATCH 08/13] adapt to review --- app/controllers/general.php | 2 +- app/http.php | 6 ++---- app/init.php | 5 ++--- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 2a0dd7021d..708e249853 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -304,7 +304,7 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) { /** @var Utopia\View $layout */ /** @var Appwrite\Database\Document $project */ - if (get_class($error) == 'PDOException') { + if ($error instanceof PDOException) { throw $error; } diff --git a/app/http.php b/app/http.php index 1329814d9c..28e2fd2805 100644 --- a/app/http.php +++ b/app/http.php @@ -98,9 +98,7 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $app->run($request, $response); } catch (\Throwable $th) { - $type = get_class($th); - - Console::error('[Error] Type: '.$type); + Console::error('[Error] Type: '.get_class($th)); Console::error('[Error] Message: '.$th->getMessage()); Console::error('[Error] File: '.$th->getFile()); Console::error('[Error] Line: '.$th->getLine()); @@ -108,7 +106,7 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo /** * Reset Database connection if PDOException was thrown. */ - if ($type === 'PDOException') { + if ($th instanceof PDOException) { $db = null; } diff --git a/app/init.php b/app/init.php index 302ce0f650..617322f9d6 100644 --- a/app/init.php +++ b/app/init.php @@ -164,12 +164,11 @@ $register->set('dbPool', function () { // Register DB connection $pool = new PDOPool((new PDOConfig()) ->withHost($dbHost) ->withPort($dbPort) - // ->withUnixSocket('/tmp/mysql.sock') ->withDbName($dbScheme) ->withCharset('utf8mb4') ->withUsername($dbUser) ->withPassword($dbPass) - ); + , 16); return $pool; }); @@ -189,7 +188,7 @@ $register->set('redisPool', function () { ->withPort($redisPort) ->withAuth($redisAuth) ->withDbIndex(0) - ); + , 16); return $pool; }); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 1acc350664..c110fcd4eb 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -342,7 +342,7 @@ services: - MYSQL_DATABASE=${_APP_DB_SCHEMA} - MYSQL_USER=${_APP_DB_USER} - MYSQL_PASSWORD=${_APP_DB_PASS} - command: 'mysqld --innodb-flush-method=fsync' + command: 'mysqld --innodb-flush-method=fsync --wait_timeout=86400' redis: image: redis:6.0-alpine3.12 diff --git a/docker-compose.yml b/docker-compose.yml index fb8a8355f9..621304f0a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -390,7 +390,7 @@ services: - MYSQL_DATABASE=${_APP_DB_SCHEMA} - MYSQL_USER=${_APP_DB_USER} - MYSQL_PASSWORD=${_APP_DB_PASS} - command: 'mysqld --innodb-flush-method=fsync' # add ' --query_cache_size=0' for DB tests + command: 'mysqld --innodb-flush-method=fsync --wait_timeout=86400' # add ' --query_cache_size=0' for DB tests # command: mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bu && mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bu # smtp: From 71941d8712d6606cdb78d9cf29add8812a707a93 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 18:21:12 +0200 Subject: [PATCH 09/13] feat(release): 0.9.1 --- CHANGES.md | 6 ++++++ README.md | 6 +++--- app/init.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5743bd42e5..c3b03d8acd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# Version 0.9.1 + +## Bugs + +- Fix PDO Connection timeout +- Remove unnecessary `app` resource and replace with `utopia` # Version 0.9.0 ## Features diff --git a/README.md b/README.md index 670121eca1..b32a84e277 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,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:0.9.0 + appwrite/appwrite:0.9.1 ``` ### Windows @@ -68,7 +68,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:0.9.0 + appwrite/appwrite:0.9.1 ``` #### PowerShell @@ -78,7 +78,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:0.9.0 + appwrite/appwrite:0.9.1 ``` Once the Docker installation completes, 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 installation completes. diff --git a/app/init.php b/app/init.php index 302ce0f650..ecf5d883f8 100644 --- a/app/init.php +++ b/app/init.php @@ -48,7 +48,7 @@ const APP_MODE_DEFAULT = 'default'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 12; const APP_CACHE_BUSTER = 149; -const APP_VERSION_STABLE = '0.9.0'; +const APP_VERSION_STABLE = '0.9.1'; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_CACHE = '/storage/cache'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 0d6995b064..bd03e7d339 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -39,6 +39,7 @@ abstract class Migration '0.7.0' => 'V06', '0.8.0' => 'V07', '0.9.0' => 'V08', + '0.9.1' => 'V08', ]; /** From 582f4e91f69cd8c9ee98717638ed52f28d55a7f3 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 12 Jul 2021 20:03:29 +0200 Subject: [PATCH 10/13] Update CHANGES.md --- CHANGES.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c3b03d8acd..94b56bc7a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,8 +2,10 @@ ## Bugs -- Fix PDO Connection timeout -- Remove unnecessary `app` resource and replace with `utopia` +- Fixed PDO Connection timeout (#1385) +- Removed unnecessary `app` resource and replace with `utopia` (#1384) +- Fixed missing quote in Functions Worker logs (#1375) + # Version 0.9.0 ## Features From 6e69b0a82bbf06042f18cfc493984de66b14a176 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 15 Jul 2021 18:12:18 +0200 Subject: [PATCH 11/13] fix(install): escape shell args --- app/tasks/install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/tasks/install.php b/app/tasks/install.php index 755e0b7e2c..483f5c5e04 100644 --- a/app/tasks/install.php +++ b/app/tasks/install.php @@ -129,7 +129,7 @@ $cli $httpsPort = Console::confirm('Choose your server HTTPS port: (default: '.$defaultHTTPSPort.')'); $httpsPort = ($httpsPort) ? $httpsPort : $defaultHTTPSPort; } - + $input = []; foreach($vars as $key => $var) { @@ -196,7 +196,7 @@ $cli foreach ($input as $key => $value) { if($value) { - $env .= $key.'='.$value.' '; + $env .= $key.'='.\escapeshellarg($value).' '; } } From cf3ffcdf32bdf4909d53e0de290bd3b9324fb1a4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 18 Jul 2021 16:19:50 +0545 Subject: [PATCH 12/13] update create membership doc --- docs/references/teams/create-team-membership.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/teams/create-team-membership.md b/docs/references/teams/create-team-membership.md index a920c260be..c6d81de484 100644 --- a/docs/references/teams/create-team-membership.md +++ b/docs/references/teams/create-team-membership.md @@ -1,5 +1,5 @@ -Use this endpoint to invite a new member to join your team. An email with a link to join the team will be sent to the new member email address if the member doesn't exist in the project it will be created automatically. +Use this endpoint to invite a new member to join your team. If initiated from Client SDK, an email with a link to join the team will be sent to the new member's email address if the member doesn't exist in the project it will be created automatically. If initiated from server side SDKs, new member will automatically be added to the team. -Use the 'URL' parameter to redirect the user from the invitation email back to your app. When the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow the user to accept the invitation to the team. +Use the 'URL' parameter to redirect the user from the invitation email back to your app. When the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow the user to accept the invitation to the team. While calling from side SDKs the redirect url can be empty string. Please note that in order to avoid a [Redirect Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URL's are the once from domains you have set when added your platforms in the console interface. \ No newline at end of file From c2f1389a568653fffdc385bbfce956ecea613421 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 19 Jul 2021 17:09:39 +0200 Subject: [PATCH 13/13] fix(jwt): correct session validation --- app/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index a139a4f841..6461f50acb 100644 --- a/app/init.php +++ b/app/init.php @@ -467,7 +467,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response $user = $projectDB->getDocument($jwtUserId); } - if (empty($user->search('$id', $jwtSessionId, $user->getAttribute('tokens')))) { // Match JWT to active token + if (empty($user->search('$id', $jwtSessionId, $user->getAttribute('sessions')))) { // Match JWT to active token $user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]); } }