diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 9d5e013cdc..6e85db8294 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -713,10 +713,8 @@ Http::get('/v1/migrations/appwrite/report') ->param('projectID', '', new Text(512), "Source's Project ID") ->param('key', '', new Text(512), "Source's API Key") ->inject('response') - ->inject('dbForProject') - ->inject('project') - ->inject('user') - ->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response) { + ->inject('dbForPlatform') + ->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response, Database $dbForPlatform) { $appwrite = new Appwrite($projectID, $endpoint, $key); @@ -735,6 +733,25 @@ 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', ['project']), + Query::equal('resourceInternalId', [$projectInternalId]), + ]); + } + } + $response ->setStatusCode(Response::STATUS_CODE_OK) ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT); diff --git a/src/Appwrite/Utopia/Response/Model/MigrationReport.php b/src/Appwrite/Utopia/Response/Model/MigrationReport.php index 56d17d3f7f..0c82b00562 100644 --- a/src/Appwrite/Utopia/Response/Model/MigrationReport.php +++ b/src/Appwrite/Utopia/Response/Model/MigrationReport.php @@ -53,6 +53,18 @@ class MigrationReport extends Model 'default' => 0, 'example' => 20, ]) + ->addRule(Resource::TYPE_PLATFORM, [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Number of platforms to be migrated.', + 'default' => 0, + 'example' => 5, + ]) + ->addRule(Resource::TYPE_KEY, [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Number of API keys to be migrated.', + 'default' => 0, + 'example' => 10, + ]) ->addRule('size', [ 'type' => self::TYPE_INTEGER, 'description' => 'Size of files to be migrated in mb.',