diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index f9d64f96d2..37c1614241 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -10,6 +10,7 @@ use Appwrite\Enums\BuildRuntime; use Appwrite\Enums\Compression; use Appwrite\Enums\Framework; use Appwrite\Enums\PasswordHash; +use Appwrite\Enums\ProtocolId; use Appwrite\Enums\Runtime; use Appwrite\Enums\SmtpEncryption; use Appwrite\InputFile; @@ -60,6 +61,7 @@ use Utopia\Migration\Resources\Messaging\Provider; use Utopia\Migration\Resources\Messaging\Subscriber; use Utopia\Migration\Resources\Messaging\Topic; use Utopia\Migration\Resources\Settings\ProjectVariable; +use Utopia\Migration\Resources\Settings\Protocols; use Utopia\Migration\Resources\Settings\Webhook; use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment; use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar; @@ -289,6 +291,7 @@ class Appwrite extends Destination // Settings Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, + Resource::TYPE_PROTOCOLS, // Backups Resource::TYPE_BACKUP_POLICY, @@ -3117,6 +3120,10 @@ class Appwrite extends Destination /** @var Webhook $resource */ $this->createWebhook($resource); break; + case Resource::TYPE_PROTOCOLS: + /** @var Protocols $resource */ + $this->createProtocols($resource); + break; } if ($resource->getStatus() !== Resource::STATUS_SKIPPED) { @@ -3165,6 +3172,26 @@ class Appwrite extends Destination return true; } + /** + * Flip each protocol on the destination via the SDK. Three single-field + * updates rather than one bulk write — the SDK only exposes per-protocol + * setters, mirroring upstream's per-flag controllers. + */ + protected function createProtocols(Protocols $resource): bool + { + $flags = [ + [ProtocolId::REST(), $resource->getRest()], + [ProtocolId::GRAPHQL(), $resource->getGraphql()], + [ProtocolId::WEBSOCKET(), $resource->getWebsocket()], + ]; + + foreach ($flags as [$protocol, $enabled]) { + $this->project->updateProtocol($protocol, $enabled); + } + + return true; + } + protected function createWebhook(Webhook $resource): bool { $existing = $this->dbForPlatform->findOne('webhooks', [ diff --git a/src/Migration/Resource.php b/src/Migration/Resource.php index dbd8474496..17150628b9 100644 --- a/src/Migration/Resource.php +++ b/src/Migration/Resource.php @@ -80,6 +80,7 @@ abstract class Resource implements \JsonSerializable // Settings public const TYPE_PROJECT_VARIABLE = 'project-variable'; public const TYPE_WEBHOOK = 'webhook'; + public const TYPE_PROTOCOLS = 'protocols'; // Messaging public const TYPE_SUBSCRIBER = 'subscriber'; @@ -124,6 +125,7 @@ abstract class Resource implements \JsonSerializable self::TYPE_API_KEY, self::TYPE_PROJECT_VARIABLE, self::TYPE_WEBHOOK, + self::TYPE_PROTOCOLS, self::TYPE_PROVIDER, self::TYPE_TOPIC, self::TYPE_SUBSCRIBER, diff --git a/src/Migration/Resources/Settings/Protocols.php b/src/Migration/Resources/Settings/Protocols.php new file mode 100644 index 0000000000..de0609a4f4 --- /dev/null +++ b/src/Migration/Resources/Settings/Protocols.php @@ -0,0 +1,82 @@ +id = $id; + $this->createdAt = $createdAt; + $this->updatedAt = $updatedAt; + } + + /** + * @param array $array + */ + public static function fromArray(array $array): self + { + return new self( + $array['id'], + (bool) ($array['rest'] ?? true), + (bool) ($array['graphql'] ?? true), + (bool) ($array['websocket'] ?? true), + createdAt: $array['createdAt'] ?? '', + updatedAt: $array['updatedAt'] ?? '', + ); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + return [ + 'id' => $this->id, + 'rest' => $this->rest, + 'graphql' => $this->graphql, + 'websocket' => $this->websocket, + 'createdAt' => $this->createdAt, + 'updatedAt' => $this->updatedAt, + ]; + } + + public static function getName(): string + { + return Resource::TYPE_PROTOCOLS; + } + + public function getGroup(): string + { + return Transfer::GROUP_SETTINGS; + } + + public function getRest(): bool + { + 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 8a72145cf0..0155099bcb 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -64,6 +64,7 @@ use Utopia\Migration\Resources\Messaging\Provider; use Utopia\Migration\Resources\Messaging\Subscriber; use Utopia\Migration\Resources\Messaging\Topic; use Utopia\Migration\Resources\Settings\ProjectVariable; +use Utopia\Migration\Resources\Settings\Protocols; use Utopia\Migration\Resources\Settings\Webhook; use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment; use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar; @@ -224,6 +225,7 @@ class Appwrite extends Source // Settings Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, + Resource::TYPE_PROTOCOLS, ]; } @@ -1534,6 +1536,11 @@ class Appwrite extends Source $report[Resource::TYPE_WEBHOOK] = 0; } } + + if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) { + // Singleton — there is exactly one protocols config per project. + $report[Resource::TYPE_PROTOCOLS] = 1; + } } /** @@ -1569,6 +1576,44 @@ class Appwrite extends Source )); } } + + try { + if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) { + $this->exportProtocols(); + } + } catch (\Throwable $e) { + $this->addError(new Exception( + Resource::TYPE_PROTOCOLS, + Transfer::GROUP_SETTINGS, + message: $e->getMessage(), + code: $e->getCode(), + previous: $e + )); + } + } + + /** + * Read protocol flags from the source project document. + * No SDK Project.get() exposed; using raw HTTP against /v1/project. + */ + private function exportProtocols(): void + { + $response = $this->call('GET', '/v1/project'); + + if (!\is_array($response)) { + return; + } + + $protocols = new Protocols( + $this->projectId, + (bool) ($response['protocolStatusForRest'] ?? true), + (bool) ($response['protocolStatusForGraphql'] ?? true), + (bool) ($response['protocolStatusForWebsocket'] ?? true), + createdAt: $response['$createdAt'] ?? '', + updatedAt: $response['$updatedAt'] ?? '', + ); + + $this->callback([$protocols]); } /** diff --git a/src/Migration/Transfer.php b/src/Migration/Transfer.php index bdc3c2a948..ccd3a8daad 100644 --- a/src/Migration/Transfer.php +++ b/src/Migration/Transfer.php @@ -98,6 +98,7 @@ class Transfer public const GROUP_SETTINGS_RESOURCES = [ Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, + Resource::TYPE_PROTOCOLS, ]; public const GROUP_BACKUPS_RESOURCES = [ @@ -142,6 +143,7 @@ class Transfer // Settings Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, + Resource::TYPE_PROTOCOLS, // legacy Resource::TYPE_DOCUMENT,