Fold email templates into projects group (rename TYPE_EMAIL_TEMPLATE -> TYPE_PROJECT_EMAIL_TEMPLATE; drop GROUP_TEMPLATES)

This commit is contained in:
Prem Palanisamy committed 2026-05-28 15:47:44 +01:00
commit ed02f85d1f
17 files changed
+185 -421

No files matched your search

+26 -56
View File
@@ -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;
@@ -299,23 +298,21 @@ 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,
Resource::TYPE_PROJECT_EMAIL_TEMPLATE,
// Backups
Resource::TYPE_BACKUP_POLICY,
// Domains
Resource::TYPE_RULE,
// Templates
Resource::TYPE_EMAIL_TEMPLATE,
];
}
@@ -474,9 +471,8 @@ 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),
Transfer::GROUP_TEMPLATES => $this->importTemplatesResource($resource),
default => throw new \Exception('Invalid resource group', Exception::CODE_VALIDATION),
};
} catch (\Throwable $e) {
@@ -3127,6 +3123,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) {
@@ -3136,32 +3140,28 @@ 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);
case Resource::TYPE_PROJECT_EMAIL_TEMPLATE:
/** @var EmailTemplate $resource */
$this->createEmailTemplate($resource);
break;
}
@@ -3191,22 +3191,6 @@ class Appwrite extends Destination
return $resource;
}
public function importTemplatesResource(Resource $resource): Resource
{
switch ($resource->getName()) {
case Resource::TYPE_EMAIL_TEMPLATE:
/** @var EmailTemplate $resource */
$this->createEmailTemplate($resource);
break;
}
if ($resource->getStatus() !== Resource::STATUS_SKIPPED) {
$resource->setStatus(Resource::STATUS_SUCCESS);
}
return $resource;
}
protected function createProjectVariable(ProjectVariable $resource): bool
{
$existing = $this->dbForProject->findOne('variables', [
@@ -3286,23 +3270,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',
+11 -13
View File
@@ -78,17 +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';
// Templates
public const TYPE_EMAIL_TEMPLATE = 'email-template';
// 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';
public const TYPE_PROJECT_EMAIL_TEMPLATE = 'project-email-template';
// Domains
public const TYPE_RULE = 'rule';
@@ -135,14 +133,14 @@ 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_PROJECT_EMAIL_TEMPLATE,
self::TYPE_RULE,
self::TYPE_EMAIL_TEMPLATE,
self::TYPE_PROVIDER,
self::TYPE_TOPIC,
self::TYPE_SUBSCRIBER,
+2 -2
View File
@@ -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;
}
/**
@@ -58,7 +58,7 @@ class ProjectVariable extends Resource
public function getGroup(): string
{
return Transfer::GROUP_SETTINGS;
return Transfer::GROUP_PROJECTS;
}
public function getKey(): string
@@ -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
+1 -1
View File
@@ -79,7 +79,7 @@ class SMTP extends Resource
public function getGroup(): string
{
return Transfer::GROUP_SETTINGS;
return Transfer::GROUP_INTEGRATIONS;
}
public function getEnabled(): bool
+16 -138
View File
@@ -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<string, bool> $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<string, bool>
*/
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;
}
}
+1 -1
View File
@@ -73,7 +73,7 @@ class Webhook extends Resource
public function getGroup(): string
{
return Transfer::GROUP_SETTINGS;
return Transfer::GROUP_INTEGRATIONS;
}
public function getWebhookName(): string
@@ -72,12 +72,12 @@ class EmailTemplate extends Resource
public static function getName(): string
{
return Resource::TYPE_EMAIL_TEMPLATE;
return Resource::TYPE_PROJECT_EMAIL_TEMPLATE;
}
public function getGroup(): string
{
return Transfer::GROUP_TEMPLATES;
return Transfer::GROUP_PROJECTS;
}
public function getTemplateId(): string
+6 -23
View File
@@ -56,7 +56,7 @@ abstract class Source extends Target
return static::$defaultBatchSize;
}
public function getSettingsBatchSize(): int
public function getProjectsBatchSize(): int
{
return static::$defaultBatchSize;
}
@@ -66,11 +66,6 @@ abstract class Source extends Target
return static::$defaultBatchSize;
}
public function getTemplatesBatchSize(): int
{
return static::$defaultBatchSize;
}
/**
* @param array<Resource> $resources
* @return void
@@ -136,9 +131,8 @@ 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,
Transfer::GROUP_TEMPLATES => Transfer::GROUP_TEMPLATES_RESOURCES,
];
foreach ($mapping as $group => $resources) {
@@ -179,15 +173,12 @@ 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);
break;
case Transfer::GROUP_TEMPLATES:
$this->exportGroupTemplates($this->getTemplatesBatchSize(), $resources);
break;
}
}
}
@@ -257,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<string> $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
@@ -271,12 +262,4 @@ abstract class Source extends Target
* @param array<string> $resources Resources to export
*/
abstract protected function exportGroupDomains(int $batchSize, array $resources): void;
/**
* Export Templates Group
*
* @param int $batchSize
* @param array<string> $resources Resources to export
*/
abstract protected function exportGroupTemplates(int $batchSize, array $resources): void;
}
+94 -120
View File
@@ -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;
@@ -79,9 +78,9 @@ use Utopia\Migration\Resources\Settings\Webhook;
use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment;
use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar;
use Utopia\Migration\Resources\Sites\Site;
use Utopia\Migration\Resources\Templates\EmailTemplate;
use Utopia\Migration\Resources\Storage\Bucket;
use Utopia\Migration\Resources\Storage\File;
use Utopia\Migration\Resources\Templates\EmailTemplate;
use Utopia\Migration\Source;
use Utopia\Migration\Sources\Appwrite\Reader;
use Utopia\Migration\Sources\Appwrite\Reader\API as APIReader;
@@ -233,23 +232,21 @@ 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,
Resource::TYPE_PROJECT_EMAIL_TEMPLATE,
// Domains
Resource::TYPE_RULE,
// Templates
Resource::TYPE_EMAIL_TEMPLATE,
];
}
@@ -290,9 +287,8 @@ 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);
$this->reportTemplates($resources, $report, $resourceIds);
$report['version'] = $this->call(
'GET',
@@ -1594,20 +1590,7 @@ class Appwrite extends Source
}
}
private function reportTemplates(array $resources, array &$report, array $resourceIds = []): void
{
if (\in_array(Resource::TYPE_EMAIL_TEMPLATE, $resources)) {
try {
// listEmailTemplates is paginated by limit/offset (not cursor); pass total: true
// so the report count is accurate even if the page is empty.
$report[Resource::TYPE_EMAIL_TEMPLATE] = $this->project->listEmailTemplates([Query::limit(1)], total: true)->total;
} catch (\Throwable) {
$report[Resource::TYPE_EMAIL_TEMPLATE] = 0;
}
}
}
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(
@@ -1622,37 +1605,29 @@ 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;
$report[Resource::TYPE_PROJECT_SERVICES] = 1;
}
if (\in_array(Resource::TYPE_SMTP, $resources)) {
// Singleton — one SMTP config per project.
$report[Resource::TYPE_SMTP] = 1;
if (\in_array(Resource::TYPE_PROJECT_EMAIL_TEMPLATE, $resources)) {
try {
// listEmailTemplates is paginated by limit/offset (not cursor); pass total: true
// so the report count is accurate even if the page is empty.
$report[Resource::TYPE_PROJECT_EMAIL_TEMPLATE] = $this->project->listEmailTemplates([Query::limit(1)], total: true)->total;
} catch (\Throwable) {
$report[Resource::TYPE_PROJECT_EMAIL_TEMPLATE] = 0;
}
}
}
@@ -1660,7 +1635,7 @@ class Appwrite extends Source
* @param int $batchSize
* @param array<string> $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 {
@@ -1668,21 +1643,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
@@ -1691,13 +1652,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
@@ -1705,13 +1666,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
@@ -1719,31 +1680,31 @@ 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();
if (\in_array(Resource::TYPE_PROJECT_EMAIL_TEMPLATE, $resources)) {
try {
$this->exportEmailTemplates($batchSize);
} catch (\Throwable $e) {
$this->addError(new Exception(
Resource::TYPE_PROJECT_EMAIL_TEMPLATE,
Transfer::GROUP_PROJECTS,
message: $e->getMessage(),
code: (int) $e->getCode() ?: Exception::CODE_INTERNAL,
previous: $e
));
}
} 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
));
}
}
@@ -1753,28 +1714,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,
);
@@ -1903,23 +1848,6 @@ class Appwrite extends Source
}
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
if (\in_array(Resource::TYPE_EMAIL_TEMPLATE, $resources)) {
try {
$this->exportEmailTemplates($batchSize);
} catch (\Throwable $e) {
$this->addError(new Exception(
Resource::TYPE_EMAIL_TEMPLATE,
Transfer::GROUP_TEMPLATES,
message: $e->getMessage(),
code: (int) $e->getCode() ?: Exception::CODE_INTERNAL,
previous: $e
));
}
}
}
/**
* @throws AppwriteException
*/
@@ -2871,6 +2799,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;
}
}
/**
@@ -2930,6 +2876,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
));
}
}
/**
+1 -6
View File
@@ -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');
}
@@ -450,11 +450,6 @@ class CSV extends Source
throw new \Exception('Not Implemented');
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
throw new \Exception('Not Implemented');
}
/**
* @param callable(resource $stream, string $delimiter): void $callback
* @return void
+1 -6
View File
@@ -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');
}
@@ -837,9 +837,4 @@ class Firebase extends Source
{
throw new \Exception('Not implemented');
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
throw new \Exception('Not implemented');
}
}
+1 -6
View File
@@ -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');
}
@@ -224,11 +224,6 @@ class JSON extends Source
throw new \Exception('Not Implemented');
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
throw new \Exception('Not Implemented');
}
/**
* @throws \Exception
*/
+1 -6
View File
@@ -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');
}
@@ -972,9 +972,4 @@ class NHost extends Source
{
throw new \Exception('Not Implemented');
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
throw new \Exception('Not Implemented');
}
}
+16 -24
View File
@@ -28,12 +28,10 @@ class Transfer
public const GROUP_BACKUPS = 'backups';
public const GROUP_SETTINGS = 'settings';
public const GROUP_PROJECTS = 'projects';
public const GROUP_DOMAINS = 'domains';
public const GROUP_TEMPLATES = 'templates';
public const GROUP_AUTH_RESOURCES = [
Resource::TYPE_USER,
Resource::TYPE_TEAM,
@@ -71,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,
@@ -100,17 +100,12 @@ 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,
];
public const GROUP_TEMPLATES_RESOURCES = [
Resource::TYPE_EMAIL_TEMPLATE,
Resource::TYPE_PROJECT_PROTOCOLS,
Resource::TYPE_PROJECT_LABELS,
Resource::TYPE_PROJECT_SERVICES,
Resource::TYPE_PROJECT_EMAIL_TEMPLATE,
];
public const GROUP_BACKUPS_RESOURCES = [
@@ -156,21 +151,19 @@ 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,
Resource::TYPE_PROJECT_EMAIL_TEMPLATE,
// Domains
Resource::TYPE_RULE,
// Templates
Resource::TYPE_EMAIL_TEMPLATE,
// legacy
Resource::TYPE_DOCUMENT,
Resource::TYPE_ATTRIBUTE,
@@ -456,9 +449,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),
self::GROUP_TEMPLATES => array_merge($resources, self::GROUP_TEMPLATES_RESOURCES),
default => throw new \Exception('No service group found'),
};
}
+3 -14
View File
@@ -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);
}
}
@@ -251,15 +251,4 @@ class MockSource extends Source
$this->handleResourceTransfer(Transfer::GROUP_DOMAINS, $resource);
}
}
protected function exportGroupTemplates(int $batchSize, array $resources): void
{
foreach (Transfer::GROUP_TEMPLATES_RESOURCES as $resource) {
if (!\in_array($resource, $resources)) {
continue;
}
$this->handleResourceTransfer(Transfer::GROUP_TEMPLATES, $resource);
}
}
}