Revert Protocols loop refactor (review feedback: only Services was flagged)

This commit is contained in:
Prem Palanisamy committed 2026-05-28 14:32:51 +01:00
1 parent 12eee286a6
commit 7c55885aaa
3 files changed
+32 -18

No files matched your search

+4 -3
View File
@@ -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',
+23 -13
View File
@@ -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<string, bool> $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<string, bool>
*/
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;
}
}
+5 -2
View File
@@ -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,
);