diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index aa0493ada7..42050b617c 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -10,7 +10,6 @@ use Appwrite\Enums\Compression; use Appwrite\Enums\Framework; use Appwrite\Enums\PasswordHash; use Appwrite\Enums\ProjectProtocolId; -use Appwrite\Enums\ProjectServiceId; use Appwrite\Enums\ProxyResourceType; use Appwrite\Enums\Runtime; use Appwrite\Enums\SmtpEncryption; @@ -298,15 +297,15 @@ class Appwrite extends Destination // Integrations Resource::TYPE_PLATFORM, Resource::TYPE_API_KEY, - - // Settings - Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, - Resource::TYPE_PROTOCOLS, - Resource::TYPE_LABELS, - Resource::TYPE_SERVICES, Resource::TYPE_SMTP, + // Project + Resource::TYPE_PROJECT_VARIABLE, + Resource::TYPE_PROJECT_PROTOCOLS, + Resource::TYPE_PROJECT_LABELS, + Resource::TYPE_PROJECT_SERVICES, + // Backups Resource::TYPE_BACKUP_POLICY, @@ -470,7 +469,7 @@ class Appwrite extends Destination Transfer::GROUP_SITES => $this->importSiteResource($resource), Transfer::GROUP_INTEGRATIONS => $this->importIntegrationsResource($resource), Transfer::GROUP_BACKUPS => $this->importBackupResource($resource), - Transfer::GROUP_SETTINGS => $this->importSettingsResource($resource), + Transfer::GROUP_PROJECTS => $this->importProjectsResource($resource), Transfer::GROUP_DOMAINS => $this->importDomainsResource($resource), default => throw new \Exception('Invalid resource group', Exception::CODE_VALIDATION), }; @@ -3122,6 +3121,14 @@ class Appwrite extends Destination /** @var ApiKey $resource */ $this->createApiKey($resource); break; + case Resource::TYPE_WEBHOOK: + /** @var Webhook $resource */ + $this->createWebhook($resource); + break; + case Resource::TYPE_SMTP: + /** @var SMTP $resource */ + $this->createSMTP($resource); + break; } if ($resource->getStatus() !== Resource::STATUS_SKIPPED) { @@ -3131,33 +3138,25 @@ class Appwrite extends Destination return $resource; } - public function importSettingsResource(Resource $resource): Resource + public function importProjectsResource(Resource $resource): Resource { switch ($resource->getName()) { case Resource::TYPE_PROJECT_VARIABLE: /** @var ProjectVariable $resource */ $this->createProjectVariable($resource); break; - case Resource::TYPE_WEBHOOK: - /** @var Webhook $resource */ - $this->createWebhook($resource); - break; - case Resource::TYPE_PROTOCOLS: + case Resource::TYPE_PROJECT_PROTOCOLS: /** @var Protocols $resource */ $this->createProtocols($resource); break; - case Resource::TYPE_LABELS: + case Resource::TYPE_PROJECT_LABELS: /** @var Labels $resource */ $this->createLabels($resource); break; - case Resource::TYPE_SERVICES: + case Resource::TYPE_PROJECT_SERVICES: /** @var ServicesResource $resource */ $this->createServices($resource); break; - case Resource::TYPE_SMTP: - /** @var SMTP $resource */ - $this->createSMTP($resource); - break; } if ($resource->getStatus() !== Resource::STATUS_SKIPPED) { @@ -3265,23 +3264,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/Resource.php b/src/Migration/Resource.php index 1a5e076b37..242e2e873b 100644 --- a/src/Migration/Resource.php +++ b/src/Migration/Resource.php @@ -78,15 +78,15 @@ abstract class Resource implements \JsonSerializable // Integrations public const TYPE_PLATFORM = 'platform'; public const TYPE_API_KEY = 'api-key'; - - // Settings - public const TYPE_PROJECT_VARIABLE = 'project-variable'; public const TYPE_WEBHOOK = 'webhook'; - public const TYPE_PROTOCOLS = 'protocols'; - public const TYPE_LABELS = 'labels'; - public const TYPE_SERVICES = 'services'; public const TYPE_SMTP = 'smtp'; + // Project (per-project singleton/settings resources) + public const TYPE_PROJECT_VARIABLE = 'project-variable'; + public const TYPE_PROJECT_PROTOCOLS = 'project-protocols'; + public const TYPE_PROJECT_LABELS = 'project-labels'; + public const TYPE_PROJECT_SERVICES = 'project-services'; + // Domains public const TYPE_RULE = 'rule'; @@ -132,12 +132,12 @@ abstract class Resource implements \JsonSerializable self::TYPE_POLICIES, self::TYPE_PLATFORM, self::TYPE_API_KEY, - self::TYPE_PROJECT_VARIABLE, self::TYPE_WEBHOOK, - self::TYPE_PROTOCOLS, - self::TYPE_LABELS, - self::TYPE_SERVICES, self::TYPE_SMTP, + self::TYPE_PROJECT_VARIABLE, + self::TYPE_PROJECT_PROTOCOLS, + self::TYPE_PROJECT_LABELS, + self::TYPE_PROJECT_SERVICES, self::TYPE_RULE, self::TYPE_PROVIDER, self::TYPE_TOPIC, diff --git a/src/Migration/Resources/Settings/Labels.php b/src/Migration/Resources/Settings/Labels.php index a2da658dd1..cc8c075a11 100644 --- a/src/Migration/Resources/Settings/Labels.php +++ b/src/Migration/Resources/Settings/Labels.php @@ -54,12 +54,12 @@ class Labels extends Resource public static function getName(): string { - return Resource::TYPE_LABELS; + return Resource::TYPE_PROJECT_LABELS; } public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + return Transfer::GROUP_PROJECTS; } /** diff --git a/src/Migration/Resources/Settings/ProjectVariable.php b/src/Migration/Resources/Settings/ProjectVariable.php index 1585695dfb..58146cf09e 100644 --- a/src/Migration/Resources/Settings/ProjectVariable.php +++ b/src/Migration/Resources/Settings/ProjectVariable.php @@ -58,7 +58,7 @@ class ProjectVariable extends Resource public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + return Transfer::GROUP_PROJECTS; } public function getKey(): string diff --git a/src/Migration/Resources/Settings/Protocols.php b/src/Migration/Resources/Settings/Protocols.php index de0609a4f4..1d65251684 100644 --- a/src/Migration/Resources/Settings/Protocols.php +++ b/src/Migration/Resources/Settings/Protocols.php @@ -57,12 +57,12 @@ class Protocols extends Resource public static function getName(): string { - return Resource::TYPE_PROTOCOLS; + return Resource::TYPE_PROJECT_PROTOCOLS; } public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + return Transfer::GROUP_PROJECTS; } public function getRest(): bool diff --git a/src/Migration/Resources/Settings/SMTP.php b/src/Migration/Resources/Settings/SMTP.php index 9233225dc6..ea14895c7a 100644 --- a/src/Migration/Resources/Settings/SMTP.php +++ b/src/Migration/Resources/Settings/SMTP.php @@ -79,7 +79,7 @@ class SMTP extends Resource public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + return Transfer::GROUP_INTEGRATIONS; } public function getEnabled(): bool diff --git a/src/Migration/Resources/Settings/Services.php b/src/Migration/Resources/Settings/Services.php index 3b7474c468..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, ]; @@ -99,96 +54,19 @@ class Services extends Resource public static function getName(): string { - return Resource::TYPE_SERVICES; + return Resource::TYPE_PROJECT_SERVICES; } public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + 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/Resources/Settings/Webhook.php b/src/Migration/Resources/Settings/Webhook.php index 20ba47f624..184d2482cf 100644 --- a/src/Migration/Resources/Settings/Webhook.php +++ b/src/Migration/Resources/Settings/Webhook.php @@ -73,7 +73,7 @@ class Webhook extends Resource public function getGroup(): string { - return Transfer::GROUP_SETTINGS; + return Transfer::GROUP_INTEGRATIONS; } public function getWebhookName(): string diff --git a/src/Migration/Source.php b/src/Migration/Source.php index 840f323b32..fae2272686 100644 --- a/src/Migration/Source.php +++ b/src/Migration/Source.php @@ -56,7 +56,7 @@ abstract class Source extends Target return static::$defaultBatchSize; } - public function getSettingsBatchSize(): int + public function getProjectsBatchSize(): int { return static::$defaultBatchSize; } @@ -131,7 +131,7 @@ abstract class Source extends Target Transfer::GROUP_SITES => Transfer::GROUP_SITES_RESOURCES, Transfer::GROUP_INTEGRATIONS => Transfer::GROUP_INTEGRATIONS_RESOURCES, Transfer::GROUP_BACKUPS => Transfer::GROUP_BACKUPS_RESOURCES, - Transfer::GROUP_SETTINGS => Transfer::GROUP_SETTINGS_RESOURCES, + Transfer::GROUP_PROJECTS => Transfer::GROUP_PROJECTS_RESOURCES, Transfer::GROUP_DOMAINS => Transfer::GROUP_DOMAINS_RESOURCES, ]; @@ -173,8 +173,8 @@ abstract class Source extends Target case Transfer::GROUP_BACKUPS: $this->exportGroupBackups($this->getBackupsBatchSize(), $resources); break; - case Transfer::GROUP_SETTINGS: - $this->exportGroupSettings($this->getSettingsBatchSize(), $resources); + case Transfer::GROUP_PROJECTS: + $this->exportGroupProjects($this->getProjectsBatchSize(), $resources); break; case Transfer::GROUP_DOMAINS: $this->exportGroupDomains($this->getDomainsBatchSize(), $resources); @@ -248,12 +248,12 @@ abstract class Source extends Target abstract protected function exportGroupBackups(int $batchSize, array $resources): void; /** - * Export Settings Group + * Export Projects Group * * @param int $batchSize * @param array $resources Resources to export */ - abstract protected function exportGroupSettings(int $batchSize, array $resources): void; + abstract protected function exportGroupProjects(int $batchSize, array $resources): void; /** * Export Domains Group diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 8fb948194c..c51230dd1f 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -7,7 +7,6 @@ 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; @@ -232,17 +231,17 @@ class Appwrite extends Source // Integrations Resource::TYPE_PLATFORM, Resource::TYPE_API_KEY, + Resource::TYPE_WEBHOOK, + Resource::TYPE_SMTP, // Backups Resource::TYPE_BACKUP_POLICY, - // Settings + // Project Resource::TYPE_PROJECT_VARIABLE, - Resource::TYPE_WEBHOOK, - Resource::TYPE_PROTOCOLS, - Resource::TYPE_LABELS, - Resource::TYPE_SERVICES, - Resource::TYPE_SMTP, + Resource::TYPE_PROJECT_PROTOCOLS, + Resource::TYPE_PROJECT_LABELS, + Resource::TYPE_PROJECT_SERVICES, // Domains Resource::TYPE_RULE, @@ -286,7 +285,7 @@ class Appwrite extends Source $this->reportSites($resources, $report, $resourceIds); $this->reportIntegrations($resources, $report, $resourceIds); $this->reportBackups($resources, $report, $resourceIds); - $this->reportSettings($resources, $report, $resourceIds); + $this->reportProjects($resources, $report, $resourceIds); $this->reportDomains($resources, $report, $resourceIds); $report['version'] = $this->call( @@ -1589,7 +1588,7 @@ class Appwrite extends Source } } - private function reportSettings(array $resources, array &$report, array $resourceIds = []): void + private function reportProjects(array $resources, array &$report, array $resourceIds = []): void { if (\in_array(Resource::TYPE_PROJECT_VARIABLE, $resources)) { $variableQueries = $this->buildQueries( @@ -1604,37 +1603,19 @@ class Appwrite extends Source } } - if (\in_array(Resource::TYPE_WEBHOOK, $resources)) { - $webhookQueries = $this->buildQueries( - resourceType: Resource::TYPE_WEBHOOK, - resourceIds: $resourceIds, - limit: 1 - ); - try { - $report[Resource::TYPE_WEBHOOK] = $this->webhooks->list($webhookQueries)->total; - } catch (\Throwable) { - $report[Resource::TYPE_WEBHOOK] = 0; - } - } - - if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_PROTOCOLS, $resources)) { // Singleton — there is exactly one protocols config per project. - $report[Resource::TYPE_PROTOCOLS] = 1; + $report[Resource::TYPE_PROJECT_PROTOCOLS] = 1; } - if (\in_array(Resource::TYPE_LABELS, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_LABELS, $resources)) { // Singleton — one labels array per project. - $report[Resource::TYPE_LABELS] = 1; + $report[Resource::TYPE_PROJECT_LABELS] = 1; } - if (\in_array(Resource::TYPE_SERVICES, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_SERVICES, $resources)) { // Singleton — one services config per project. - $report[Resource::TYPE_SERVICES] = 1; - } - - if (\in_array(Resource::TYPE_SMTP, $resources)) { - // Singleton — one SMTP config per project. - $report[Resource::TYPE_SMTP] = 1; + $report[Resource::TYPE_PROJECT_SERVICES] = 1; } } @@ -1642,7 +1623,7 @@ class Appwrite extends Source * @param int $batchSize * @param array $resources */ - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { if (\in_array(Resource::TYPE_PROJECT_VARIABLE, $resources)) { try { @@ -1650,21 +1631,7 @@ class Appwrite extends Source } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_PROJECT_VARIABLE, - Transfer::GROUP_SETTINGS, - message: $e->getMessage(), - code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, - previous: $e - )); - } - } - - if (\in_array(Resource::TYPE_WEBHOOK, $resources)) { - try { - $this->exportWebhooks($batchSize); - } catch (\Throwable $e) { - $this->addError(new Exception( - Resource::TYPE_WEBHOOK, - Transfer::GROUP_SETTINGS, + Transfer::GROUP_PROJECTS, message: $e->getMessage(), code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, previous: $e @@ -1673,13 +1640,13 @@ class Appwrite extends Source } try { - if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_PROTOCOLS, $resources)) { $this->exportProtocols(); } } catch (\Throwable $e) { $this->addError(new Exception( - Resource::TYPE_PROTOCOLS, - Transfer::GROUP_SETTINGS, + Resource::TYPE_PROJECT_PROTOCOLS, + Transfer::GROUP_PROJECTS, message: $e->getMessage(), code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, previous: $e @@ -1687,13 +1654,13 @@ class Appwrite extends Source } try { - if (\in_array(Resource::TYPE_LABELS, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_LABELS, $resources)) { $this->exportLabels(); } } catch (\Throwable $e) { $this->addError(new Exception( - Resource::TYPE_LABELS, - Transfer::GROUP_SETTINGS, + Resource::TYPE_PROJECT_LABELS, + Transfer::GROUP_PROJECTS, message: $e->getMessage(), code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, previous: $e @@ -1701,32 +1668,19 @@ class Appwrite extends Source } try { - if (\in_array(Resource::TYPE_SERVICES, $resources)) { + if (\in_array(Resource::TYPE_PROJECT_SERVICES, $resources)) { $this->exportServices(); } } catch (\Throwable $e) { $this->addError(new Exception( - Resource::TYPE_SERVICES, - Transfer::GROUP_SETTINGS, + Resource::TYPE_PROJECT_SERVICES, + Transfer::GROUP_PROJECTS, message: $e->getMessage(), code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, previous: $e )); } - try { - if (\in_array(Resource::TYPE_SMTP, $resources)) { - $this->exportSMTP(); - } - } catch (\Throwable $e) { - $this->addError(new Exception( - Resource::TYPE_SMTP, - Transfer::GROUP_SETTINGS, - message: $e->getMessage(), - code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, - previous: $e - )); - } } private function exportServices(): void @@ -1735,28 +1689,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, ); @@ -2788,6 +2726,24 @@ class Appwrite extends Source $report[Resource::TYPE_API_KEY] = 0; } } + + if (\in_array(Resource::TYPE_WEBHOOK, $resources)) { + $webhookQueries = $this->buildQueries( + resourceType: Resource::TYPE_WEBHOOK, + resourceIds: $resourceIds, + limit: 1 + ); + try { + $report[Resource::TYPE_WEBHOOK] = $this->webhooks->list($webhookQueries)->total; + } catch (\Throwable) { + $report[Resource::TYPE_WEBHOOK] = 0; + } + } + + if (\in_array(Resource::TYPE_SMTP, $resources)) { + // Singleton — one SMTP config per project. + $report[Resource::TYPE_SMTP] = 1; + } } /** @@ -2847,6 +2803,34 @@ class Appwrite extends Source )); } } + + if (\in_array(Resource::TYPE_WEBHOOK, $resources)) { + try { + $this->exportWebhooks($batchSize); + } catch (\Throwable $e) { + $this->addError(new Exception( + Resource::TYPE_WEBHOOK, + Transfer::GROUP_INTEGRATIONS, + message: $e->getMessage(), + code: $e->getCode(), + previous: $e + )); + } + } + + try { + if (\in_array(Resource::TYPE_SMTP, $resources)) { + $this->exportSMTP(); + } + } catch (\Throwable $e) { + $this->addError(new Exception( + Resource::TYPE_SMTP, + Transfer::GROUP_INTEGRATIONS, + message: $e->getMessage(), + code: (int) $e->getCode() ?: Exception::CODE_INTERNAL, + previous: $e + )); + } } /** diff --git a/src/Migration/Sources/CSV.php b/src/Migration/Sources/CSV.php index 4d67d55145..411a096d71 100644 --- a/src/Migration/Sources/CSV.php +++ b/src/Migration/Sources/CSV.php @@ -440,7 +440,7 @@ class CSV extends Source throw new \Exception('Not Implemented'); } - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { throw new \Exception('Not Implemented'); } diff --git a/src/Migration/Sources/Firebase.php b/src/Migration/Sources/Firebase.php index b9211663e3..9f056e2354 100644 --- a/src/Migration/Sources/Firebase.php +++ b/src/Migration/Sources/Firebase.php @@ -828,7 +828,7 @@ class Firebase extends Source throw new \Exception('Not implemented'); } - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { throw new \Exception('Not implemented'); } diff --git a/src/Migration/Sources/JSON.php b/src/Migration/Sources/JSON.php index 56464100c2..46124a093e 100644 --- a/src/Migration/Sources/JSON.php +++ b/src/Migration/Sources/JSON.php @@ -214,7 +214,7 @@ class JSON extends Source throw new \Exception('Not Implemented'); } - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { throw new \Exception('Not Implemented'); } diff --git a/src/Migration/Sources/NHost.php b/src/Migration/Sources/NHost.php index a2fafc4d68..9ac916938b 100644 --- a/src/Migration/Sources/NHost.php +++ b/src/Migration/Sources/NHost.php @@ -963,7 +963,7 @@ class NHost extends Source throw new \Exception('Not Implemented'); } - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { throw new \Exception('Not Implemented'); } diff --git a/src/Migration/Transfer.php b/src/Migration/Transfer.php index 87d318391b..8b3d163872 100644 --- a/src/Migration/Transfer.php +++ b/src/Migration/Transfer.php @@ -28,7 +28,7 @@ class Transfer public const GROUP_BACKUPS = 'backups'; - public const GROUP_SETTINGS = 'settings'; + public const GROUP_PROJECTS = 'projects'; public const GROUP_DOMAINS = 'domains'; @@ -69,6 +69,8 @@ class Transfer public const GROUP_INTEGRATIONS_RESOURCES = [ Resource::TYPE_PLATFORM, Resource::TYPE_API_KEY, + Resource::TYPE_WEBHOOK, + Resource::TYPE_SMTP, ]; public const GROUP_DOCUMENTSDB_RESOURCES = [ Resource::TYPE_DATABASE_DOCUMENTSDB, @@ -98,13 +100,11 @@ class Transfer Resource::TYPE_ATTRIBUTE ]; - public const GROUP_SETTINGS_RESOURCES = [ + public const GROUP_PROJECTS_RESOURCES = [ Resource::TYPE_PROJECT_VARIABLE, - Resource::TYPE_WEBHOOK, - Resource::TYPE_PROTOCOLS, - Resource::TYPE_LABELS, - Resource::TYPE_SERVICES, - Resource::TYPE_SMTP, + Resource::TYPE_PROJECT_PROTOCOLS, + Resource::TYPE_PROJECT_LABELS, + Resource::TYPE_PROJECT_SERVICES, ]; public const GROUP_BACKUPS_RESOURCES = [ @@ -150,15 +150,15 @@ class Transfer // Integrations Resource::TYPE_PLATFORM, Resource::TYPE_API_KEY, - - // Settings - Resource::TYPE_PROJECT_VARIABLE, Resource::TYPE_WEBHOOK, - Resource::TYPE_PROTOCOLS, - Resource::TYPE_LABELS, - Resource::TYPE_SERVICES, Resource::TYPE_SMTP, + // Project + Resource::TYPE_PROJECT_VARIABLE, + Resource::TYPE_PROJECT_PROTOCOLS, + Resource::TYPE_PROJECT_LABELS, + Resource::TYPE_PROJECT_SERVICES, + // Domains Resource::TYPE_RULE, @@ -447,8 +447,8 @@ class Transfer self::GROUP_DATABASES_VECTOR_DB => array_merge($resources, self::GROUP_VECTORSDB_RESOURCES), self::GROUP_MESSAGING => array_merge($resources, self::GROUP_MESSAGING_RESOURCES), self::GROUP_BACKUPS => array_merge($resources, self::GROUP_BACKUPS_RESOURCES), + self::GROUP_PROJECTS => array_merge($resources, self::GROUP_PROJECTS_RESOURCES), self::GROUP_DOMAINS => array_merge($resources, self::GROUP_DOMAINS_RESOURCES), - self::GROUP_SETTINGS => array_merge($resources, self::GROUP_SETTINGS_RESOURCES), default => throw new \Exception('No service group found'), }; } diff --git a/tests/Migration/Unit/Adapters/MockSource.php b/tests/Migration/Unit/Adapters/MockSource.php index d3e515c945..ad7a3996fa 100644 --- a/tests/Migration/Unit/Adapters/MockSource.php +++ b/tests/Migration/Unit/Adapters/MockSource.php @@ -230,14 +230,14 @@ class MockSource extends Source } } - protected function exportGroupSettings(int $batchSize, array $resources): void + protected function exportGroupProjects(int $batchSize, array $resources): void { - foreach (Transfer::GROUP_SETTINGS_RESOURCES as $resource) { + foreach (Transfer::GROUP_PROJECTS_RESOURCES as $resource) { if (!\in_array($resource, $resources)) { continue; } - $this->handleResourceTransfer(Transfer::GROUP_SETTINGS, $resource); + $this->handleResourceTransfer(Transfer::GROUP_PROJECTS, $resource); } }