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
Implement getExportEstimatedSize in migrators
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed May 30, 2022
commit 09917b85838d6cf8f075eadfac65a674be2c4316
15 changes: 15 additions & 0 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri):
return $calendarUri;
}

/**
* {@inheritDoc}
*/
public function getExportEstimatedSize(IUser $user): int {
$principalUri = $this->getPrincipalUri($user);

return array_sum(array_map(
function (ICalendar $calendar) use ($user): int {
// FIXME 1MiB by calendar, no idea if this is accurate and if we should go into more details
return 1000;
},
$this->calendarManager->getCalendarsForPrincipal($principalUri),
));
}

/**
* {@inheritDoc}
*/
Expand Down
15 changes: 15 additions & 0 deletions apps/dav/lib/UserMigration/ContactsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ private function serializeCards(array $vCards): string {
);
}

/**
* {@inheritDoc}
*/
public function getExportEstimatedSize(IUser $user): int {
$principalUri = $this->getPrincipalUri($user);

return array_sum(array_map(
function (array $addressBookInfo) use ($user): int {
// FIXME 1MiB by addressbook, no idea if this is accurate and if we should go into more details
return 1000;
},
$this->cardDavBackend->getAddressBooksForUser($principalUri),
));
}

/**
* {@inheritDoc}
*/
Expand Down
17 changes: 17 additions & 0 deletions apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ public function __construct(
$this->l10n = $l10n;
}

/**
* {@inheritDoc}
*/
public function getExportEstimatedSize(IUser $user): int {
$uid = $user->getUID();

try {
$trashbinFolder = $this->root->get('/'.$uid.'/files_trashbin');
if (!$trashbinFolder instanceof Folder) {
return 0;
}
return (int)ceil($trashbinFolder->getSize() / 1024);
} catch (\Throwable $e) {
return 0;
}
}

/**
* {@inheritDoc}
*/
Expand Down
21 changes: 21 additions & 0 deletions apps/settings/lib/UserMigration/AccountMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ public function __construct(
$this->l10n = $l10n;
}

/**
* {@inheritDoc}
*/
public function getExportEstimatedSize(IUser $user): int {
$uid = $user->getUID();

$size = 100; // 100KiB for account JSON

try {
$avatar = $this->avatarManager->getAvatar($user->getUID());
if ($avatar->isCustomAvatar()) {
$avatarFile = $avatar->getFile(-1);
$size += $avatarFile->getSize() / 1024;
}
} catch (Throwable $e) {
return 0;
}

return (int)ceil($size);
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/public/UserMigration/IMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getVersion(): int;
*
* @since 24.0.0
*/
public function getExportEstimatedSize(): int;
public function getExportEstimatedSize(IUser $user): int;

/**
* Checks whether it is able to import a version of the export format for this migrator
Expand Down