From: Côme Chilliet Date: Thu, 28 Apr 2022 09:47:04 +0000 (+0200) Subject: Implement getExportEstimatedSize in migrators X-Git-Tag: v25.0.0beta1~335^2~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=09917b85838d6cf8f075eadfac65a674be2c4316;p=nextcloud-server.git Implement getExportEstimatedSize in migrators Signed-off-by: Côme Chilliet --- diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index 015ce6faa86..e6383bcc1dd 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -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} */ diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index aed41e5c82f..068500a1ba7 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -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} */ diff --git a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php index dbc6267eb3a..721ca59f929 100644 --- a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php +++ b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php @@ -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} */ diff --git a/apps/settings/lib/UserMigration/AccountMigrator.php b/apps/settings/lib/UserMigration/AccountMigrator.php index 7b60a101cee..733d4a0b75d 100644 --- a/apps/settings/lib/UserMigration/AccountMigrator.php +++ b/apps/settings/lib/UserMigration/AccountMigrator.php @@ -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} */ diff --git a/lib/public/UserMigration/IMigrator.php b/lib/public/UserMigration/IMigrator.php index b7ad382bef2..6915e9b18a7 100644 --- a/lib/public/UserMigration/IMigrator.php +++ b/lib/public/UserMigration/IMigrator.php @@ -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