Implement getExportEstimatedSize in migrators

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2022-04-28 11:47:04 +02:00 committed by backportbot-nextcloud[bot]
parent c16b72f588
commit dde192da4a
5 changed files with 69 additions and 1 deletions

View file

@ -206,6 +206,21 @@ class CalendarMigrator implements IMigrator {
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}
*/

View file

@ -193,6 +193,21 @@ class ContactsMigrator implements IMigrator {
);
}
/**
* {@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}
*/

View file

@ -63,6 +63,23 @@ class TrashbinMigrator implements IMigrator {
$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}
*/

View file

@ -68,6 +68,27 @@ class AccountMigrator implements IMigrator {
$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}
*/

View file

@ -93,7 +93,7 @@ interface IMigrator {
*
* @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