From 4350bda1370093d023ecb8a02a488bd9d242cafd Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 12 Feb 2026 15:39:28 +0000 Subject: [PATCH] Use console API key for report endpoint instead of dbForPlatform --- app/controllers/api/migrations.php | 38 +++++++++++++----------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 66852270f8..5bf4813403 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -1,5 +1,6 @@ param('projectID', '', new Text(512), "Source's Project ID") ->param('key', '', new Text(512), "Source's API Key") ->inject('response') - ->inject('dbForPlatform') - ->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response, Database $dbForPlatform) { + ->inject('dbForProject') + ->inject('project') + ->inject('user') + ->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response) { - $appwrite = new Appwrite($projectID, $endpoint, $key); + $consoleApiKey = ''; + $openSslKey = System::getEnv('_APP_OPENSSL_KEY_V1'); + if (!empty($openSslKey)) { + $jwt = new JWT($openSslKey, 'HS256', 86400, 0); + $consoleApiKey = API_KEY_DYNAMIC . '_' . $jwt->encode([ + 'projectId' => 'console', + 'scopes' => ['platforms.read', 'keys.read'], + ]); + } + + $appwrite = new Appwrite($projectID, $endpoint, $key, consoleApiKey: $consoleApiKey, sourceProjectId: $projectID); try { $report = $appwrite->report($resources); @@ -733,25 +746,6 @@ Http::get('/v1/migrations/appwrite/report') throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); } - $sourceProject = $dbForPlatform->getDocument('projects', $projectID); - - if (!$sourceProject->isEmpty()) { - $projectInternalId = $sourceProject->getSequence(); - - if (\in_array(Resource::TYPE_PLATFORM, $resources)) { - $report[Resource::TYPE_PLATFORM] = $dbForPlatform->count('platforms', [ - Query::equal('projectInternalId', [$projectInternalId]), - ]); - } - - if (\in_array(Resource::TYPE_KEY, $resources)) { - $report[Resource::TYPE_KEY] = $dbForPlatform->count('keys', [ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$projectInternalId]), - ]); - } - } - $response ->setStatusCode(Response::STATUS_CODE_OK) ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT);