From 7c55885aaa04c53b57110180a303a7689480d4cf Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 28 May 2026 14:32:51 +0100 Subject: [PATCH] Revert Protocols loop refactor (review feedback: only Services was flagged) --- src/Migration/Destinations/Appwrite.php | 7 ++-- .../Resources/Settings/Protocols.php | 36 ++++++++++++------- src/Migration/Sources/Appwrite.php | 7 ++-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 46c60e0133..2b89e1be0f 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -9,6 +9,7 @@ use Appwrite\Enums\BuildRuntime; use Appwrite\Enums\Compression; use Appwrite\Enums\Framework; use Appwrite\Enums\PasswordHash; +use Appwrite\Enums\ProjectProtocolId; use Appwrite\Enums\Runtime; use Appwrite\Enums\SmtpEncryption; use Appwrite\InputFile; @@ -3193,9 +3194,9 @@ class Appwrite extends Destination $project = $this->dbForPlatform->getDocument('projects', $this->projectId); $apis = $project->getAttribute('apis', []); - foreach ($resource->getProtocols() as $protocolId => $enabled) { - $apis[$protocolId] = (bool) $enabled; - } + $apis[(string) ProjectProtocolId::REST()] = $resource->getRest(); + $apis[(string) ProjectProtocolId::GRAPHQL()] = $resource->getGraphql(); + $apis[(string) ProjectProtocolId::WEBSOCKET()] = $resource->getWebsocket(); $this->dbForPlatform->getAuthorization()->skip(fn () => $this->dbForPlatform->updateDocument( 'projects', diff --git a/src/Migration/Resources/Settings/Protocols.php b/src/Migration/Resources/Settings/Protocols.php index c609ef093f..1d65251684 100644 --- a/src/Migration/Resources/Settings/Protocols.php +++ b/src/Migration/Resources/Settings/Protocols.php @@ -7,17 +7,16 @@ use Utopia\Migration\Transfer; /** * Singleton resource representing the project's exposed API protocols - * (REST, GraphQL, WebSocket), keyed by ProtocolId value. One per project; - * destination merges each entry into the project's protocols map. + * (REST, GraphQL, WebSocket). One per project; destination flips each + * via Project::updateProtocol(). */ class Protocols extends Resource { - /** - * @param array $protocols Map of ProtocolId string → enabled flag. - */ public function __construct( string $id, - private readonly array $protocols = [], + private readonly bool $rest = true, + private readonly bool $graphql = true, + private readonly bool $websocket = true, string $createdAt = '', string $updatedAt = '', ) { @@ -33,7 +32,9 @@ class Protocols extends Resource { return new self( $array['id'], - (array) ($array['protocols'] ?? []), + (bool) ($array['rest'] ?? true), + (bool) ($array['graphql'] ?? true), + (bool) ($array['websocket'] ?? true), createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', ); @@ -46,7 +47,9 @@ class Protocols extends Resource { return [ 'id' => $this->id, - 'protocols' => $this->protocols, + 'rest' => $this->rest, + 'graphql' => $this->graphql, + 'websocket' => $this->websocket, 'createdAt' => $this->createdAt, 'updatedAt' => $this->updatedAt, ]; @@ -62,11 +65,18 @@ class Protocols extends Resource return Transfer::GROUP_PROJECTS; } - /** - * @return array - */ - public function getProtocols(): array + public function getRest(): bool { - return $this->protocols; + return $this->rest; + } + + public function getGraphql(): bool + { + return $this->graphql; + } + + public function getWebsocket(): bool + { + return $this->websocket; } } diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 9ee09a6118..c3397ac822 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -6,6 +6,7 @@ use Appwrite\AppwriteException; use Appwrite\Client; use Appwrite\Enums\ProjectAuthMethodId; use Appwrite\Enums\ProjectPolicyId; +use Appwrite\Enums\ProjectProtocolId; use Appwrite\Query; use Appwrite\Services\Functions; use Appwrite\Services\Messaging; @@ -1698,12 +1699,14 @@ class Appwrite extends Source $byId = []; foreach ($project->protocols as $protocol) { - $byId[(string) $protocol->id] = (bool) $protocol->enabled; + $byId[(string) $protocol->id] = $protocol->enabled; } $protocols = new Protocols( $this->projectId, - $byId, + $byId[(string) ProjectProtocolId::REST()] ?? true, + $byId[(string) ProjectProtocolId::GRAPHQL()] ?? true, + $byId[(string) ProjectProtocolId::WEBSOCKET()] ?? true, createdAt: $project->createdAt, updatedAt: $project->updatedAt, );