refactor: convert SDK array-access to property access for typed models

SDK 22+ returns typed Models without ArrayAccess, so existing
\$response['key'] patterns fail at runtime ('Cannot use object of
type Appwrite\Models\\\*List as array'). Convert all SDK call sites
in Sources and Destinations to property access:

- \$list['total'] / ['users'|'teams'|...] -> \$list->total / ->users
- \$user['\$id'] -> \$user->id (SDK 22+ drops \$ prefix)
- \$bucket['\$permissions'] -> \$bucket->permissions

API Reader keeps its array contract (matches Database reader, used by
existing callers): converts SDK typed responses via array_map ->toArray
at the I/O boundary.

\Appwrite\Models\Deployment param types added to
exportDeploymentData and exportSiteDeploymentData.

PHPStan level 7 finds zero remaining 'Cannot access offset on
Appwrite\Models\\\*' errors. Level 3 (project default) clean.
This commit is contained in:
Prem Palanisamy committed 2026-05-08 12:11:49 +01:00
1 parent 0305666aca
commit a5195bad3e
3 files changed
+233 -224

No files matched your search

+1 -1
View File
@@ -1999,7 +1999,7 @@ class Appwrite extends Destination
$resource->getTransformations() $resource->getTransformations()
); );
$resource->setId($response['$id']); $resource->setId($response->id);
} }
$resource->setStatus(Resource::STATUS_SUCCESS); $resource->setStatus(Resource::STATUS_SUCCESS);
+193 -193
View File
@@ -288,7 +288,7 @@ class Appwrite extends Source
limit: 1 limit: 1
); );
$userList = $this->users->list($userQueries); $userList = $this->users->list($userQueries);
$report[Resource::TYPE_USER] = $userList['total']; $report[Resource::TYPE_USER] = $userList->total;
} }
if ($needTeams) { if ($needTeams) {
@@ -304,11 +304,11 @@ class Appwrite extends Source
); );
$teamList = $this->teams->list($params); $teamList = $this->teams->list($params);
$totalTeams = $teamList['total']; $totalTeams = $teamList->total;
$currentTeams = $teamList['teams']; $currentTeams = $teamList->teams;
$allTeams = array_merge($allTeams, $currentTeams); $allTeams = array_merge($allTeams, $currentTeams);
$lastTeam = $currentTeams[count($currentTeams) - 1]['$id'] ?? null; $lastTeam = end($currentTeams)?->id ?? null;
if (count($currentTeams) < self::DEFAULT_PAGE_LIMIT) { if (count($currentTeams) < self::DEFAULT_PAGE_LIMIT) {
break; break;
@@ -322,7 +322,7 @@ class Appwrite extends Source
limit: 1 limit: 1
); );
$teamList = $this->teams->list($params); $teamList = $this->teams->list($params);
$teams = ['total' => $teamList['total'], 'teams' => []]; $teams = ['total' => $teamList->total, 'teams' => []];
} }
} }
@@ -334,9 +334,9 @@ class Appwrite extends Source
$report[Resource::TYPE_MEMBERSHIP] = 0; $report[Resource::TYPE_MEMBERSHIP] = 0;
foreach ($teams['teams'] as $team) { foreach ($teams['teams'] as $team) {
$report[Resource::TYPE_MEMBERSHIP] += $this->teams->listMemberships( $report[Resource::TYPE_MEMBERSHIP] += $this->teams->listMemberships(
$team['$id'], $team->id,
[Query::limit(1)] [Query::limit(1)]
)['total']; )->total;
} }
} }
} }
@@ -364,7 +364,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_BUCKET] = $this->storage->listBuckets($bucketQueries)['total']; $report[Resource::TYPE_BUCKET] = $this->storage->listBuckets($bucketQueries)->total;
} }
if (\in_array(Resource::TYPE_FILE, $resources)) { if (\in_array(Resource::TYPE_FILE, $resources)) {
@@ -379,10 +379,10 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
cursor: $lastBucket, cursor: $lastBucket,
); );
$currentBuckets = $this->storage->listBuckets($queries)['buckets']; $currentBuckets = $this->storage->listBuckets($queries)->buckets;
$buckets = array_merge($buckets, $currentBuckets); $buckets = array_merge($buckets, $currentBuckets);
$lastBucket = $buckets[count($buckets) - 1]['$id'] ?? null; $lastBucket = $buckets[count($buckets) - 1]->id ?? null;
if (count($currentBuckets) < self::DEFAULT_PAGE_LIMIT) { if (count($currentBuckets) < self::DEFAULT_PAGE_LIMIT) {
break; break;
@@ -391,12 +391,12 @@ class Appwrite extends Source
foreach ($buckets as $bucket) { foreach ($buckets as $bucket) {
$filesResponse = $this->storage->listFiles( $filesResponse = $this->storage->listFiles(
$bucket['$id'], $bucket->id,
[Query::limit(1)] [Query::limit(1)]
); );
$report['size'] += $bucket['totalSize'] ?? 0; $report['size'] += $bucket->totalSize ?? 0;
$report[Resource::TYPE_FILE] += $filesResponse['total']; $report[Resource::TYPE_FILE] += $filesResponse->total;
} }
$report['size'] = $report['size'] / 1000 / 1000; // MB $report['size'] = $report['size'] / 1000 / 1000; // MB
@@ -419,7 +419,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_FUNCTION] = $this->functions->list($functionQueries)['total']; $report[Resource::TYPE_FUNCTION] = $this->functions->list($functionQueries)->total;
return; return;
} }
@@ -433,11 +433,11 @@ class Appwrite extends Source
); );
$funcList = $this->functions->list($params); $funcList = $this->functions->list($params);
$totalFunctions = $funcList['total']; $totalFunctions = $funcList->total;
$currentFunctions = $funcList['functions']; $currentFunctions = $funcList->functions;
$functions = array_merge($functions, $currentFunctions); $functions = array_merge($functions, $currentFunctions);
$lastFunction = $currentFunctions[count($currentFunctions) - 1]['$id'] ?? null; $lastFunction = $currentFunctions[count($currentFunctions) - 1]->id ?? null;
if (count($currentFunctions) < self::DEFAULT_PAGE_LIMIT) { if (count($currentFunctions) < self::DEFAULT_PAGE_LIMIT) {
break; break;
} }
@@ -451,7 +451,7 @@ class Appwrite extends Source
if (\in_array(Resource::TYPE_DEPLOYMENT, $resources)) { if (\in_array(Resource::TYPE_DEPLOYMENT, $resources)) {
$report[Resource::TYPE_DEPLOYMENT] = 0; $report[Resource::TYPE_DEPLOYMENT] = 0;
foreach ($functions as $function) { foreach ($functions as $function) {
if (!empty($function['deploymentId'])) { if (!empty($function->deploymentId)) {
$report[Resource::TYPE_DEPLOYMENT] += 1; $report[Resource::TYPE_DEPLOYMENT] += 1;
} }
} }
@@ -461,7 +461,7 @@ class Appwrite extends Source
$report[Resource::TYPE_ENVIRONMENT_VARIABLE] = 0; $report[Resource::TYPE_ENVIRONMENT_VARIABLE] = 0;
foreach ($functions as $function) { foreach ($functions as $function) {
// function model contains `vars`, we don't need to fetch the list again. // function model contains `vars`, we don't need to fetch the list again.
$report[Resource::TYPE_ENVIRONMENT_VARIABLE] += count($function['vars'] ?? []); $report[Resource::TYPE_ENVIRONMENT_VARIABLE] += count($function->vars ?? []);
} }
} }
} }
@@ -482,7 +482,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_SITE] = $this->sites->list($siteQueries)['total']; $report[Resource::TYPE_SITE] = $this->sites->list($siteQueries)->total;
return; return;
} }
@@ -496,15 +496,15 @@ class Appwrite extends Source
); );
$siteList = $this->sites->list($params); $siteList = $this->sites->list($params);
$totalSites = $siteList['total']; $totalSites = $siteList->total;
$currentSites = $siteList['sites']; $currentSites = $siteList->sites;
$sites = array_merge($sites, $currentSites); $sites = array_merge($sites, $currentSites);
if (count($currentSites) === 0 || count($currentSites) < self::DEFAULT_PAGE_LIMIT) { if (count($currentSites) === 0 || count($currentSites) < self::DEFAULT_PAGE_LIMIT) {
break; break;
} }
$lastSite = $currentSites[count($currentSites) - 1]['$id']; $lastSite = $currentSites[count($currentSites) - 1]->id;
} }
} }
@@ -515,7 +515,7 @@ class Appwrite extends Source
if (\in_array(Resource::TYPE_SITE_DEPLOYMENT, $resources)) { if (\in_array(Resource::TYPE_SITE_DEPLOYMENT, $resources)) {
$report[Resource::TYPE_SITE_DEPLOYMENT] = 0; $report[Resource::TYPE_SITE_DEPLOYMENT] = 0;
foreach ($sites as $site) { foreach ($sites as $site) {
if (!empty($site['deploymentId'])) { if (!empty($site->deploymentId)) {
$report[Resource::TYPE_SITE_DEPLOYMENT] += 1; $report[Resource::TYPE_SITE_DEPLOYMENT] += 1;
} }
} }
@@ -524,8 +524,8 @@ class Appwrite extends Source
if (\in_array(Resource::TYPE_SITE_VARIABLE, $resources)) { if (\in_array(Resource::TYPE_SITE_VARIABLE, $resources)) {
$report[Resource::TYPE_SITE_VARIABLE] = 0; $report[Resource::TYPE_SITE_VARIABLE] = 0;
foreach ($sites as $site) { foreach ($sites as $site) {
$variables = $this->sites->listVariables($site['$id']); $variables = $this->sites->listVariables($site->id);
$report[Resource::TYPE_SITE_VARIABLE] += $variables['total'] ?? 0; $report[Resource::TYPE_SITE_VARIABLE] += $variables->total ?? 0;
} }
} }
} }
@@ -603,27 +603,27 @@ class Appwrite extends Source
} }
$response = $this->users->list($queries); $response = $this->users->list($queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['users'] as $user) { foreach ($response->users as $user) {
$users[] = new User( $users[] = new User(
$user['$id'], $user->id,
empty($user['email']) ? null : $user['email'], empty($user->email) ? null : $user->email,
empty($user['name']) ? null : $user['name'], empty($user->name) ? null : $user->name,
$user['password'] ? new Hash($user['password'], algorithm: $user['hash']) : null, $user->password ? new Hash($user->password, algorithm: $user->hash) : null,
empty($user['phone']) ? null : $user['phone'], empty($user->phone) ? null : $user->phone,
$user['labels'] ?? [], $user->labels ?? [],
'', '',
$user['emailVerification'] ?? false, $user->emailVerification ?? false,
$user['phoneVerification'] ?? false, $user->phoneVerification ?? false,
!$user['status'], !$user->status,
$user['prefs'] ?? [], $user->prefs ?? [],
$user['targets'] ?? [], $user->targets ?? [],
); );
$lastDocument = $user['$id']; $lastDocument = $user->id;
} }
$this->callback($users); $this->callback($users);
@@ -657,18 +657,18 @@ class Appwrite extends Source
} }
$response = $this->teams->list($queries); $response = $this->teams->list($queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['teams'] as $team) { foreach ($response->teams as $team) {
$teams[] = new Team( $teams[] = new Team(
$team['$id'], $team->id,
$team['name'], $team->name,
$team['prefs'], $team->prefs,
); );
$lastDocument = $team['$id']; $lastDocument = $team->id;
} }
$this->callback($teams); $this->callback($teams);
@@ -709,25 +709,25 @@ class Appwrite extends Source
$response = $this->teams->listMemberships($team->getId(), $queries); $response = $this->teams->listMemberships($team->getId(), $queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['memberships'] as $membership) { foreach ($response->memberships as $membership) {
$user = $cacheUsers[$membership['userId']] ?? null; $user = $cacheUsers[$membership->userId] ?? null;
if ($user === null) { if ($user === null) {
throw new \Exception('User not found', Exception::CODE_NOT_FOUND); throw new \Exception('User not found', Exception::CODE_NOT_FOUND);
} }
$memberships[] = new Membership( $memberships[] = new Membership(
$membership['$id'], $membership->id,
$team, $team,
$user, $user,
$membership['roles'], $membership->roles,
$membership['confirm'] $membership->confirm
); );
$lastDocument = $membership['$id']; $lastDocument = $membership->id;
} }
$this->callback($memberships); $this->callback($memberships);
@@ -1245,20 +1245,20 @@ class Appwrite extends Source
$convertedBuckets = []; $convertedBuckets = [];
foreach ($buckets['buckets'] as $bucket) { foreach ($buckets->buckets as $bucket) {
$bucket = new Bucket( $bucket = new Bucket(
$bucket['$id'], $bucket->id,
$bucket['name'], $bucket->name,
$bucket['$permissions'], $bucket->permissions,
$bucket['fileSecurity'], $bucket->fileSecurity,
$bucket['enabled'], $bucket->enabled,
$bucket['maximumFileSize'], $bucket->maximumFileSize,
$bucket['allowedFileExtensions'], $bucket->allowedFileExtensions,
$bucket['compression'], $bucket->compression,
$bucket['encryption'], $bucket->encryption,
$bucket['antivirus'], $bucket->antivirus,
false, false,
$bucket['transformations'] ?? false, $bucket->transformations ?? false,
); );
$convertedBuckets[] = $bucket; $convertedBuckets[] = $bucket;
} }
@@ -1293,31 +1293,31 @@ class Appwrite extends Source
$queries $queries
); );
foreach ($response['files'] as $file) { foreach ($response->files as $file) {
try { try {
$this->exportFileData(new File( $this->exportFileData(new File(
$file['$id'], $file->id,
$bucket, $bucket,
$file['name'], $file->name,
$file['signature'], $file->signature,
$file['mimeType'], $file->mimeType,
$file['$permissions'], $file->permissions,
$file['sizeOriginal'], $file->sizeOriginal,
)); ));
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->addError(new Exception( $this->addError(new Exception(
resourceName: Resource::TYPE_FILE, resourceName: Resource::TYPE_FILE,
resourceGroup: Transfer::GROUP_STORAGE, resourceGroup: Transfer::GROUP_STORAGE,
resourceId: $file['$id'], resourceId: $file->id,
message: $e->getMessage(), message: $e->getMessage(),
code: $e->getCode() code: $e->getCode()
)); ));
} }
$lastDocument = $file['$id']; $lastDocument = $file->id;
} }
if (count($response['files']) < $batchSize) { if (count($response->files) < $batchSize) {
break; break;
} }
} }
@@ -1463,40 +1463,40 @@ class Appwrite extends Source
$response = $this->functions->list($queries); $response = $this->functions->list($queries);
if ($response['total'] === 0) { if ($response->total === 0) {
return; return;
} }
$functions = []; $functions = [];
$convertedResources = []; $convertedResources = [];
foreach ($response['functions'] as $function) { foreach ($response->functions as $function) {
$convertedFunc = new Func( $convertedFunc = new Func(
$function['$id'], $function->id,
$function['name'], $function->name,
$function['runtime'], $function->runtime,
$function['execute'], $function->execute,
$function['enabled'], $function->enabled,
$function['events'], $function->events,
$function['schedule'], $function->schedule,
$function['timeout'], $function->timeout,
$function['deploymentId'] ?? '', $function->deploymentId ?? '',
$function['entrypoint'], $function->entrypoint,
$function['commands'] ?? '', $function->commands ?? '',
$function['logging'] ?? true, $function->logging ?? true,
$function['scopes'] ?? [], $function->scopes ?? [],
$function['specification'] ?? '', $function->specification ?? '',
); );
$functions[] = $convertedFunc; $functions[] = $convertedFunc;
$convertedResources[] = $convertedFunc; $convertedResources[] = $convertedFunc;
foreach ($function['vars'] as $var) { foreach ($function->vars as $var) {
$convertedResources[] = new EnvVar( $convertedResources[] = new EnvVar(
$var['$id'], $var->id,
$convertedFunc, $convertedFunc,
$var['key'], $var->key,
$var['value'], $var->value,
); );
} }
} }
@@ -1551,17 +1551,17 @@ class Appwrite extends Source
$queries $queries
); );
foreach ($response['deployments'] as $deployment) { foreach ($response->deployments as $deployment) {
try { try {
$this->exportDeploymentData($func, $deployment); $this->exportDeploymentData($func, $deployment);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$func->setStatus(Resource::STATUS_ERROR, $e->getMessage()); $func->setStatus(Resource::STATUS_ERROR, $e->getMessage());
} }
$lastDocument = $deployment['$id']; $lastDocument = $deployment->id;
} }
if (count($response['deployments']) < $batchSize) { if (count($response->deployments) < $batchSize) {
break; break;
} }
} }
@@ -1571,7 +1571,7 @@ class Appwrite extends Source
/** /**
* @throws \Exception * @throws \Exception
*/ */
private function exportDeploymentData(Func $func, array $deployment): void private function exportDeploymentData(Func $func, \Appwrite\Models\Deployment $deployment): void
{ {
// Set the chunk size (5MB) // Set the chunk size (5MB)
$start = 0; $start = 0;
@@ -1582,7 +1582,7 @@ class Appwrite extends Source
$this->call( $this->call(
'HEAD', 'HEAD',
"/functions/{$func->getId()}/deployments/{$deployment['$id']}/download", "/functions/{$func->getId()}/deployments/{$deployment->id}/download",
[], [],
[], [],
$responseHeaders $responseHeaders
@@ -1592,7 +1592,7 @@ class Appwrite extends Source
if (!array_key_exists('content-length', $responseHeaders)) { if (!array_key_exists('content-length', $responseHeaders)) {
$file = $this->call( $file = $this->call(
'GET', 'GET',
"/functions/{$func->getId()}/deployments/{$deployment['$id']}/download", "/functions/{$func->getId()}/deployments/{$deployment->id}/download",
[], [],
[], [],
$responseHeaders $responseHeaders
@@ -1605,14 +1605,14 @@ class Appwrite extends Source
} }
$deployment = new Deployment( $deployment = new Deployment(
$deployment['$id'], $deployment->id,
$func, $func,
$size, $size,
$deployment['entrypoint'], $deployment->entrypoint,
$start, $start,
$end, $end,
$file, $file,
$deployment['activate'] $deployment->activate
); );
$deployment->setSequence($deployment->getId()); $deployment->setSequence($deployment->getId());
@@ -1628,14 +1628,14 @@ class Appwrite extends Source
} }
$deployment = new Deployment( $deployment = new Deployment(
$deployment['$id'], $deployment->id,
$func, $func,
$fileSize, $fileSize,
$deployment['entrypoint'], $deployment->entrypoint,
$start, $start,
$end, $end,
'', '',
$deployment['activate'] $deployment->activate
); );
$deployment->setSequence($deployment->getId()); $deployment->setSequence($deployment->getId());
@@ -1680,7 +1680,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_PROVIDER] = $this->messaging->listProviders($providerQueries)['total']; $report[Resource::TYPE_PROVIDER] = $this->messaging->listProviders($providerQueries)->total;
} }
if (\in_array(Resource::TYPE_TOPIC, $resources)) { if (\in_array(Resource::TYPE_TOPIC, $resources)) {
@@ -1689,7 +1689,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_TOPIC] = $this->messaging->listTopics($topicQueries)['total']; $report[Resource::TYPE_TOPIC] = $this->messaging->listTopics($topicQueries)->total;
} }
if (\in_array(Resource::TYPE_SUBSCRIBER, $resources)) { if (\in_array(Resource::TYPE_SUBSCRIBER, $resources)) {
@@ -1703,16 +1703,16 @@ class Appwrite extends Source
} }
$topicResponse = $this->messaging->listTopics($topicQueries); $topicResponse = $this->messaging->listTopics($topicQueries);
if ($topicResponse['total'] == 0 || empty($topicResponse['topics'])) { if ($topicResponse->total == 0 || empty($topicResponse->topics)) {
break; break;
} }
foreach ($topicResponse['topics'] as $topic) { foreach ($topicResponse->topics as $topic) {
$subscriberTotal += $this->messaging->listSubscribers($topic['$id'], [Query::limit(1)])['total']; $subscriberTotal += $this->messaging->listSubscribers($topic->id, [Query::limit(1)])->total;
$lastTopic = $topic['$id']; $lastTopic = $topic->id;
} }
if (\count($topicResponse['topics']) < self::DEFAULT_PAGE_LIMIT) { if (\count($topicResponse->topics) < self::DEFAULT_PAGE_LIMIT) {
break; break;
} }
} }
@@ -1726,7 +1726,7 @@ class Appwrite extends Source
resourceIds: $resourceIds, resourceIds: $resourceIds,
limit: 1 limit: 1
); );
$report[Resource::TYPE_MESSAGE] = $this->messaging->listMessages($messageQueries)['total']; $report[Resource::TYPE_MESSAGE] = $this->messaging->listMessages($messageQueries)->total;
} }
} }
@@ -1812,24 +1812,24 @@ class Appwrite extends Source
$response = $this->messaging->listProviders($queries); $response = $this->messaging->listProviders($queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['providers'] as $provider) { foreach ($response->providers as $provider) {
$providers[] = new Provider( $providers[] = new Provider(
$provider['$id'], $provider->id,
$provider['name'], $provider->name,
$provider['provider'], $provider->provider,
$provider['type'], $provider->type,
$provider['enabled'], $provider->enabled,
$provider['credentials'] ?? [], $provider->credentials ?? [],
$provider['options'] ?? [], $provider->options ?? [],
$provider['$createdAt'] ?? '', $provider->createdAt ?? '',
$provider['$updatedAt'] ?? '', $provider->updatedAt ?? '',
); );
$lastDocument = $provider['$id']; $lastDocument = $provider->id;
} }
$this->callback($providers); $this->callback($providers);
@@ -1863,20 +1863,20 @@ class Appwrite extends Source
$response = $this->messaging->listTopics($queries); $response = $this->messaging->listTopics($queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['topics'] as $topic) { foreach ($response->topics as $topic) {
$topics[] = new Topic( $topics[] = new Topic(
$topic['$id'], $topic->id,
$topic['name'], $topic->name,
$topic['subscribe'] ?? [], $topic->subscribe ?? [],
$topic['$createdAt'] ?? '', $topic->createdAt ?? '',
$topic['$updatedAt'] ?? '', $topic->updatedAt ?? '',
); );
$lastDocument = $topic['$id']; $lastDocument = $topic->id;
} }
$this->callback($topics); $this->callback($topics);
@@ -1909,23 +1909,23 @@ class Appwrite extends Source
$response = $this->messaging->listSubscribers($topic->getId(), $queries); $response = $this->messaging->listSubscribers($topic->getId(), $queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['subscribers'] as $subscriber) { foreach ($response->subscribers as $subscriber) {
$subscribers[] = new Subscriber( $subscribers[] = new Subscriber(
$subscriber['$id'], $subscriber->id,
$subscriber['topicId'], $subscriber->topicId,
$subscriber['targetId'], $subscriber->targetId,
$subscriber['userId'] ?? '', $subscriber->userId ?? '',
$subscriber['userName'] ?? '', $subscriber->userName ?? '',
$subscriber['providerType'] ?? '', $subscriber->providerType ?? '',
$subscriber['$createdAt'] ?? '', $subscriber->createdAt ?? '',
$subscriber['$updatedAt'] ?? '', $subscriber->updatedAt ?? '',
); );
$lastDocument = $subscriber['$id']; $lastDocument = $subscriber->id;
} }
$this->callback($subscribers); $this->callback($subscribers);
@@ -1960,28 +1960,28 @@ class Appwrite extends Source
$response = $this->messaging->listMessages($queries); $response = $this->messaging->listMessages($queries);
if ($response['total'] == 0) { if ($response->total == 0) {
break; break;
} }
foreach ($response['messages'] as $message) { foreach ($response->messages as $message) {
$messages[] = new Message( $messages[] = new Message(
$message['$id'], $message->id,
$message['providerType'] ?? '', $message->providerType ?? '',
$message['topics'] ?? [], $message->topics ?? [],
$message['users'] ?? [], $message->users ?? [],
$message['targets'] ?? [], $message->targets ?? [],
$message['data'] ?? [], $message->data ?? [],
$message['status'] ?? '', $message->status ?? '',
$message['scheduledAt'] ?? '', $message->scheduledAt ?? '',
$message['deliveredAt'] ?? '', $message->deliveredAt ?? '',
$message['deliveryErrors'] ?? [], $message->deliveryErrors ?? [],
$message['deliveredTotal'] ?? 0, $message->deliveredTotal ?? 0,
$message['$createdAt'] ?? '', $message->createdAt ?? '',
$message['$updatedAt'] ?? '', $message->updatedAt ?? '',
); );
$lastDocument = $message['$id']; $lastDocument = $message->id;
} }
$this->callback($messages); $this->callback($messages);
@@ -2015,40 +2015,40 @@ class Appwrite extends Source
$response = $this->sites->list($queries); $response = $this->sites->list($queries);
if ($response['total'] === 0) { if ($response->total === 0) {
return; return;
} }
$sites = []; $sites = [];
$convertedResources = []; $convertedResources = [];
foreach ($response['sites'] as $site) { foreach ($response->sites as $site) {
$convertedSite = new Site( $convertedSite = new Site(
$site['$id'], $site->id,
$site['name'], $site->name,
$site['framework'], $site->framework,
$site['buildRuntime'], $site->buildRuntime,
$site['enabled'], $site->enabled,
$site['logging'], $site->logging,
$site['timeout'], $site->timeout,
$site['installCommand'] ?? '', $site->installCommand ?? '',
$site['buildCommand'] ?? '', $site->buildCommand ?? '',
$site['outputDirectory'] ?? '', $site->outputDirectory ?? '',
$site['adapter'] ?? 'static', $site->adapter ?? 'static',
$site['fallbackFile'] ?? '', $site->fallbackFile ?? '',
$site['specification'] ?? '', $site->specification ?? '',
$site['deploymentId'] ?? '' $site->deploymentId ?? ''
); );
$sites[] = $convertedSite; $sites[] = $convertedSite;
$convertedResources[] = $convertedSite; $convertedResources[] = $convertedSite;
$variables = $this->sites->listVariables($site['$id']); $variables = $this->sites->listVariables($site->id);
foreach ($variables['variables'] ?? [] as $var) { foreach ($variables->variables ?? [] as $var) {
$convertedResources[] = new SiteEnvVar( $convertedResources[] = new SiteEnvVar(
$var['$id'], $var->id,
$convertedSite, $convertedSite,
$var['key'], $var->key,
$var['value'] $var->value
); );
} }
} }
@@ -2104,17 +2104,17 @@ class Appwrite extends Source
$queries $queries
); );
foreach ($response['deployments'] as $deployment) { foreach ($response->deployments as $deployment) {
try { try {
$this->exportSiteDeploymentData($site, $deployment); $this->exportSiteDeploymentData($site, $deployment);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$site->setStatus(Resource::STATUS_ERROR, $e->getMessage()); $site->setStatus(Resource::STATUS_ERROR, $e->getMessage());
} }
$lastDocument = $deployment['$id']; $lastDocument = $deployment->id;
} }
if (count($response['deployments']) < $batchSize) { if (count($response->deployments) < $batchSize) {
break; break;
} }
} }
@@ -2124,7 +2124,7 @@ class Appwrite extends Source
/** /**
* @throws \Exception * @throws \Exception
*/ */
private function exportSiteDeploymentData(Site $site, array $deployment): void private function exportSiteDeploymentData(Site $site, \Appwrite\Models\Deployment $deployment): void
{ {
$start = 0; $start = 0;
$end = Transfer::STORAGE_MAX_CHUNK_SIZE - 1; $end = Transfer::STORAGE_MAX_CHUNK_SIZE - 1;
@@ -2133,7 +2133,7 @@ class Appwrite extends Source
$this->call( $this->call(
'HEAD', 'HEAD',
"/sites/{$site->getId()}/deployments/{$deployment['$id']}/download", "/sites/{$site->getId()}/deployments/{$deployment->id}/download",
[], [],
[], [],
$responseHeaders $responseHeaders
@@ -2142,7 +2142,7 @@ class Appwrite extends Source
if (!\array_key_exists('content-length', $responseHeaders)) { if (!\array_key_exists('content-length', $responseHeaders)) {
$file = $this->call( $file = $this->call(
'GET', 'GET',
"/sites/{$site->getId()}/deployments/{$deployment['$id']}/download", "/sites/{$site->getId()}/deployments/{$deployment->id}/download",
[], [],
[], [],
$responseHeaders $responseHeaders
@@ -2155,13 +2155,13 @@ class Appwrite extends Source
} }
$siteDeployment = new SiteDeployment( $siteDeployment = new SiteDeployment(
$deployment['$id'], $deployment->id,
$site, $site,
$size, $size,
$start, $start,
$end, $end,
$file, $file,
$deployment['$id'] === $site->getActiveDeployment() $deployment->id === $site->getActiveDeployment()
); );
$siteDeployment->setSequence($siteDeployment->getId()); $siteDeployment->setSequence($siteDeployment->getId());
@@ -2177,13 +2177,13 @@ class Appwrite extends Source
} }
$siteDeployment = new SiteDeployment( $siteDeployment = new SiteDeployment(
$deployment['$id'], $deployment->id,
$site, $site,
$fileSize, $fileSize,
$start, $start,
$end, $end,
'', '',
$deployment['$id'] === $site->getActiveDeployment() $deployment->id === $site->getActiveDeployment()
); );
$siteDeployment->setSequence($siteDeployment->getId()); $siteDeployment->setSequence($siteDeployment->getId());
+39 -30
View File
@@ -11,6 +11,10 @@ use Utopia\Migration\Resources\Database\Table;
use Utopia\Migration\Sources\Appwrite\Reader; use Utopia\Migration\Sources\Appwrite\Reader;
/** /**
* Adapts Appwrite SDK typed models to the Reader's plain-array contract so that
* downstream callers can use array-offset syntax interchangeably with the
* Database reader (which returns utopia-php Document objects).
*
* @implements Reader<Query> * @implements Reader<Query>
*/ */
class API implements Reader class API implements Reader
@@ -51,10 +55,10 @@ class API implements Reader
} }
$databasesResponse = $this->database->list($databaseQueries); $databasesResponse = $this->database->list($databaseQueries);
$databases = $databasesResponse['databases']; $databases = \array_map(fn ($database) => $database->toArray(), $databasesResponse->databases);
if (in_array(Resource::TYPE_DATABASE, $resources)) { if (in_array(Resource::TYPE_DATABASE, $resources)) {
$report[Resource::TYPE_DATABASE] = $databasesResponse['total']; $report[Resource::TYPE_DATABASE] = $databasesResponse->total;
} }
if (count(array_intersect($resources, $relevantResources)) === 1 && if (count(array_intersect($resources, $relevantResources)) === 1 &&
@@ -71,12 +75,13 @@ class API implements Reader
$lastTable = null; $lastTable = null;
while (true) { while (true) {
$currentTables = $this->database->listTables( $tablesResponse = $this->database->listTables(
$databaseId, $databaseId,
$lastTable $lastTable
? [Query::cursorAfter($lastTable)] ? [Query::cursorAfter($lastTable)]
: [Query::limit($pageLimit)] : [Query::limit($pageLimit)]
)['tables']; );
$currentTables = \array_map(fn ($table) => $table->toArray(), $tablesResponse->tables);
$tables = \array_merge($tables, $currentTables); $tables = \array_merge($tables, $currentTables);
$lastTable = $tables[count($tables) - 1]['$id'] ?? null; $lastTable = $tables[count($tables) - 1]['$id'] ?? null;
@@ -111,7 +116,7 @@ class API implements Reader
[Query::limit(1)] [Query::limit(1)]
); );
$report[Resource::TYPE_ROW] += $rowsResponse['total']; $report[Resource::TYPE_ROW] += $rowsResponse->total;
} }
} }
} }
@@ -121,75 +126,79 @@ class API implements Reader
} }
/** /**
* @return array<array<string, mixed>>
* @throws AppwriteException * @throws AppwriteException
*/ */
public function listDatabases(array $queries = []): array public function listDatabases(array $queries = []): array
{ {
return $this->database->list($queries)['databases']; return \array_map(
fn ($database) => $database->toArray(),
$this->database->list($queries)->databases
);
} }
/** /**
* @return array<array<string, mixed>>
* @throws AppwriteException * @throws AppwriteException
*/ */
public function listTables(Database $resource, array $queries = []): array public function listTables(Database $resource, array $queries = []): array
{ {
return $this->database->listTables( return \array_map(
$resource->getId(), fn ($table) => $table->toArray(),
$queries $this->database->listTables($resource->getId(), $queries)->tables
)['tables']; );
} }
/** /**
* @param Table $resource * @return array<array<string, mixed>>
* @param array $queries
* @return array
* @throws AppwriteException * @throws AppwriteException
*/ */
public function listColumns(Table $resource, array $queries = []): array public function listColumns(Table $resource, array $queries = []): array
{ {
return $this->database->listColumns( return \array_map(
fn ($column) => $column->toArray(),
$this->database->listColumns(
$resource->getDatabase()->getId(), $resource->getDatabase()->getId(),
$resource->getId(), $resource->getId(),
$queries $queries
)['columns']; )->columns
);
} }
/** /**
* @param Table $resource * @return array<array<string, mixed>>
* @param array $queries
* @return array
* @throws AppwriteException * @throws AppwriteException
*/ */
public function listIndexes(Table $resource, array $queries = []): array public function listIndexes(Table $resource, array $queries = []): array
{ {
return $this->database->listIndexes( return \array_map(
fn ($index) => $index->toArray(),
$this->database->listIndexes(
$resource->getDatabase()->getId(), $resource->getDatabase()->getId(),
$resource->getId(), $resource->getId(),
$queries $queries
)['indexes']; )->indexes
);
} }
/** /**
* @param Table $resource * @return array<array<string, mixed>>
* @param array $queries
* @return array
* @throws AppwriteException * @throws AppwriteException
*/ */
public function listRows(Table $resource, array $queries = []): array public function listRows(Table $resource, array $queries = []): array
{ {
return $this->database->listRows( return \array_map(
fn ($row) => $row->toArray(),
$this->database->listRows(
$resource->getDatabase()->getId(), $resource->getDatabase()->getId(),
$resource->getId(), $resource->getId(),
$queries $queries
)['rows']; )->rows
);
} }
/** /**
* @param Table $resource * @return array<string, mixed>
* @param string $rowId
* @param array $queries
* @return array
* @throws AppwriteException * @throws AppwriteException
*/ */
public function getRow(Table $resource, string $rowId, array $queries = []): array public function getRow(Table $resource, string $rowId, array $queries = []): array