From 943a3a7fddb87f1c7d61a7175b1e49cd7e17ac6b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 29 Oct 2024 17:20:15 +0900 Subject: [PATCH 01/30] Remove correct version of XDebug --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 13b018df0f..bc9fa75e6f 100755 --- a/Dockerfile +++ b/Dockerfile @@ -94,8 +94,8 @@ RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ # Enable Extensions RUN if [ "$DEBUG" == "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi RUN if [ "$DEBUG" == "true" ]; then mkdir -p /tmp/xdebug; fi -RUN if [ "$DEBUG" = "false" ]; then rm -rf /usr/src/code/dev; fi -RUN if [ "$DEBUG" = "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so; fi +RUN if [ "$DEBUG" == "false" ]; then rm -rf /usr/src/code/dev; fi +RUN if [ "$DEBUG" == "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so; fi EXPOSE 80 From ce36392a37a84208e7473641bd473c57beb3d2bd Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 6 Nov 2024 18:56:40 +0100 Subject: [PATCH 02/30] chore: bump framework --- composer.json | 2 +- composer.lock | 124 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 91 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index a04ca51d43..ac5d3a5412 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "utopia-php/database": "0.53.16", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "dev-feat-compression-0.33.x as 0.33.9", "utopia-php/fetch": "0.2.*", "utopia-php/image": "0.7.*", "utopia-php/locale": "0.4.*", diff --git a/composer.lock b/composer.lock index 6dce436601..69a4d41b71 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": "b358198535c1867eabed7c0f99135a57", + "content-hash": "c53d2cc50894be845538b4a23ea8be94", "packages": [ { "name": "adhocore/jwt", @@ -1671,6 +1671,52 @@ }, "time": "2024-10-04T13:55:36+00:00" }, + { + "name": "utopia-php/compression", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/compression.git", + "reference": "8c6d9bcb5b0972faa27e5bf70923c20403aaf25c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/8c6d9bcb5b0972faa27e5bf70923c20403aaf25c", + "reference": "8c6d9bcb5b0972faa27e5bf70923c20403aaf25c", + "shasum": "" + }, + "require": { + "php": ">=8.0" + }, + "require-dev": { + "laravel/pint": "1.2.*", + "phpunit/phpunit": "^9.3", + "vimeo/psalm": "4.0.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Compression\\": "src/Compression" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A simple Compression library to handle file compression", + "keywords": [ + "compression", + "framework", + "php", + "upf", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/compression/issues", + "source": "https://github.com/utopia-php/compression/tree/0.1.0" + }, + "time": "2024-10-23T10:17:46+00:00" + }, { "name": "utopia-php/config", "version": "0.2.2", @@ -1926,20 +1972,21 @@ }, { "name": "utopia-php/framework", - "version": "0.33.8", + "version": "dev-feat-compression-0.33.x", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5" + "reference": "a501a56f89097f2fd48c13eb2c632aafb1285cff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/a7f577540a25cb90896fef2b64767bf8d700f3c5", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5", + "url": "https://api.github.com/repos/utopia-php/http/zipball/a501a56f89097f2fd48c13eb2c632aafb1285cff", + "reference": "a501a56f89097f2fd48c13eb2c632aafb1285cff", "shasum": "" }, "require": { - "php": ">=8.0" + "php": ">=8.0", + "utopia-php/compression": "0.1.*" }, "require-dev": { "laravel/pint": "^1.2", @@ -1965,9 +2012,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.8" + "source": "https://github.com/utopia-php/http/tree/feat-compression-0.33.x" }, - "time": "2024-08-15T14:10:09+00:00" + "time": "2024-11-01T17:05:05+00:00" }, { "name": "utopia-php/image", @@ -2608,16 +2655,16 @@ }, { "name": "utopia-php/storage", - "version": "0.18.5", + "version": "0.18.6", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919" + "reference": "893ccf06e183f8ece2aed8dbf14d64d6ba036071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/7d355c5e3ccc8ecebc0266f8ddd30088a43be919", - "reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/893ccf06e183f8ece2aed8dbf14d64d6ba036071", + "reference": "893ccf06e183f8ece2aed8dbf14d64d6ba036071", "shasum": "" }, "require": { @@ -2657,9 +2704,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.18.5" + "source": "https://github.com/utopia-php/storage/tree/0.18.6" }, - "time": "2024-09-04T08:57:27+00:00" + "time": "2024-11-06T09:58:50+00:00" }, { "name": "utopia-php/swoole", @@ -4004,16 +4051,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.5.0", + "version": "5.5.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "54e10d44fc1a84e2598d26f70d4f6f1f233e228a" + "reference": "0c70d2c566e899666f367ab7b80986beb3581e6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/54e10d44fc1a84e2598d26f70d4f6f1f233e228a", - "reference": "54e10d44fc1a84e2598d26f70d4f6f1f233e228a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/0c70d2c566e899666f367ab7b80986beb3581e6f", + "reference": "0c70d2c566e899666f367ab7b80986beb3581e6f", "shasum": "" }, "require": { @@ -4062,9 +4109,9 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.5.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.5.1" }, - "time": "2024-11-04T21:26:31+00:00" + "time": "2024-11-06T11:58:54+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -5875,16 +5922,16 @@ }, { "name": "symfony/console", - "version": "v7.1.6", + "version": "v7.1.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "bb5192af6edc797cbab5c8e8ecfea2fe5f421e57" + "reference": "3284aafcac338b6e86fd955ee4d794cbe434151a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/bb5192af6edc797cbab5c8e8ecfea2fe5f421e57", - "reference": "bb5192af6edc797cbab5c8e8ecfea2fe5f421e57", + "url": "https://api.github.com/repos/symfony/console/zipball/3284aafcac338b6e86fd955ee4d794cbe434151a", + "reference": "3284aafcac338b6e86fd955ee4d794cbe434151a", "shasum": "" }, "require": { @@ -5948,7 +5995,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.6" + "source": "https://github.com/symfony/console/tree/v7.1.7" }, "funding": [ { @@ -5964,7 +6011,7 @@ "type": "tidelift" } ], - "time": "2024-10-09T08:46:59+00:00" + "time": "2024-11-05T15:34:55+00:00" }, { "name": "symfony/deprecation-contracts", @@ -6546,16 +6593,16 @@ }, { "name": "symfony/process", - "version": "v7.1.6", + "version": "v7.1.7", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e" + "reference": "9b8a40b7289767aa7117e957573c2a535efe6585" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e", - "reference": "6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e", + "url": "https://api.github.com/repos/symfony/process/zipball/9b8a40b7289767aa7117e957573c2a535efe6585", + "reference": "9b8a40b7289767aa7117e957573c2a535efe6585", "shasum": "" }, "require": { @@ -6587,7 +6634,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.6" + "source": "https://github.com/symfony/process/tree/v7.1.7" }, "funding": [ { @@ -6603,7 +6650,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-11-06T09:25:12+00:00" }, { "name": "symfony/service-contracts", @@ -7003,9 +7050,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/framework", + "version": "dev-feat-compression-0.33.x", + "alias": "0.33.9", + "alias_normalized": "0.33.9.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/framework": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 35c2978b7416d4dfccf9f1c220570bbb023f05e0 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:01:18 +0100 Subject: [PATCH 03/30] fix: test warning --- tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index b1315103b1..4f4b0c960d 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -1,12 +1,13 @@ Date: Thu, 7 Nov 2024 16:50:33 +0100 Subject: [PATCH 04/30] chore: bump composer --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 69a4d41b71..40c63c74ad 100644 --- a/composer.lock +++ b/composer.lock @@ -6923,16 +6923,16 @@ }, { "name": "twig/twig", - "version": "v3.14.0", + "version": "v3.14.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72" + "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/126b2c97818dbff0cdf3fbfc881aedb3d40aae72", - "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", + "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", "shasum": "" }, "require": { @@ -6986,7 +6986,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.14.0" + "source": "https://github.com/twigphp/Twig/tree/v3.14.2" }, "funding": [ { @@ -6998,7 +6998,7 @@ "type": "tidelift" } ], - "time": "2024-09-09T17:55:12+00:00" + "time": "2024-11-07T12:36:22+00:00" }, { "name": "webmozart/glob", From 71eba6a879f8fb84ef3b2472619f9a2b5a71b839 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:21:41 +0100 Subject: [PATCH 05/30] fix: tests --- app/http.php | 4 +- composer.lock | 8 +- tests/e2e/General/CompressionTest.php | 138 ++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 tests/e2e/General/CompressionTest.php diff --git a/app/http.php b/app/http.php index bec772c770..5a95b25f67 100644 --- a/app/http.php +++ b/app/http.php @@ -39,8 +39,7 @@ $http ->set([ 'worker_num' => $workerNumber, 'open_http2_protocol' => true, - 'http_compression' => true, - 'http_compression_level' => 6, + 'http_compression' => false, 'package_max_length' => $payloadSize, 'buffer_output_size' => $payloadSize, ]); @@ -61,6 +60,7 @@ include __DIR__ . '/controllers/general.php'; $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $register) { $app = new App('UTC'); + $app->setCompression(true); go(function () use ($register, $app) { $pools = $register->get('pools'); diff --git a/composer.lock b/composer.lock index 40c63c74ad..c00875c600 100644 --- a/composer.lock +++ b/composer.lock @@ -1976,12 +1976,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "a501a56f89097f2fd48c13eb2c632aafb1285cff" + "reference": "72239fb95a65fc65e3a8e435f1645e234b00ea04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/a501a56f89097f2fd48c13eb2c632aafb1285cff", - "reference": "a501a56f89097f2fd48c13eb2c632aafb1285cff", + "url": "https://api.github.com/repos/utopia-php/http/zipball/72239fb95a65fc65e3a8e435f1645e234b00ea04", + "reference": "72239fb95a65fc65e3a8e435f1645e234b00ea04", "shasum": "" }, "require": { @@ -2014,7 +2014,7 @@ "issues": "https://github.com/utopia-php/http/issues", "source": "https://github.com/utopia-php/http/tree/feat-compression-0.33.x" }, - "time": "2024-11-01T17:05:05+00:00" + "time": "2024-11-07T17:00:49+00:00" }, { "name": "utopia-php/image", diff --git a/tests/e2e/General/CompressionTest.php b/tests/e2e/General/CompressionTest.php new file mode 100644 index 0000000000..2a565ff34d --- /dev/null +++ b/tests/e2e/General/CompressionTest.php @@ -0,0 +1,138 @@ +client->call(Client::METHOD_GET, '/ping', [ + 'accept-encoding' => 'gzip', + 'x-appwrite-project' => $this->getProject()['$id'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('Pong!', $response['body']); + $this->assertLessThan(1024, strlen($response['body'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + + // without header + $response = $this->client->call(Client::METHOD_GET, '/ping', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('Pong!', $response['body']); + $this->assertLessThan(1024, strlen($response['body'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } + + public function testLargeResponse() + { + // create an anonymous user + $response = $this->client->call(Client::METHOD_POST, '/users', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'userId' => ID::unique(), + 'email' => 'test@localhost.test', + 'password' => 'password', + 'name' => 'User Name', + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $userId = $response['body']['$id']; + + // set prefs with 2000 bytes of data + $prefs = ["longValue" => str_repeat('a', 2000)]; + + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'prefs' => $prefs, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + // get prefs with compression + $response = $this->client->call(Client::METHOD_GET, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'accept-encoding' => 'gzip', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertArrayHasKey('content-encoding', $response['headers'], 'Content encoding should be gzip, headers received: ' . json_encode($response['headers'], JSON_PRETTY_PRINT)); + $this->assertLessThan(2000, intval($response['headers']['content-length'])); + + // get prefs without compression + $response = $this->client->call(Client::METHOD_GET, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThanOrEqual(2000, intval($response['headers']['content-length'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } + + public function testImageResponse() + { + // create bucket + $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'bucketId' => ID::unique(), + 'name' => 'Test Bucket', + 'fileSecurity' => true, + ]); + $bucketId = $bucket['body']['$id']; + $this->assertEquals(201, $bucket['headers']['status-code']); + + // upload image + $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $fileId = $file['body']['$id']; + + // get image with header + $response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([ + 'content-type' => 'application/json', + 'accept-encoding' => 'gzip', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('gzip', $response['headers']['content-encoding']); + + // get image without + $response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } +} From 83cbddb9267e4ad4735268c2169c5598e63b2486 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:31:12 +0100 Subject: [PATCH 06/30] fix: test --- app/http.php | 1 + tests/e2e/Client.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/http.php b/app/http.php index 5a95b25f67..87472a3fbe 100644 --- a/app/http.php +++ b/app/http.php @@ -244,6 +244,7 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo } $app = new App('UTC'); + $app->setCompression(true); $pools = $register->get('pools'); App::setResource('pools', fn () => $pools); diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index 0774f1c6fd..2bcabd7c61 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -221,6 +221,10 @@ class Client curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } + if (isset($headers['accept-encoding'])) { + curl_setopt($ch, CURLOPT_ENCODING, $headers['accept-encoding']); // Enable automatic decoding + } + $responseBody = curl_exec($ch); $responseType = $responseHeaders['content-type'] ?? ''; $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); From d33056d13b74e4ed78dda36d8130c2e11cb8ce84 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 8 Nov 2024 13:48:41 +0900 Subject: [PATCH 07/30] Address Comments --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index bc9fa75e6f..07295f4afb 100755 --- a/Dockerfile +++ b/Dockerfile @@ -92,10 +92,10 @@ RUN chmod +x /usr/local/bin/doctor && \ RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ # Enable Extensions -RUN if [ "$DEBUG" == "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi -RUN if [ "$DEBUG" == "true" ]; then mkdir -p /tmp/xdebug; fi -RUN if [ "$DEBUG" == "false" ]; then rm -rf /usr/src/code/dev; fi -RUN if [ "$DEBUG" == "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so; fi +RUN if [ "$DEBUG" = "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi +RUN if [ "$DEBUG" = "true" ]; then mkdir -p /tmp/xdebug; fi +RUN if [ "$DEBUG" = "false" ]; then rm -rf /usr/src/code/dev; fi +RUN if [ "$DEBUG" = "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so; fi EXPOSE 80 From a17e722dc793553c85bb798dcb5e1bcff28009ff Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Nov 2024 20:19:40 +1300 Subject: [PATCH 08/30] Update database --- composer.json | 2 +- composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index a04ca51d43..5c2441fd1b 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.11.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.16", + "utopia-php/database": "0.53.19", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index ff822aaafb..c7ecca5034 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": "b358198535c1867eabed7c0f99135a57", + "content-hash": "5be1b916c221b97b77b0e7f14491aabf", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.16", + "version": "0.53.19", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de" + "reference": "48951885f2787df30ad8581a0e94423558619daa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/6661edffeef05b59e16d102b989a72f7f78cf7de", - "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de", + "url": "https://api.github.com/repos/utopia-php/database/zipball/48951885f2787df30ad8581a0e94423558619daa", + "reference": "48951885f2787df30ad8581a0e94423558619daa", "shasum": "" }, "require": { @@ -1774,9 +1774,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.16" + "source": "https://github.com/utopia-php/database/tree/0.53.19" }, - "time": "2024-11-06T03:07:16+00:00" + "time": "2024-11-08T07:00:24+00:00" }, { "name": "utopia-php/domains", @@ -6876,16 +6876,16 @@ }, { "name": "twig/twig", - "version": "v3.14.1", + "version": "v3.14.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "f405356d20fb43603bcadc8b09bfb676cb04a379" + "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/f405356d20fb43603bcadc8b09bfb676cb04a379", - "reference": "f405356d20fb43603bcadc8b09bfb676cb04a379", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", + "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", "shasum": "" }, "require": { @@ -6939,7 +6939,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.14.1" + "source": "https://github.com/twigphp/Twig/tree/v3.14.2" }, "funding": [ { @@ -6951,7 +6951,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T18:17:38+00:00" + "time": "2024-11-07T12:36:22+00:00" }, { "name": "webmozart/glob", From 14532acb376e29f6c5be5c88dac00af3d795a93f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Nov 2024 21:43:25 +1300 Subject: [PATCH 09/30] Update limit errors --- app/config/errors.php | 2 +- app/controllers/api/databases.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 3afec4faaf..f09d1596eb 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -686,7 +686,7 @@ return [ ], Exception::ATTRIBUTE_LIMIT_EXCEEDED => [ 'name' => Exception::ATTRIBUTE_LIMIT_EXCEEDED, - 'description' => 'The maximum number of attributes has been reached.', + 'description' => 'The maximum number or size of attributes for this collection has been reached.', 'code' => 400, ], Exception::ATTRIBUTE_VALUE_INVALID => [ diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 0114fd343c..dcf5bbffa5 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -153,7 +153,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (DuplicateException) { throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); } catch (LimitException) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } catch (\Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); @@ -197,7 +197,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); } catch (LimitException) { $dbForProject->deleteDocument('attributes', $attribute->getId()); - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } catch (\Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); @@ -393,6 +393,8 @@ function updateAttribute( throw new Exception(Exception::ATTRIBUTE_INVALID_RESIZE); } catch (NotFoundException) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + } catch (LimitException) { + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } } From 78c4bb395cf6677f5390464d63fc079c269d3b59 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Nov 2024 21:59:42 +1300 Subject: [PATCH 10/30] Fix test --- tests/e2e/Services/Databases/DatabasesCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 7cb8adb815..b501e2119e 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -1362,7 +1362,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooWide['headers']['status-code']); - $this->assertEquals('Attribute limit exceeded', $tooWide['body']['message']); + $this->assertEquals('attribute_limit_exceeded', $tooWide['body']['type']); } public function testIndexLimitException() From ee4b54857f3287906b35946a55844839a6524024 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:01:18 +0100 Subject: [PATCH 11/30] fix: tests --- tests/e2e/Client.php | 17 ++++++++++------- tests/e2e/General/CompressionTest.php | 5 ++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index 2bcabd7c61..cb8fd44cb3 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -179,9 +179,14 @@ class Client default => http_build_query($params), }; - foreach ($headers as $i => $header) { - $headers[] = $i . ':' . $header; - unset($headers[$i]); + $formattedHeaders = []; + foreach ($headers as $key => $value) { + if (strtolower($key) === 'accept-encoding') { + curl_setopt($ch, CURLOPT_ENCODING, $value); + continue; + } else { + $formattedHeaders[] = $key . ': ' . $value; + } } curl_setopt($ch, CURLOPT_PATH_AS_IS, 1); @@ -189,7 +194,7 @@ class Client curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_HTTPHEADER, $formattedHeaders); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$responseHeaders, &$cookies) { @@ -221,9 +226,7 @@ class Client curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } - if (isset($headers['accept-encoding'])) { - curl_setopt($ch, CURLOPT_ENCODING, $headers['accept-encoding']); // Enable automatic decoding - } + curl_setopt($ch, CURLOPT_VERBOSE, true); $responseBody = curl_exec($ch); $responseType = $responseHeaders['content-type'] ?? ''; diff --git a/tests/e2e/General/CompressionTest.php b/tests/e2e/General/CompressionTest.php index 2a565ff34d..9affacfe0a 100644 --- a/tests/e2e/General/CompressionTest.php +++ b/tests/e2e/General/CompressionTest.php @@ -107,7 +107,7 @@ class CompressionTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'fileId' => ID::unique(), - 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'file' => new CURLFile(realpath(__DIR__ . '/../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -124,8 +124,7 @@ class CompressionTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('gzip', $response['headers']['content-encoding']); - + $this->assertArrayNotHasKey('content-encoding', $response['headers']); // get image without $response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([ 'content-type' => 'application/json', From e43887c53b950c733208bed9a1566869bea9d412 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:06:09 +0100 Subject: [PATCH 12/30] feat: remove verbose --- tests/e2e/Client.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index cb8fd44cb3..dc80808b14 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -225,9 +225,6 @@ class Client curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } - - curl_setopt($ch, CURLOPT_VERBOSE, true); - $responseBody = curl_exec($ch); $responseType = $responseHeaders['content-type'] ?? ''; $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); From c8c4dd28df552e4d17552fb150b09237d36a7e14 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:28:01 +0100 Subject: [PATCH 13/30] chore: composer update --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index c00875c600..6727e73bff 100644 --- a/composer.lock +++ b/composer.lock @@ -1673,16 +1673,16 @@ }, { "name": "utopia-php/compression", - "version": "0.1.0", + "version": "0.1.1", "source": { "type": "git", "url": "https://github.com/utopia-php/compression.git", - "reference": "8c6d9bcb5b0972faa27e5bf70923c20403aaf25c" + "reference": "2ac5709e39823dbccb9fa66099ccebe809078c2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/compression/zipball/8c6d9bcb5b0972faa27e5bf70923c20403aaf25c", - "reference": "8c6d9bcb5b0972faa27e5bf70923c20403aaf25c", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/2ac5709e39823dbccb9fa66099ccebe809078c2e", + "reference": "2ac5709e39823dbccb9fa66099ccebe809078c2e", "shasum": "" }, "require": { @@ -1713,9 +1713,9 @@ ], "support": { "issues": "https://github.com/utopia-php/compression/issues", - "source": "https://github.com/utopia-php/compression/tree/0.1.0" + "source": "https://github.com/utopia-php/compression/tree/0.1.1" }, - "time": "2024-10-23T10:17:46+00:00" + "time": "2024-11-08T12:22:15+00:00" }, { "name": "utopia-php/config", @@ -1976,12 +1976,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "72239fb95a65fc65e3a8e435f1645e234b00ea04" + "reference": "58851dc88c4d8ac32757f30f1508cdf55a26cb4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/72239fb95a65fc65e3a8e435f1645e234b00ea04", - "reference": "72239fb95a65fc65e3a8e435f1645e234b00ea04", + "url": "https://api.github.com/repos/utopia-php/http/zipball/58851dc88c4d8ac32757f30f1508cdf55a26cb4a", + "reference": "58851dc88c4d8ac32757f30f1508cdf55a26cb4a", "shasum": "" }, "require": { @@ -2014,7 +2014,7 @@ "issues": "https://github.com/utopia-php/http/issues", "source": "https://github.com/utopia-php/http/tree/feat-compression-0.33.x" }, - "time": "2024-11-07T17:00:49+00:00" + "time": "2024-11-08T12:23:25+00:00" }, { "name": "utopia-php/image", From 56c43560f1c2f2c31d98236a2e905355b647e60d Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:41:29 +0100 Subject: [PATCH 14/30] chore: composer update --- composer.json | 2 +- composer.lock | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 15b2c9af90..5c2441fd1b 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "utopia-php/database": "0.53.19", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", - "utopia-php/framework": "dev-feat-compression-0.33.x as 0.33.9", + "utopia-php/framework": "0.33.*", "utopia-php/fetch": "0.2.*", "utopia-php/image": "0.7.*", "utopia-php/locale": "0.4.*", diff --git a/composer.lock b/composer.lock index 6425354bcd..e007c4eac9 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": "6786247bf3743103412df3642d68dbb5", + "content-hash": "5be1b916c221b97b77b0e7f14491aabf", "packages": [ { "name": "adhocore/jwt", @@ -1972,16 +1972,16 @@ }, { "name": "utopia-php/framework", - "version": "dev-feat-compression-0.33.x", + "version": "0.33.9", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "58851dc88c4d8ac32757f30f1508cdf55a26cb4a" + "reference": "82c7252c02ae39a027592175f2732df27c167db4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/58851dc88c4d8ac32757f30f1508cdf55a26cb4a", - "reference": "58851dc88c4d8ac32757f30f1508cdf55a26cb4a", + "url": "https://api.github.com/repos/utopia-php/http/zipball/82c7252c02ae39a027592175f2732df27c167db4", + "reference": "82c7252c02ae39a027592175f2732df27c167db4", "shasum": "" }, "require": { @@ -2012,9 +2012,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/feat-compression-0.33.x" + "source": "https://github.com/utopia-php/http/tree/0.33.9" }, - "time": "2024-11-08T12:23:25+00:00" + "time": "2024-11-08T12:39:51+00:00" }, { "name": "utopia-php/image", @@ -7050,18 +7050,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/framework", - "version": "dev-feat-compression-0.33.x", - "alias": "0.33.9", - "alias_normalized": "0.33.9.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/framework": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { From 4b9457acc5a69c0e0a1dae1356009e38ba60f4b8 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:03:32 +0100 Subject: [PATCH 15/30] chore: bump compression --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index e007c4eac9..1ea0a1a048 100644 --- a/composer.lock +++ b/composer.lock @@ -1673,16 +1673,16 @@ }, { "name": "utopia-php/compression", - "version": "0.1.1", + "version": "0.1.2", "source": { "type": "git", "url": "https://github.com/utopia-php/compression.git", - "reference": "2ac5709e39823dbccb9fa66099ccebe809078c2e" + "reference": "6062f70596415f8d5de40a589367b0eb2a435f98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/compression/zipball/2ac5709e39823dbccb9fa66099ccebe809078c2e", - "reference": "2ac5709e39823dbccb9fa66099ccebe809078c2e", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/6062f70596415f8d5de40a589367b0eb2a435f98", + "reference": "6062f70596415f8d5de40a589367b0eb2a435f98", "shasum": "" }, "require": { @@ -1713,9 +1713,9 @@ ], "support": { "issues": "https://github.com/utopia-php/compression/issues", - "source": "https://github.com/utopia-php/compression/tree/0.1.1" + "source": "https://github.com/utopia-php/compression/tree/0.1.2" }, - "time": "2024-11-08T12:22:15+00:00" + "time": "2024-11-08T14:59:54+00:00" }, { "name": "utopia-php/config", From cd817dbc0f6a68fd7ef7627eae000cfa7f9afba0 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:04:33 +0100 Subject: [PATCH 16/30] chore: bump framework --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index f2845dc137..79c6a82420 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,6 +83,7 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev + - ./vendor:/usr/src/code/vendor depends_on: - mariadb - redis From d37c0500fc77c4a43924280e9a1ac16a4f87beac Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:11:30 +0100 Subject: [PATCH 17/30] chore: bump framework, remove vender mount --- composer.lock | 12 ++++++------ docker-compose.yml | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 1ea0a1a048..0bcc5669ea 100644 --- a/composer.lock +++ b/composer.lock @@ -1972,16 +1972,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.9", + "version": "0.33.10", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "82c7252c02ae39a027592175f2732df27c167db4" + "reference": "247b934529ab9bcde7d39d6e6212cefcccfc3b20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/82c7252c02ae39a027592175f2732df27c167db4", - "reference": "82c7252c02ae39a027592175f2732df27c167db4", + "url": "https://api.github.com/repos/utopia-php/http/zipball/247b934529ab9bcde7d39d6e6212cefcccfc3b20", + "reference": "247b934529ab9bcde7d39d6e6212cefcccfc3b20", "shasum": "" }, "require": { @@ -2012,9 +2012,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.9" + "source": "https://github.com/utopia-php/http/tree/0.33.10" }, - "time": "2024-11-08T12:39:51+00:00" + "time": "2024-11-08T15:02:59+00:00" }, { "name": "utopia-php/image", diff --git a/docker-compose.yml b/docker-compose.yml index 79c6a82420..f2845dc137 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,7 +83,6 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev - - ./vendor:/usr/src/code/vendor depends_on: - mariadb - redis From d0cf0f6d1d3ba381fb2786c456912aedd2175a0f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:48:32 +0100 Subject: [PATCH 18/30] feat: min size env --- .env | 1 + app/config/variables.php | 9 +++++++++ app/http.php | 2 ++ composer.lock | 24 ++++++++++++------------ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.env b/.env index f6a6a7f642..95dca6d868 100644 --- a/.env +++ b/.env @@ -2,6 +2,7 @@ _APP_ENV=development _APP_EDITION=self-hosted _APP_LOCALE=en _APP_WORKER_PER_CORE=6 +_APP_COMPRESSION_MIN_SIZE_BYTES=1000 _APP_CONSOLE_WHITELIST_ROOT=disabled _APP_CONSOLE_WHITELIST_EMAILS= _APP_CONSOLE_SESSION_ALERTS=enabled diff --git a/app/config/variables.php b/app/config/variables.php index 113fbae335..dbd8a0e50f 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -97,6 +97,15 @@ return [ 'question' => 'Enter a DNS A record hostname to serve as a CNAME for your custom domains.' . PHP_EOL . 'You can use the same value as used for the Appwrite hostname.', 'filter' => 'domainTarget' ], + [ + 'name' => '_APP_COMPRESSION_MIN_SIZE_BYTES', + 'description' => 'The minimum size of the response body to be compressed. The default value is 1024 bytes. To disable compression, set the value to 0.', + 'introduction' => '1.6.0', + 'default' => '1024', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_CONSOLE_WHITELIST_ROOT', 'description' => 'This option allows you to disable the creation of new users on the Appwrite console. When enabled only 1 user will be able to use the registration form. New users can be added by inviting them to your project. By default this option is enabled.', diff --git a/app/http.php b/app/http.php index 87472a3fbe..641143694d 100644 --- a/app/http.php +++ b/app/http.php @@ -61,6 +61,7 @@ include __DIR__ . '/controllers/general.php'; $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $register) { $app = new App('UTC'); $app->setCompression(true); + $app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB go(function () use ($register, $app) { $pools = $register->get('pools'); @@ -245,6 +246,7 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $app = new App('UTC'); $app->setCompression(true); + $app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB $pools = $register->get('pools'); App::setResource('pools', fn () => $pools); diff --git a/composer.lock b/composer.lock index 0bcc5669ea..097cee9868 100644 --- a/composer.lock +++ b/composer.lock @@ -1972,16 +1972,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.10", + "version": "0.33.11", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "247b934529ab9bcde7d39d6e6212cefcccfc3b20" + "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/247b934529ab9bcde7d39d6e6212cefcccfc3b20", - "reference": "247b934529ab9bcde7d39d6e6212cefcccfc3b20", + "url": "https://api.github.com/repos/utopia-php/http/zipball/354ff0d23bfc6e82bea0fe8e89e115cff1af8466", + "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466", "shasum": "" }, "require": { @@ -2012,9 +2012,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.10" + "source": "https://github.com/utopia-php/http/tree/0.33.11" }, - "time": "2024-11-08T15:02:59+00:00" + "time": "2024-11-08T18:47:43+00:00" }, { "name": "utopia-php/image", @@ -3560,16 +3560,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -3608,7 +3608,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -3616,7 +3616,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:39:25+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nikic/php-parser", From 428998b6b639b49451666da2795038faa0d8a818 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:50:20 +0100 Subject: [PATCH 19/30] chore: fix --- .env | 2 +- app/config/variables.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 95dca6d868..8ff8164a21 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ _APP_ENV=development _APP_EDITION=self-hosted _APP_LOCALE=en _APP_WORKER_PER_CORE=6 -_APP_COMPRESSION_MIN_SIZE_BYTES=1000 +_APP_COMPRESSION_MIN_SIZE_BYTES=1024 _APP_CONSOLE_WHITELIST_ROOT=disabled _APP_CONSOLE_WHITELIST_EMAILS= _APP_CONSOLE_SESSION_ALERTS=enabled diff --git a/app/config/variables.php b/app/config/variables.php index dbd8a0e50f..2cba7e83c2 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -100,7 +100,7 @@ return [ [ 'name' => '_APP_COMPRESSION_MIN_SIZE_BYTES', 'description' => 'The minimum size of the response body to be compressed. The default value is 1024 bytes. To disable compression, set the value to 0.', - 'introduction' => '1.6.0', + 'introduction' => '1.6.1', 'default' => '1024', 'required' => false, 'question' => '', From 532aac6a62e3950d718b5ed15f42691c9c15a71f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:00:05 +0100 Subject: [PATCH 20/30] chore: dockerfiles --- app/config/variables.php | 9 --------- app/views/install/compose.phtml | 1 + docker-compose.yml | 1 + tests/resources/docker/docker-compose.yml | 1 + 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/config/variables.php b/app/config/variables.php index 2cba7e83c2..113fbae335 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -97,15 +97,6 @@ return [ 'question' => 'Enter a DNS A record hostname to serve as a CNAME for your custom domains.' . PHP_EOL . 'You can use the same value as used for the Appwrite hostname.', 'filter' => 'domainTarget' ], - [ - 'name' => '_APP_COMPRESSION_MIN_SIZE_BYTES', - 'description' => 'The minimum size of the response body to be compressed. The default value is 1024 bytes. To disable compression, set the value to 0.', - 'introduction' => '1.6.1', - 'default' => '1024', - 'required' => false, - 'question' => '', - 'filter' => '' - ], [ 'name' => '_APP_CONSOLE_WHITELIST_ROOT', 'description' => 'This option allows you to disable the creation of new users on the Appwrite console. When enabled only 1 user will be able to use the registration form. New users can be added by inviting them to your project. By default this option is enabled.', diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index ad35135a6f..8d7fecb479 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -73,6 +73,7 @@ $image = $this->getParam('image', ''); - _APP_ENV - _APP_WORKER_PER_CORE - _APP_LOCALE + - _APP_COMPRESSION_MIN_SIZE_BYTES - _APP_CONSOLE_WHITELIST_ROOT - _APP_CONSOLE_WHITELIST_EMAILS - _APP_CONSOLE_SESSION_ALERTS diff --git a/docker-compose.yml b/docker-compose.yml index f2845dc137..048178e60a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -96,6 +96,7 @@ services: - _APP_EDITION - _APP_WORKER_PER_CORE - _APP_LOCALE + - _APP_COMPRESSION_MIN_SIZE_BYTES - _APP_CONSOLE_WHITELIST_ROOT - _APP_CONSOLE_WHITELIST_EMAILS - _APP_CONSOLE_SESSION_ALERTS diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index a34b4fcf88..94d506056c 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -62,6 +62,7 @@ services: - redis # - clamav environment: + - _APP_COMPRESSION_MIN_SIZE_BYTES - _APP_ENV - _APP_OPTIONS_ABUSE - _APP_OPTIONS_ROUTER_PROTECTION From af448ac1831455c777e285073fdd0978f18cf17c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:55:53 +0100 Subject: [PATCH 21/30] feat: setpaused --- src/Appwrite/Event/Audit.php | 4 ++++ src/Appwrite/Event/Build.php | 4 ++++ src/Appwrite/Event/Certificate.php | 4 ++++ src/Appwrite/Event/Database.php | 4 ++++ src/Appwrite/Event/Delete.php | 4 ++++ src/Appwrite/Event/Event.php | 22 ++++++++++++++++++++++ src/Appwrite/Event/Func.php | 4 ++++ src/Appwrite/Event/Mail.php | 4 ++++ src/Appwrite/Event/Messaging.php | 4 ++++ src/Appwrite/Event/Migration.php | 3 +++ src/Appwrite/Event/Realtime.php | 2 +- src/Appwrite/Event/Usage.php | 4 ++++ src/Appwrite/Event/UsageDump.php | 4 ++++ 13 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Audit.php b/src/Appwrite/Event/Audit.php index 4b02849970..17506bfe6c 100644 --- a/src/Appwrite/Event/Audit.php +++ b/src/Appwrite/Event/Audit.php @@ -121,6 +121,10 @@ class Audit extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php index b8cb62a6f8..1fbf20a9f9 100644 --- a/src/Appwrite/Event/Build.php +++ b/src/Appwrite/Event/Build.php @@ -112,6 +112,10 @@ class Build extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Certificate.php b/src/Appwrite/Event/Certificate.php index 85058c96fe..5d30c3d5ac 100644 --- a/src/Appwrite/Event/Certificate.php +++ b/src/Appwrite/Event/Certificate.php @@ -74,6 +74,10 @@ class Certificate extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index f9eb7d9a7d..1b0ea6851c 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -108,6 +108,10 @@ class Database extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + try { $dsn = new DSN($this->getProject()->getAttribute('database')); } catch (\InvalidArgumentException) { diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index 064fbcefa9..1a4c9318e3 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -140,6 +140,10 @@ class Delete extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 3f166ad7a4..e3a2e394cf 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -65,6 +65,24 @@ class Event { } + /** + * Set paused state for this event. + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } + + /** + * Get paused state for this event. + */ + public function getPaused(): bool + { + return $this->paused; + } + /** * Set queue used for this event. * @@ -302,6 +320,10 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 11a445d8ed..0ad639a9f5 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -213,6 +213,10 @@ class Func extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index 9bdbf6044d..a0fca75688 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -404,6 +404,10 @@ class Mail extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index f97ff02d21..ab9b1bee6b 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -182,6 +182,10 @@ class Messaging extends Event */ public function trigger(): string | bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Migration.php b/src/Appwrite/Event/Migration.php index e57ac3c87c..789b8e2160 100644 --- a/src/Appwrite/Event/Migration.php +++ b/src/Appwrite/Event/Migration.php @@ -75,6 +75,9 @@ class Migration extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } $client = new Client($this->queue, $this->connection); diff --git a/src/Appwrite/Event/Realtime.php b/src/Appwrite/Event/Realtime.php index e158076f9b..f4f00b59d4 100644 --- a/src/Appwrite/Event/Realtime.php +++ b/src/Appwrite/Event/Realtime.php @@ -32,7 +32,7 @@ class Realtime extends Event */ public function trigger(): string|bool { - if (empty($this->event)) { + if ($this->paused || empty($this->event)) { return false; } diff --git a/src/Appwrite/Event/Usage.php b/src/Appwrite/Event/Usage.php index 4426f4ab1b..161c251c8e 100644 --- a/src/Appwrite/Event/Usage.php +++ b/src/Appwrite/Event/Usage.php @@ -57,6 +57,10 @@ class Usage extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ 'project' => $this->getProject(), diff --git a/src/Appwrite/Event/UsageDump.php b/src/Appwrite/Event/UsageDump.php index 8f87908849..2998e4e104 100644 --- a/src/Appwrite/Event/UsageDump.php +++ b/src/Appwrite/Event/UsageDump.php @@ -38,6 +38,10 @@ class UsageDump extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ From b1a1ad618a553efe42157306d2f6c59e6444892c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 01:01:14 +0400 Subject: [PATCH 22/30] Revert "Update database" --- app/config/errors.php | 2 +- app/controllers/api/databases.php | 6 ++--- composer.json | 2 +- composer.lock | 26 +++++++++---------- .../Databases/DatabasesCustomServerTest.php | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index f09d1596eb..3afec4faaf 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -686,7 +686,7 @@ return [ ], Exception::ATTRIBUTE_LIMIT_EXCEEDED => [ 'name' => Exception::ATTRIBUTE_LIMIT_EXCEEDED, - 'description' => 'The maximum number or size of attributes for this collection has been reached.', + 'description' => 'The maximum number of attributes has been reached.', 'code' => 400, ], Exception::ATTRIBUTE_VALUE_INVALID => [ diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index dcf5bbffa5..0114fd343c 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -153,7 +153,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (DuplicateException) { throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); } catch (LimitException) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); } catch (\Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId()); @@ -197,7 +197,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); } catch (LimitException) { $dbForProject->deleteDocument('attributes', $attribute->getId()); - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); } catch (\Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId()); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); @@ -393,8 +393,6 @@ function updateAttribute( throw new Exception(Exception::ATTRIBUTE_INVALID_RESIZE); } catch (NotFoundException) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); - } catch (LimitException) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } } diff --git a/composer.json b/composer.json index 5c2441fd1b..a04ca51d43 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.11.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.19", + "utopia-php/database": "0.53.16", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 097cee9868..2724542a38 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": "5be1b916c221b97b77b0e7f14491aabf", + "content-hash": "b358198535c1867eabed7c0f99135a57", "packages": [ { "name": "adhocore/jwt", @@ -1770,16 +1770,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.19", + "version": "0.53.16", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "48951885f2787df30ad8581a0e94423558619daa" + "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/48951885f2787df30ad8581a0e94423558619daa", - "reference": "48951885f2787df30ad8581a0e94423558619daa", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6661edffeef05b59e16d102b989a72f7f78cf7de", + "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de", "shasum": "" }, "require": { @@ -1820,9 +1820,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.19" + "source": "https://github.com/utopia-php/database/tree/0.53.16" }, - "time": "2024-11-08T07:00:24+00:00" + "time": "2024-11-06T03:07:16+00:00" }, { "name": "utopia-php/domains", @@ -6923,16 +6923,16 @@ }, { "name": "twig/twig", - "version": "v3.14.2", + "version": "v3.14.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a" + "reference": "f405356d20fb43603bcadc8b09bfb676cb04a379" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", - "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/f405356d20fb43603bcadc8b09bfb676cb04a379", + "reference": "f405356d20fb43603bcadc8b09bfb676cb04a379", "shasum": "" }, "require": { @@ -6986,7 +6986,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.14.2" + "source": "https://github.com/twigphp/Twig/tree/v3.14.1" }, "funding": [ { @@ -6998,7 +6998,7 @@ "type": "tidelift" } ], - "time": "2024-11-07T12:36:22+00:00" + "time": "2024-11-06T18:17:38+00:00" }, { "name": "webmozart/glob", diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index b501e2119e..7cb8adb815 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -1362,7 +1362,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooWide['headers']['status-code']); - $this->assertEquals('attribute_limit_exceeded', $tooWide['body']['type']); + $this->assertEquals('Attribute limit exceeded', $tooWide['body']['message']); } public function testIndexLimitException() From 5f29af2c271d63f1320d84cfb2384d4fc01a1bd3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 8 Nov 2024 22:08:13 +0100 Subject: [PATCH 23/30] feat: use getDocument instead of find() for rules --- app/controllers/api/functions.php | 2 +- app/controllers/api/proxy.php | 2 +- app/controllers/general.php | 11 ++++------- src/Appwrite/Migration/Version/V19.php | 1 + src/Appwrite/Platform/Workers/Certificates.php | 4 +--- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0ca73ee6ac..2309defe5a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -326,9 +326,9 @@ App::post('/v1/functions') $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); if (!empty($functionsDomain)) { - $ruleId = ID::unique(); $routeSubdomain = ID::unique(); $domain = "{$routeSubdomain}.{$functionsDomain}"; + $ruleId = md5($domain); $rule = Authorization::skip( fn () => $dbForConsole->createDocument('rules', new Document([ diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 02a3ec8e9d..9860bd8276 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -103,7 +103,7 @@ App::post('/v1/proxy/rules') throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.'); } - $ruleId = ID::unique(); + $ruleId = md5($domain->get()); $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), diff --git a/app/controllers/general.php b/app/controllers/general.php index b08ecb3d12..908ffdcb71 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -52,14 +52,10 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo $host = $request->getHostname() ?? ''; - $route = Authorization::skip( - fn () => $dbForConsole->find('rules', [ - Query::equal('domain', [$host]), - Query::limit(1) - ]) - )[0] ?? null; + $ruleId = md5($host); + $route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', $ruleId)); - if ($route === null) { + if ($route->isEmpty()) { if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) { throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.'); } @@ -531,6 +527,7 @@ App::init() if ($domainDocument->isEmpty()) { $domainDocument = new Document([ + '$id' => md5($domain->get()), 'domain' => $domain->get(), 'resourceType' => 'api', 'status' => 'verifying', diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index 18234ebdc4..2546ae9baf 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -72,6 +72,7 @@ class V19 extends Migration } $ruleDocument = new Document([ + '$id' => md5($domain->getAttribute('domain')), 'projectId' => $domain->getAttribute('projectId'), 'projectInternalId' => $domain->getAttribute('projectInternalId'), 'domain' => $domain->getAttribute('domain'), diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index a14f164295..21d967d9e1 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -478,9 +478,7 @@ class Certificates extends Action private function updateDomainDocuments(string $certificateId, string $domain, bool $success, Database $dbForConsole, Event $queueForEvents, Func $queueForFunctions): void { - $rule = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain]), - ]); + $rule = $dbForConsole->getDocument('rules', md5($domain)); if (!$rule->isEmpty()) { $rule->setAttribute('certificateId', $certificateId); From 6ae9952fa64b105e6881459e89e2e82cb97ae205 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 8 Nov 2024 22:18:05 +0100 Subject: [PATCH 24/30] chore: linter --- app/controllers/api/proxy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 9860bd8276..e3bef01417 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -11,7 +11,6 @@ use Utopia\App; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; -use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; From e4cd914d574ee38375200c262277ee88a5004cc5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 11:34:56 +0100 Subject: [PATCH 25/30] feat: downgrade db library --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c2441fd1b..a04ca51d43 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.11.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.19", + "utopia-php/database": "0.53.16", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", From e04551ab6e380d90f64ea8cae9d03a5a758728e7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 11:43:52 +0100 Subject: [PATCH 26/30] feat: adjust more proxy queries --- app/controllers/api/proxy.php | 5 ++--- app/controllers/general.php | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index e3bef01417..56fd31e88c 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -59,9 +59,8 @@ App::post('/v1/proxy/rules') throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.'); } - $document = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain]), - ]); + $ruleId = md5($domain); + $document = $dbForConsole->getDocument('rules', $ruleId); if (!$document->isEmpty()) { if ($document->getAttribute('projectId') === $project->getId()) { diff --git a/app/controllers/general.php b/app/controllers/general.php index 908ffdcb71..35a55d195f 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -521,9 +521,7 @@ App::init() if ($mainDomain !== $domain->get()) { Console::warning($domain->get() . ' is not a main domain. Skipping SSL certificate generation.'); } else { - $domainDocument = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain->get()]) - ]); + $domainDocument = $dbForConsole->getDocument('rules', md5($domain->get())); if ($domainDocument->isEmpty()) { $domainDocument = new Document([ From e8ddda079d01e9fe65e03d8f6bb80f4af374b468 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 16:13:44 +0100 Subject: [PATCH 27/30] chore: update more find methods --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 35a55d195f..b4ff3a1de4 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -514,7 +514,7 @@ App::init() if (!empty($envDomain) && $envDomain !== 'localhost') { $mainDomain = $envDomain; } else { - $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); + $domainDocument = $dbForConsole->getDocument('rules', md5($envDomain)); $mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get(); } From 6c7f484383229cd62bde3016db3f3a99f1bc3ddf Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 16:18:22 +0100 Subject: [PATCH 28/30] chore: update more find methods --- app/controllers/general.php | 3 +-- src/Appwrite/Migration/Version/V19.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index b4ff3a1de4..7cfee0e2f4 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -52,8 +52,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo $host = $request->getHostname() ?? ''; - $ruleId = md5($host); - $route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', $ruleId)); + $route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', md5($host))); if ($route->isEmpty()) { if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) { diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index 2546ae9baf..18234ebdc4 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -72,7 +72,6 @@ class V19 extends Migration } $ruleDocument = new Document([ - '$id' => md5($domain->getAttribute('domain')), 'projectId' => $domain->getAttribute('projectId'), 'projectInternalId' => $domain->getAttribute('projectInternalId'), 'domain' => $domain->getAttribute('domain'), From ba91d90c40fa1709ecd3f9a5ad076b856217e335 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 9 Nov 2024 16:31:33 +0100 Subject: [PATCH 29/30] chore: linter --- app/controllers/general.php | 1 - composer.lock | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 7cfee0e2f4..663242882a 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -29,7 +29,6 @@ use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; -use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Domains\Domain; use Utopia\DSN\DSN; diff --git a/composer.lock b/composer.lock index 097cee9868..62a7a755f2 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": "5be1b916c221b97b77b0e7f14491aabf", + "content-hash": "b358198535c1867eabed7c0f99135a57", "packages": [ { "name": "adhocore/jwt", @@ -1770,16 +1770,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.19", + "version": "0.53.16", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "48951885f2787df30ad8581a0e94423558619daa" + "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/48951885f2787df30ad8581a0e94423558619daa", - "reference": "48951885f2787df30ad8581a0e94423558619daa", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6661edffeef05b59e16d102b989a72f7f78cf7de", + "reference": "6661edffeef05b59e16d102b989a72f7f78cf7de", "shasum": "" }, "require": { @@ -1820,9 +1820,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.19" + "source": "https://github.com/utopia-php/database/tree/0.53.16" }, - "time": "2024-11-08T07:00:24+00:00" + "time": "2024-11-06T03:07:16+00:00" }, { "name": "utopia-php/domains", @@ -4115,23 +4115,23 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.9.0", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d" + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a", + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.18" + "phpstan/phpdoc-parser": "^1.18|^2.0" }, "require-dev": { "ext-tokenizer": "*", @@ -4167,9 +4167,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0" }, - "time": "2024-11-03T20:11:34+00:00" + "time": "2024-11-09T15:12:26+00:00" }, { "name": "phpspec/prophecy", From d9e2ecff54fba52489e393ea5168a1d908d968f8 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 11 Nov 2024 16:45:17 +0900 Subject: [PATCH 30/30] Remove get document from worker --- src/Appwrite/Platform/Workers/Migrations.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index d430d0eb67..4b1926ed26 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -268,8 +268,6 @@ class Migrations extends Action $transfer = $source = $destination = null; try { - $migration = $this->dbForProject->getDocument('migrations', $migration->getId()); - if ( $migration->getAttribute('source') === SourceAppwrite::getName() && empty($migration->getAttribute('credentials', []))