diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index cf5a63da39..46c60e0133 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -9,8 +9,6 @@ use Appwrite\Enums\BuildRuntime; use Appwrite\Enums\Compression; use Appwrite\Enums\Framework; use Appwrite\Enums\PasswordHash; -use Appwrite\Enums\ProjectProtocolId; -use Appwrite\Enums\ProjectServiceId; use Appwrite\Enums\Runtime; use Appwrite\Enums\SmtpEncryption; use Appwrite\InputFile; @@ -3195,9 +3193,9 @@ class Appwrite extends Destination $project = $this->dbForPlatform->getDocument('projects', $this->projectId); $apis = $project->getAttribute('apis', []); - $apis[(string) ProjectProtocolId::REST()] = $resource->getRest(); - $apis[(string) ProjectProtocolId::GRAPHQL()] = $resource->getGraphql(); - $apis[(string) ProjectProtocolId::WEBSOCKET()] = $resource->getWebsocket(); + foreach ($resource->getProtocols() as $protocolId => $enabled) { + $apis[$protocolId] = (bool) $enabled; + } $this->dbForPlatform->getAuthorization()->skip(fn () => $this->dbForPlatform->updateDocument( 'projects', @@ -3230,23 +3228,9 @@ class Appwrite extends Destination $project = $this->dbForPlatform->getDocument('projects', $this->projectId); $services = $project->getAttribute('services', []); - $services[(string) ProjectServiceId::ACCOUNT()] = $resource->getAccount(); - $services[(string) ProjectServiceId::AVATARS()] = $resource->getAvatars(); - $services[(string) ProjectServiceId::DATABASES()] = $resource->getDatabases(); - $services[(string) ProjectServiceId::TABLESDB()] = $resource->getTablesdb(); - $services[(string) ProjectServiceId::LOCALE()] = $resource->getLocale(); - $services[(string) ProjectServiceId::HEALTH()] = $resource->getHealth(); - $services[(string) ProjectServiceId::PROJECT()] = $resource->getProject(); - $services[(string) ProjectServiceId::STORAGE()] = $resource->getStorage(); - $services[(string) ProjectServiceId::TEAMS()] = $resource->getTeams(); - $services[(string) ProjectServiceId::USERS()] = $resource->getUsers(); - $services[(string) ProjectServiceId::VCS()] = $resource->getVcs(); - $services[(string) ProjectServiceId::SITES()] = $resource->getSites(); - $services[(string) ProjectServiceId::FUNCTIONS()] = $resource->getFunctions(); - $services[(string) ProjectServiceId::PROXY()] = $resource->getProxy(); - $services[(string) ProjectServiceId::GRAPHQL()] = $resource->getGraphql(); - $services[(string) ProjectServiceId::MIGRATIONS()] = $resource->getMigrations(); - $services[(string) ProjectServiceId::MESSAGING()] = $resource->getMessaging(); + foreach ($resource->getServices() as $serviceId => $enabled) { + $services[$serviceId] = (bool) $enabled; + } $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 1d65251684..c609ef093f 100644 --- a/src/Migration/Resources/Settings/Protocols.php +++ b/src/Migration/Resources/Settings/Protocols.php @@ -7,16 +7,17 @@ use Utopia\Migration\Transfer; /** * Singleton resource representing the project's exposed API protocols - * (REST, GraphQL, WebSocket). One per project; destination flips each - * via Project::updateProtocol(). + * (REST, GraphQL, WebSocket), keyed by ProtocolId value. One per project; + * destination merges each entry into the project's protocols map. */ class Protocols extends Resource { + /** + * @param array $protocols Map of ProtocolId string → enabled flag. + */ public function __construct( string $id, - private readonly bool $rest = true, - private readonly bool $graphql = true, - private readonly bool $websocket = true, + private readonly array $protocols = [], string $createdAt = '', string $updatedAt = '', ) { @@ -32,9 +33,7 @@ class Protocols extends Resource { return new self( $array['id'], - (bool) ($array['rest'] ?? true), - (bool) ($array['graphql'] ?? true), - (bool) ($array['websocket'] ?? true), + (array) ($array['protocols'] ?? []), createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', ); @@ -47,9 +46,7 @@ class Protocols extends Resource { return [ 'id' => $this->id, - 'rest' => $this->rest, - 'graphql' => $this->graphql, - 'websocket' => $this->websocket, + 'protocols' => $this->protocols, 'createdAt' => $this->createdAt, 'updatedAt' => $this->updatedAt, ]; @@ -65,18 +62,11 @@ class Protocols extends Resource return Transfer::GROUP_PROJECTS; } - public function getRest(): bool + /** + * @return array + */ + public function getProtocols(): array { - return $this->rest; - } - - public function getGraphql(): bool - { - return $this->graphql; - } - - public function getWebsocket(): bool - { - return $this->websocket; + return $this->protocols; } } diff --git a/src/Migration/Resources/Settings/Services.php b/src/Migration/Resources/Settings/Services.php index a7176ad854..b4a17fa651 100644 --- a/src/Migration/Resources/Settings/Services.php +++ b/src/Migration/Resources/Settings/Services.php @@ -6,31 +6,18 @@ use Utopia\Migration\Resource; use Utopia\Migration\Transfer; /** - * Singleton settings resource carrying the project's 17 per-service - * enable/disable flags. One per project; destination flips each via - * Project::updateService(). + * Singleton settings resource carrying the project's per-service enable/disable + * flags, keyed by ServiceId value. One per project; destination merges each + * entry into the project's services map. */ class Services extends Resource { + /** + * @param array $services Map of ServiceId string → enabled flag. + */ public function __construct( string $id, - private readonly bool $account = true, - private readonly bool $avatars = true, - private readonly bool $databases = true, - private readonly bool $tablesdb = true, - private readonly bool $locale = true, - private readonly bool $health = true, - private readonly bool $project = true, - private readonly bool $storage = true, - private readonly bool $teams = true, - private readonly bool $users = true, - private readonly bool $vcs = true, - private readonly bool $sites = true, - private readonly bool $functions = true, - private readonly bool $proxy = true, - private readonly bool $graphql = true, - private readonly bool $migrations = true, - private readonly bool $messaging = true, + private readonly array $services = [], string $createdAt = '', string $updatedAt = '', ) { @@ -46,23 +33,7 @@ class Services extends Resource { return new self( $array['id'], - (bool) ($array['account'] ?? true), - (bool) ($array['avatars'] ?? true), - (bool) ($array['databases'] ?? true), - (bool) ($array['tablesdb'] ?? true), - (bool) ($array['locale'] ?? true), - (bool) ($array['health'] ?? true), - (bool) ($array['project'] ?? true), - (bool) ($array['storage'] ?? true), - (bool) ($array['teams'] ?? true), - (bool) ($array['users'] ?? true), - (bool) ($array['vcs'] ?? true), - (bool) ($array['sites'] ?? true), - (bool) ($array['functions'] ?? true), - (bool) ($array['proxy'] ?? true), - (bool) ($array['graphql'] ?? true), - (bool) ($array['migrations'] ?? true), - (bool) ($array['messaging'] ?? true), + (array) ($array['services'] ?? []), createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', ); @@ -75,23 +46,7 @@ class Services extends Resource { return [ 'id' => $this->id, - 'account' => $this->account, - 'avatars' => $this->avatars, - 'databases' => $this->databases, - 'tablesdb' => $this->tablesdb, - 'locale' => $this->locale, - 'health' => $this->health, - 'project' => $this->project, - 'storage' => $this->storage, - 'teams' => $this->teams, - 'users' => $this->users, - 'vcs' => $this->vcs, - 'sites' => $this->sites, - 'functions' => $this->functions, - 'proxy' => $this->proxy, - 'graphql' => $this->graphql, - 'migrations' => $this->migrations, - 'messaging' => $this->messaging, + 'services' => $this->services, 'createdAt' => $this->createdAt, 'updatedAt' => $this->updatedAt, ]; @@ -107,88 +62,11 @@ class Services extends Resource return Transfer::GROUP_PROJECTS; } - public function getAccount(): bool + /** + * @return array + */ + public function getServices(): array { - return $this->account; - } - - public function getAvatars(): bool - { - return $this->avatars; - } - - public function getDatabases(): bool - { - return $this->databases; - } - - public function getTablesdb(): bool - { - return $this->tablesdb; - } - - public function getLocale(): bool - { - return $this->locale; - } - - public function getHealth(): bool - { - return $this->health; - } - - public function getProject(): bool - { - return $this->project; - } - - public function getStorage(): bool - { - return $this->storage; - } - - public function getTeams(): bool - { - return $this->teams; - } - - public function getUsers(): bool - { - return $this->users; - } - - public function getVcs(): bool - { - return $this->vcs; - } - - public function getSites(): bool - { - return $this->sites; - } - - public function getFunctions(): bool - { - return $this->functions; - } - - public function getProxy(): bool - { - return $this->proxy; - } - - public function getGraphql(): bool - { - return $this->graphql; - } - - public function getMigrations(): bool - { - return $this->migrations; - } - - public function getMessaging(): bool - { - return $this->messaging; + return $this->services; } } diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index ecee90c891..9ee09a6118 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -6,8 +6,6 @@ use Appwrite\AppwriteException; use Appwrite\Client; use Appwrite\Enums\ProjectAuthMethodId; use Appwrite\Enums\ProjectPolicyId; -use Appwrite\Enums\ProjectProtocolId; -use Appwrite\Enums\ProjectServiceId; use Appwrite\Query; use Appwrite\Services\Functions; use Appwrite\Services\Messaging; @@ -1667,28 +1665,12 @@ class Appwrite extends Source $byId = []; foreach ($project->services as $service) { - $byId[(string) $service->id] = $service->enabled; + $byId[(string) $service->id] = (bool) $service->enabled; } $services = new ServicesResource( $this->projectId, - $byId[(string) ProjectServiceId::ACCOUNT()] ?? true, - $byId[(string) ProjectServiceId::AVATARS()] ?? true, - $byId[(string) ProjectServiceId::DATABASES()] ?? true, - $byId[(string) ProjectServiceId::TABLESDB()] ?? true, - $byId[(string) ProjectServiceId::LOCALE()] ?? true, - $byId[(string) ProjectServiceId::HEALTH()] ?? true, - $byId[(string) ProjectServiceId::PROJECT()] ?? true, - $byId[(string) ProjectServiceId::STORAGE()] ?? true, - $byId[(string) ProjectServiceId::TEAMS()] ?? true, - $byId[(string) ProjectServiceId::USERS()] ?? true, - $byId[(string) ProjectServiceId::VCS()] ?? true, - $byId[(string) ProjectServiceId::SITES()] ?? true, - $byId[(string) ProjectServiceId::FUNCTIONS()] ?? true, - $byId[(string) ProjectServiceId::PROXY()] ?? true, - $byId[(string) ProjectServiceId::GRAPHQL()] ?? true, - $byId[(string) ProjectServiceId::MIGRATIONS()] ?? true, - $byId[(string) ProjectServiceId::MESSAGING()] ?? true, + $byId, createdAt: $project->createdAt, updatedAt: $project->updatedAt, ); @@ -1716,14 +1698,12 @@ class Appwrite extends Source $byId = []; foreach ($project->protocols as $protocol) { - $byId[(string) $protocol->id] = $protocol->enabled; + $byId[(string) $protocol->id] = (bool) $protocol->enabled; } $protocols = new Protocols( $this->projectId, - $byId[(string) ProjectProtocolId::REST()] ?? true, - $byId[(string) ProjectProtocolId::GRAPHQL()] ?? true, - $byId[(string) ProjectProtocolId::WEBSOCKET()] ?? true, + $byId, createdAt: $project->createdAt, updatedAt: $project->updatedAt, );