From 9b8e4dd8623bac50235ef0579754bb2f88d0b985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 4 Mar 2025 15:22:20 +0100 Subject: [PATCH 1/7] Rename active deployment path --- .../Http/Deployments/{ => Status}/Update.php | 11 ++++++----- .../Platform/Modules/Functions/Services/Http.php | 4 ++-- .../Sites/Http/Deployments/{ => Status}/Update.php | 11 ++++++----- src/Appwrite/Platform/Modules/Sites/Services/Http.php | 4 ++-- .../Services/Functions/FunctionsCustomServerTest.php | 5 +++++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 5 +++++ 6 files changed, 26 insertions(+), 14 deletions(-) rename src/Appwrite/Platform/Modules/Functions/Http/Deployments/{ => Status}/Update.php (92%) rename src/Appwrite/Platform/Modules/Sites/Http/Deployments/{ => Status}/Update.php (91%) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php similarity index 92% rename from src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php rename to src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php index 75144deefe..a26065d09a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId') - ->desc('Update deployment') + ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/status') + ->httpAlias('/v1/functions/:functionId/deployments/:deploymentId') + ->desc('Update deployment status') ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('event', 'functions.[functionId].deployments.[deploymentId].update') @@ -38,7 +39,7 @@ class Update extends Action ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( namespace: 'functions', - name: 'updateDeployment', + name: 'updateDeploymentStatus', description: <<addAction(CreateDeployment::getName(), new CreateDeployment()); $this->addAction(GetDeployment::getName(), new GetDeployment()); - $this->addAction(UpdateDeployment::getName(), new UpdateDeployment()); + $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); $this->addAction(ListDeployments::getName(), new ListDeployments()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(CreateTemplateDeployment::getName(), new CreateTemplateDeployment()); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php similarity index 91% rename from src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php rename to src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php index 846b552eb0..5119568645 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId') - ->desc('Update deployment') + ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/status') + ->httpAlias('/v1/sites/:siteId/deployments/:deploymentId') + ->desc('Update deployment status') ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('event', 'sites.[siteId].deployments.[deploymentId].update') @@ -36,7 +37,7 @@ class Update extends Action ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( namespace: 'sites', - name: 'updateDeployment', + name: 'updateDeploymentStatus', description: <<addAction(CreateVcsDeployment::getName(), new CreateVcsDeployment()); $this->addAction(GetDeployment::getName(), new GetDeployment()); $this->addAction(ListDeployments::getName(), new ListDeployments()); - $this->addAction(UpdateDeployment::getName(), new UpdateDeployment()); + $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateBuild::getName(), new CreateBuild()); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index f4cd9ca493..5ad63676fe 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1989,4 +1989,9 @@ class FunctionsCustomServerTest extends Scope $this->cleanupFunction($functionId); } + + public function testUpdateDeploymentStatus(): void + { + // TODO: Create function, create deployment A, create execution A. create deployment B, ensure function B. Activate deployment A, ensure execution A. Cleanup + } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 3e6132c845..73dd0132f7 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1747,4 +1747,9 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testUpdateDeploymentStatus(): void + { + // TODO: Create site, create deployment A, ensure site A. create dpeloyment B, ensure site B. Activate deploymnt A, ensure site A. Cleanup + } } From ea30d976a858bb99e7d332eab4c49aa7032cb752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 4 Mar 2025 16:04:37 +0100 Subject: [PATCH 2/7] Fix wrong path, implement tests --- .../Deployment}/Update.php | 10 ++-- .../Modules/Functions/Services/Http.php | 4 +- .../Status => Sites/Deployment}/Update.php | 10 ++-- .../Platform/Modules/Sites/Services/Http.php | 4 +- .../e2e/Services/Functions/FunctionsBase.php | 12 ++++ .../Functions/FunctionsCustomServerTest.php | 54 +++++++++++++++++- tests/e2e/Services/Sites/SitesBase.php | 12 ++++ .../Services/Sites/SitesCustomServerTest.php | 55 ++++++++++++++++++- 8 files changed, 145 insertions(+), 16 deletions(-) rename src/Appwrite/Platform/Modules/Functions/Http/{Deployments/Status => Functions/Deployment}/Update.php (92%) rename src/Appwrite/Platform/Modules/Sites/Http/{Deployments/Status => Sites/Deployment}/Update.php (91%) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php similarity index 92% rename from src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php rename to src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index a26065d09a..bcd62c8320 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/status') + ->setHttpPath('/v1/functions/:functionId/deployment') ->httpAlias('/v1/functions/:functionId/deployments/:deploymentId') - ->desc('Update deployment status') + ->desc('Update function\'s deployment') ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('event', 'functions.[functionId].deployments.[deploymentId].update') @@ -39,7 +39,7 @@ class Update extends Action ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( namespace: 'functions', - name: 'updateDeploymentStatus', + name: 'updateFunctionDeployment', description: <<addAction(CreateDeployment::getName(), new CreateDeployment()); $this->addAction(GetDeployment::getName(), new GetDeployment()); - $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); + $this->addAction(UpdateFunctionDeployment::getName(), new UpdateFunctionDeployment()); $this->addAction(ListDeployments::getName(), new ListDeployments()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(CreateTemplateDeployment::getName(), new CreateTemplateDeployment()); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php similarity index 91% rename from src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php rename to src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index 5119568645..4dfbee6cde 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/status') + ->setHttpPath('/v1/sites/:siteId/deployment') ->httpAlias('/v1/sites/:siteId/deployments/:deploymentId') - ->desc('Update deployment status') + ->desc('Update site\'s deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('event', 'sites.[siteId].deployments.[deploymentId].update') @@ -37,7 +37,7 @@ class Update extends Action ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( namespace: 'sites', - name: 'updateDeploymentStatus', + name: 'updateSiteDeployment', description: <<addAction(CreateVcsDeployment::getName(), new CreateVcsDeployment()); $this->addAction(GetDeployment::getName(), new GetDeployment()); $this->addAction(ListDeployments::getName(), new ListDeployments()); - $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); + $this->addAction(UpdateSiteDeployment::getName(), new UpdateSiteDeployment()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateBuild::getName(), new CreateBuild()); diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index f97245b0af..b55eea42ac 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -324,4 +324,16 @@ trait FunctionsBase return $response; } + + protected function updateFunctionDeployment(string $functionId, string $deploymentId): mixed + { + $function = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployment', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'deploymentId' => $deploymentId + ]); + + return $function; + } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 5ad63676fe..481f4b8263 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1992,6 +1992,58 @@ class FunctionsCustomServerTest extends Scope public function testUpdateDeploymentStatus(): void { - // TODO: Create function, create deployment A, create execution A. create deployment B, ensure function B. Activate deployment A, ensure execution A. Cleanup + + $functionId = $this->setupFunction([ + 'functionId' => ID::unique(), + 'runtime' => 'php-8.0', + 'name' => 'Re-activate Test', + 'entrypoint' => 'index.php', + ]); + $this->assertNotEmpty($functionId); + + $deploymentId1 = $this->setupDeployment($functionId, [ + 'code' => $this->packageFunction('php-cookie'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId1); + + $execution = $this->createExecution($functionId, [ + 'headers' => [ 'cookie' => 'cookieName=cookieValue' ] + ]); + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertNotEmpty($execution['body']['$id']); + $this->assertStringContainsString('cookieValue', $execution['body']['responseBody']); + + $deploymentId2 = $this->setupDeployment($functionId, [ + 'code' => $this->packageFunction('php'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId2); + + $execution = $this->createExecution($functionId); + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertNotEmpty($execution['body']['$id']); + $this->assertStringContainsString('UNICODE_TEST', $execution['body']['responseBody']); + + $function = $this->getFunction($functionId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId2, $function['body']['deployment']); + + $function = $this->updateFunctionDeployment($functionId, $deploymentId1); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId1, $function['body']['deployment']); + + $function = $this->getFunction($functionId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId1, $function['body']['deployment']); + + $execution = $this->createExecution($functionId, [ + 'headers' => [ 'cookie' => 'cookieName=cookieValue' ] + ]); + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertNotEmpty($execution['body']['$id']); + $this->assertStringContainsString('cookieValue', $execution['body']['responseBody']); + + $this->cleanupFunction($functionId); } } diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 6e597b31ec..e0d3696c59 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -359,4 +359,16 @@ trait SitesBase return $response; } + + protected function updateFunctionDeployment(string $siteId, string $deploymentId): mixed + { + $site = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployment', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'deploymentId' => $deploymentId + ]); + + return $site; + } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 73dd0132f7..de0e3ce0b2 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1750,6 +1750,59 @@ class SitesCustomServerTest extends Scope public function testUpdateDeploymentStatus(): void { - // TODO: Create site, create deployment A, ensure site A. create dpeloyment B, ensure site B. Activate deploymnt A, ensure site A. Cleanup + $siteId = $this->setupSite([ + 'buildRuntime' => 'ssr-22', + 'framework' => 'other', + 'name' => 'Activate test Site', + 'siteId' => ID::unique() + ]); + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + + $deploymentId1 = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('static'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId1); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + // TODO: Ensure response from static + + $deploymentId2 = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('static-spa'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId2); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + // TODO: Ensure response from static-spa + + $function = $this->getSite($siteId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId2, $function['body']['deploymentId']); + + $function = $this->updateFunctionDeployment($siteId, $deploymentId1); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId1, $function['body']['deploymentId']); + + $function = $this->getSite($siteId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId1, $function['body']['deploymentId']); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + // TODO: Ensure response from static + + $this->cleanupSite($siteId); } } From 520b96f0d93d84c219b6c465ad16531b6aec7e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 4 Mar 2025 16:12:57 +0100 Subject: [PATCH 3/7] Finish tests --- tests/e2e/Services/Sites/SitesBase.php | 2 +- .../Services/Sites/SitesCustomServerTest.php | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index e0d3696c59..08a87991b7 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -360,7 +360,7 @@ trait SitesBase return $response; } - protected function updateFunctionDeployment(string $siteId, string $deploymentId): mixed + protected function updateSiteDeployment(string $siteId, string $deploymentId): mixed { $site = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployment', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index de0e3ce0b2..9486156c23 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1754,12 +1754,15 @@ class SitesCustomServerTest extends Scope 'buildRuntime' => 'ssr-22', 'framework' => 'other', 'name' => 'Activate test Site', - 'siteId' => ID::unique() + 'siteId' => ID::unique(), + 'adapter' => 'static', ]); $this->assertNotEmpty($siteId); $domain = $this->setupSiteDomain($siteId); $this->assertNotEmpty($domain); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); $deploymentId1 = $this->setupDeployment($siteId, [ 'code' => $this->packageSite('static'), @@ -1767,11 +1770,9 @@ class SitesCustomServerTest extends Scope ]); $this->assertNotEmpty($deploymentId1); - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); $response = $proxyClient->call(Client::METHOD_GET, '/'); $this->assertEquals(200, $response['headers']['status-code']); - // TODO: Ensure response from static + $this->assertStringContainsString('Hello Appwrite', $response['body']); $deploymentId2 = $this->setupDeployment($siteId, [ 'code' => $this->packageSite('static-spa'), @@ -1779,17 +1780,15 @@ class SitesCustomServerTest extends Scope ]); $this->assertNotEmpty($deploymentId2); - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); $response = $proxyClient->call(Client::METHOD_GET, '/'); $this->assertEquals(200, $response['headers']['status-code']); - // TODO: Ensure response from static-spa + $this->assertStringContainsString('Index page', $response['body']); $function = $this->getSite($siteId); $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals($deploymentId2, $function['body']['deploymentId']); - $function = $this->updateFunctionDeployment($siteId, $deploymentId1); + $function = $this->updateSiteDeployment($siteId, $deploymentId1); $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals($deploymentId1, $function['body']['deploymentId']); @@ -1797,11 +1796,9 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals($deploymentId1, $function['body']['deploymentId']); - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); $response = $proxyClient->call(Client::METHOD_GET, '/'); $this->assertEquals(200, $response['headers']['status-code']); - // TODO: Ensure response from static + $this->assertStringContainsString('Hello Appwrite', $response['body']); $this->cleanupSite($siteId); } From dfc2e871707c35bcc65d07fa3fb39118aaf1c022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 4 Mar 2025 21:56:51 +0100 Subject: [PATCH 4/7] Upgrade http library --- composer.json | 2 +- composer.lock | 92 ++++++++++++++++++++++++--------------------------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/composer.json b/composer.json index 5f40f4d593..ca67bef867 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "utopia-php/database": "0.59.0", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "dev-fix-alias-params as 0.33.99", "utopia-php/fetch": "0.3.*", "utopia-php/image": "0.7.*", "utopia-php/locale": "0.4.*", diff --git a/composer.lock b/composer.lock index 3690e25ed0..3ed64683c9 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": "6883b3e81cfb0c5355997def668d5df2", + "content-hash": "ddd12adbfb90892b90d82377f5b47fb6", "packages": [ { "name": "adhocore/jwt", @@ -279,16 +279,16 @@ }, { "name": "brick/math", - "version": "0.12.2", + "version": "0.12.3", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "901eddb1e45a8e0f689302e40af871c181ecbe40" + "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/901eddb1e45a8e0f689302e40af871c181ecbe40", - "reference": "901eddb1e45a8e0f689302e40af871c181ecbe40", + "url": "https://api.github.com/repos/brick/math/zipball/866551da34e9a618e64a819ee1e01c20d8a588ba", + "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba", "shasum": "" }, "require": { @@ -327,7 +327,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.2" + "source": "https://github.com/brick/math/tree/0.12.3" }, "funding": [ { @@ -335,7 +335,7 @@ "type": "github" } ], - "time": "2025-02-26T10:21:45+00:00" + "time": "2025-02-28T13:11:00+00:00" }, { "name": "chillerlan/php-qrcode", @@ -2371,16 +2371,16 @@ }, { "name": "ramsey/collection", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/ramsey/collection.git", - "reference": "a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5" + "reference": "3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/collection/zipball/a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5", - "reference": "a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5", + "url": "https://api.github.com/repos/ramsey/collection/zipball/3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109", + "reference": "3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109", "shasum": "" }, "require": { @@ -2388,25 +2388,22 @@ }, "require-dev": { "captainhook/plugin-composer": "^5.3", - "ergebnis/composer-normalize": "^2.28.3", - "fakerphp/faker": "^1.21", + "ergebnis/composer-normalize": "^2.45", + "fakerphp/faker": "^1.24", "hamcrest/hamcrest-php": "^2.0", - "jangregor/phpstan-prophecy": "^1.0", - "mockery/mockery": "^1.5", + "jangregor/phpstan-prophecy": "^2.1", + "mockery/mockery": "^1.6", "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpcsstandards/phpcsutils": "^1.0.0-rc1", - "phpspec/prophecy-phpunit": "^2.0", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.9", - "phpstan/phpstan-mockery": "^1.1", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5", - "psalm/plugin-mockery": "^1.1", - "psalm/plugin-phpunit": "^0.18.4", - "ramsey/coding-standard": "^2.0.3", - "ramsey/conventional-commits": "^1.3", - "vimeo/psalm": "^5.4" + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpspec/prophecy-phpunit": "^2.3", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-mockery": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^10.5", + "ramsey/coding-standard": "^2.3", + "ramsey/conventional-commits": "^1.6", + "roave/security-advisories": "dev-latest" }, "type": "library", "extra": { @@ -2444,19 +2441,9 @@ ], "support": { "issues": "https://github.com/ramsey/collection/issues", - "source": "https://github.com/ramsey/collection/tree/2.0.0" + "source": "https://github.com/ramsey/collection/tree/2.1.0" }, - "funding": [ - { - "url": "https://github.com/ramsey", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ramsey/collection", - "type": "tidelift" - } - ], - "time": "2022-12-31T21:50:55+00:00" + "time": "2025-03-02T04:48:29+00:00" }, { "name": "ramsey/uuid", @@ -3919,16 +3906,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.17", + "version": "dev-fix-alias-params", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "73fac6fbce9f56282dba4e52a58cf836ec434644" + "reference": "5771262c147b5bc5cb1e2a7942abc929c1e09b0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/73fac6fbce9f56282dba4e52a58cf836ec434644", - "reference": "73fac6fbce9f56282dba4e52a58cf836ec434644", + "url": "https://api.github.com/repos/utopia-php/http/zipball/5771262c147b5bc5cb1e2a7942abc929c1e09b0d", + "reference": "5771262c147b5bc5cb1e2a7942abc929c1e09b0d", "shasum": "" }, "require": { @@ -3960,9 +3947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.17" + "source": "https://github.com/utopia-php/http/tree/fix-alias-params" }, - "time": "2025-02-24T17:35:48+00:00" + "time": "2025-03-04T20:30:12+00:00" }, { "name": "utopia-php/image", @@ -8804,9 +8791,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/framework", + "version": "dev-fix-alias-params", + "alias": "0.33.99", + "alias_normalized": "0.33.99.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/framework": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From ce3bff13dd0388543cb684f8006109f8cba30afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 5 Mar 2025 10:01:50 +0100 Subject: [PATCH 5/7] upgrade http lib --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index 3ed64683c9..0d39ca7340 100644 --- a/composer.lock +++ b/composer.lock @@ -709,16 +709,16 @@ }, { "name": "google/protobuf", - "version": "v4.29.3", + "version": "v4.30.0", "source": { "type": "git", "url": "https://github.com/protocolbuffers/protobuf-php.git", - "reference": "ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7" + "reference": "e1d66682f6836aa87820400f0aa07d9eb566feb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7", - "reference": "ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7", + "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/e1d66682f6836aa87820400f0aa07d9eb566feb6", + "reference": "e1d66682f6836aa87820400f0aa07d9eb566feb6", "shasum": "" }, "require": { @@ -747,9 +747,9 @@ "proto" ], "support": { - "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.29.3" + "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.30.0" }, - "time": "2025-01-08T21:00:13+00:00" + "time": "2025-03-04T22:54:49+00:00" }, { "name": "jean85/pretty-package-versions", @@ -3910,12 +3910,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "5771262c147b5bc5cb1e2a7942abc929c1e09b0d" + "reference": "1d31f755348f78004f870693b4f072e600da2e5a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/5771262c147b5bc5cb1e2a7942abc929c1e09b0d", - "reference": "5771262c147b5bc5cb1e2a7942abc929c1e09b0d", + "url": "https://api.github.com/repos/utopia-php/http/zipball/1d31f755348f78004f870693b4f072e600da2e5a", + "reference": "1d31f755348f78004f870693b4f072e600da2e5a", "shasum": "" }, "require": { @@ -3949,7 +3949,7 @@ "issues": "https://github.com/utopia-php/http/issues", "source": "https://github.com/utopia-php/http/tree/fix-alias-params" }, - "time": "2025-03-04T20:30:12+00:00" + "time": "2025-03-04T22:31:03+00:00" }, { "name": "utopia-php/image", From 46039ded2f709febb0f8a6cdb07dec3929e4b5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 5 Mar 2025 10:35:01 +0100 Subject: [PATCH 6/7] Fix rule updating --- .../Http/Functions/Deployment/Update.php | 45 +++++++++++++++++- .../Modules/Functions/Workers/Builds.php | 2 +- .../Sites/Http/Deployments/Download/Get.php | 1 - .../Sites/Http/Sites/Deployment/Update.php | 46 ++++++++++++++++++- 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index 79655c1405..a92dabbda5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Functions\Deployment; use Appwrite\Event\Event; use Appwrite\Extend\Exception; +use Appwrite\Query; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -54,6 +55,7 @@ class Update extends Action )) ->param('functionId', '', new UID(), 'Function ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->inject('project') ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') @@ -61,7 +63,7 @@ class Update extends Action ->callback([$this, 'action']); } - public function action(string $functionId, string $deploymentId, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) + public function action(string $functionId, string $deploymentId, Document $project, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) { $function = $dbForProject->getDocument('functions', $functionId); $deployment = $dbForProject->getDocument('deployments', $deploymentId); @@ -96,10 +98,51 @@ class Update extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForPlatform->updateDocument('schedules', $schedule->getId(), $schedule)); + $this->listRules($project, [ + Query::equal("automation", ["function=" . $function->getId()]), + ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule->setAttribute('value', $deployment->getId()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }); + $queueForEvents ->setParam('functionId', $function->getId()) ->setParam('deploymentId', $deployment->getId()); $response->dynamic($function, Response::MODEL_FUNCTION); } + + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void + { + $limit = 100; + $cursor = null; + + do { + $queries = \array_merge([ + Query::limit($limit), + Query::equal("projectInternalId", [$project->getInternalId()]) + ], $queries); + + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + + $results = $database->find('rules', $queries); + + $total = \count($results); + if ($total > 0) { + $cursor = $results[$total - 1]; + } + + if ($total < $limit) { + $cursor = null; + } + + foreach ($results as $document) { + if (is_callable($callback)) { + $callback($document); + } + } + } while (!\is_null($cursor)); + } } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index aa24182e9a..53556f60ba 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1177,7 +1177,7 @@ class Builds extends Action } } - protected function listRules(Document $project, array $queries, Database $database, callable $callback = null): void + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void { $limit = 100; $cursor = null; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index b1d67fe26b..f4b6b73784 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -31,7 +31,6 @@ class Get extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/download') - ->httpAlias('/v1/sites/:functionId/deployments/:deploymentId/build/download', [ 'type' => 'output' ]) ->desc('Download deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.read') diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index fb1dd82709..d090253c29 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Sites\Http\Sites\Deployment; use Appwrite\Event\Event; use Appwrite\Extend\Exception; +use Appwrite\Query; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -28,7 +29,6 @@ class Update extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/sites/:siteId/deployment') - ->httpAlias('/v1/sites/:siteId/deployments/:deploymentId') ->desc('Update site\'s deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.write') @@ -52,6 +52,7 @@ class Update extends Action )) ->param('siteId', '', new UID(), 'Site ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->inject('project') ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') @@ -59,7 +60,7 @@ class Update extends Action ->callback([$this, 'action']); } - public function action(string $siteId, string $deploymentId, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) + public function action(string $siteId, string $deploymentId, Document $project, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) { $site = $dbForProject->getDocument('sites', $siteId); $deployment = $dbForProject->getDocument('deployments', $deploymentId); @@ -86,10 +87,51 @@ class Update extends Action 'deploymentId' => $deployment->getId(), ]))); + $this->listRules($project, [ + Query::equal("automation", ["site=" . $site->getId()]), + ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule->setAttribute('value', $deployment->getId()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }); + $queueForEvents ->setParam('siteId', $site->getId()) ->setParam('deploymentId', $deployment->getId()); $response->dynamic($site, Response::MODEL_SITE); } + + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void + { + $limit = 100; + $cursor = null; + + do { + $queries = \array_merge([ + Query::limit($limit), + Query::equal("projectInternalId", [$project->getInternalId()]) + ], $queries); + + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + + $results = $database->find('rules', $queries); + + $total = \count($results); + if ($total > 0) { + $cursor = $results[$total - 1]; + } + + if ($total < $limit) { + $cursor = null; + } + + foreach ($results as $document) { + if (is_callable($callback)) { + $callback($document); + } + } + } while (!\is_null($cursor)); + } } From b29b5da00670156f0741b5f35ce7556f507ac98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 5 Mar 2025 10:48:26 +0100 Subject: [PATCH 7/7] Improve code quality --- .../Platform/Modules/Compute/Base.php | 35 ++++++++++++++++++ .../Http/Functions/Deployment/Update.php | 37 +------------------ .../Sites/Http/Sites/Deployment/Update.php | 37 +------------------ .../Services/Sites/SitesCustomServerTest.php | 6 +-- 4 files changed, 40 insertions(+), 75 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 157654c486..7880df189e 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Compute; use Appwrite\Event\Build; use Appwrite\Extend\Exception; +use Appwrite\Query; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; @@ -197,4 +198,38 @@ class Base extends Action return $deployment; } + + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void + { + $limit = 100; + $cursor = null; + + do { + $queries = \array_merge([ + Query::limit($limit), + Query::equal("projectInternalId", [$project->getInternalId()]) + ], $queries); + + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + + $results = $database->find('rules', $queries); + + $total = \count($results); + if ($total > 0) { + $cursor = $results[$total - 1]; + } + + if ($total < $limit) { + $cursor = null; + } + + foreach ($results as $document) { + if (is_callable($callback)) { + $callback($document); + } + } + } while (!\is_null($cursor)); + } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index a92dabbda5..f45aa0a108 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Functions\Deployment; use Appwrite\Event\Event; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Compute\Base; use Appwrite\Query; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -17,7 +18,7 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -class Update extends Action +class Update extends Base { use HTTP; @@ -111,38 +112,4 @@ class Update extends Action $response->dynamic($function, Response::MODEL_FUNCTION); } - - protected function listRules(Document $project, array $queries, Database $database, callable $callback): void - { - $limit = 100; - $cursor = null; - - do { - $queries = \array_merge([ - Query::limit($limit), - Query::equal("projectInternalId", [$project->getInternalId()]) - ], $queries); - - if ($cursor !== null) { - $queries[] = Query::cursorAfter($cursor); - } - - $results = $database->find('rules', $queries); - - $total = \count($results); - if ($total > 0) { - $cursor = $results[$total - 1]; - } - - if ($total < $limit) { - $cursor = null; - } - - foreach ($results as $document) { - if (is_callable($callback)) { - $callback($document); - } - } - } while (!\is_null($cursor)); - } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index d090253c29..fcb0532929 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Sites\Http\Sites\Deployment; use Appwrite\Event\Event; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Compute\Base; use Appwrite\Query; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -15,7 +16,7 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -class Update extends Action +class Update extends Base { use HTTP; @@ -100,38 +101,4 @@ class Update extends Action $response->dynamic($site, Response::MODEL_SITE); } - - protected function listRules(Document $project, array $queries, Database $database, callable $callback): void - { - $limit = 100; - $cursor = null; - - do { - $queries = \array_merge([ - Query::limit($limit), - Query::equal("projectInternalId", [$project->getInternalId()]) - ], $queries); - - if ($cursor !== null) { - $queries[] = Query::cursorAfter($cursor); - } - - $results = $database->find('rules', $queries); - - $total = \count($results); - if ($total > 0) { - $cursor = $results[$total - 1]; - } - - if ($total < $limit) { - $cursor = null; - } - - foreach ($results as $document) { - if (is_callable($callback)) { - $callback($document); - } - } - } while (!\is_null($cursor)); - } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 9486156c23..89e05cfe2f 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -767,11 +767,7 @@ class SitesCustomServerTest extends Scope */ $dateValidator = new DatetimeValidator(); - $response = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - + $response = $this->updateSiteDeployment($siteId, $deploymentId); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); $this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt']));