Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add export estimate endpoint
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Jun 3, 2022
commit bb1a0788617a381ea3e1b5bf2d47f1367747dc61
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
['name' => 'Api#migrators', 'url' => '/api/v{apiVersion}/migrators', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#status', 'url' => '/api/v{apiVersion}/status', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#cancel', 'url' => '/api/v{apiVersion}/cancel', 'verb' => 'PUT', 'requirements' => $requirements],
['name' => 'Api#exportable', 'url' => '/api/v{apiVersion}/exportable', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#estimate', 'url' => '/api/v{apiVersion}/export/estimate', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#exportable', 'url' => '/api/v{apiVersion}/export', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#export', 'url' => '/api/v{apiVersion}/export', 'verb' => 'POST', 'requirements' => $requirements],
['name' => 'Api#import', 'url' => '/api/v{apiVersion}/import', 'verb' => 'POST', 'requirements' => $requirements],
],
Expand Down
22 changes: 22 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ private function checkJobAndGetUser(): IUser {
return $user;
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
*
* @throws OCSException
*/
public function estimate(?array $migrators): DataResponse {
$user = $this->checkJobAndGetUser();

if (!is_null($migrators)) {
$this->checkMigrators($migrators);
}

try {
$size = $this->migrationService->estimateExportSize($user, $migrators);
} catch (UserMigrationException $e) {
throw new OCSException($e->getMessage());
}

return new DataResponse(['size' => $size], Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
Expand Down
10 changes: 8 additions & 2 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ public function __construct(
* @param ?string[] $filteredMigratorList If not null, only these migrators will run. If empty only the main account data will be exported.
*
* @return int Estimated size in KiB
*
* @throws UserMigrationException
*/
private function estimateExportSize(IUser $user, ?array $filteredMigratorList = null): int {
public function estimateExportSize(IUser $user, ?array $filteredMigratorList = null): int {
// 1MiB for base user data
$size = 1024;

Expand All @@ -125,7 +127,11 @@ private function estimateExportSize(IUser $user, ?array $filteredMigratorList =
continue;
}
if ($migrator instanceof ISizeEstimationMigrator) {
$migratorSize = $migrator->getEstimatedExportSize($user);
try {
$migratorSize = $migrator->getEstimatedExportSize($user);
} catch (Throwable $e) {
throw new UserMigrationException('Could not estimate export size for ' . $migrator->getDisplayName(), 0, $e);
}
$this->internalCache->set($cacheKey, $migratorSize);
$size += $migratorSize;
}
Expand Down