From 09917b85838d6cf8f075eadfac65a674be2c4316 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 28 Apr 2022 11:47:04 +0200 Subject: Implement getExportEstimatedSize in migrators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/dav/lib/UserMigration/CalendarMigrator.php | 15 +++++++++++++++ apps/dav/lib/UserMigration/ContactsMigrator.php | 15 +++++++++++++++ .../lib/UserMigration/TrashbinMigrator.php | 17 +++++++++++++++++ apps/settings/lib/UserMigration/AccountMigrator.php | 21 +++++++++++++++++++++ 4 files changed, 68 insertions(+) (limited to 'apps') 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} */ -- cgit v1.2.3 From 6da413f7af5e53ce6d02a0e86a07e81593f68644 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Tue, 24 May 2022 10:01:14 +0200 Subject: Move new IMigrator method to a specific interface ISizeEstimationMigrator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/dav/lib/UserMigration/CalendarMigrator.php | 3 ++- apps/dav/lib/UserMigration/ContactsMigrator.php | 3 ++- apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php | 3 ++- apps/settings/lib/UserMigration/AccountMigrator.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index e6383bcc1dd..2345acd43fd 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -42,6 +42,7 @@ use OCP\IUser; use OCP\UserMigration\IExportDestination; use OCP\UserMigration\IImportSource; use OCP\UserMigration\IMigrator; +use OCP\UserMigration\ISizeEstimationMigrator; use OCP\UserMigration\TMigratorBasicVersionHandling; use Sabre\VObject\Component as VObjectComponent; use Sabre\VObject\Component\VCalendar; @@ -53,7 +54,7 @@ use Safe\Exceptions\StringsException; use Symfony\Component\Console\Output\OutputInterface; use Throwable; -class CalendarMigrator implements IMigrator { +class CalendarMigrator implements IMigrator, ISizeEstimationMigrator { use TMigratorBasicVersionHandling; diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index 068500a1ba7..5adf631f65e 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -39,6 +39,7 @@ use OCP\IUser; use OCP\UserMigration\IExportDestination; use OCP\UserMigration\IImportSource; use OCP\UserMigration\IMigrator; +use OCP\UserMigration\ISizeEstimationMigrator; use OCP\UserMigration\TMigratorBasicVersionHandling; use Sabre\VObject\Component\VCard; use Sabre\VObject\Parser\Parser as VObjectParser; @@ -50,7 +51,7 @@ use Safe\Exceptions\StringsException; use Symfony\Component\Console\Output\OutputInterface; use Throwable; -class ContactsMigrator implements IMigrator { +class ContactsMigrator implements IMigrator, ISizeEstimationMigrator { use TMigratorBasicVersionHandling; diff --git a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php index 721ca59f929..658f5015b0e 100644 --- a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php +++ b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php @@ -36,11 +36,12 @@ use OCP\IUser; use OCP\UserMigration\IExportDestination; use OCP\UserMigration\IImportSource; use OCP\UserMigration\IMigrator; +use OCP\UserMigration\ISizeEstimationMigrator; use OCP\UserMigration\TMigratorBasicVersionHandling; use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class TrashbinMigrator implements IMigrator { +class TrashbinMigrator implements IMigrator, ISizeEstimationMigrator { use TMigratorBasicVersionHandling; diff --git a/apps/settings/lib/UserMigration/AccountMigrator.php b/apps/settings/lib/UserMigration/AccountMigrator.php index 733d4a0b75d..79955a59fde 100644 --- a/apps/settings/lib/UserMigration/AccountMigrator.php +++ b/apps/settings/lib/UserMigration/AccountMigrator.php @@ -37,11 +37,12 @@ use OCP\IUser; use OCP\UserMigration\IExportDestination; use OCP\UserMigration\IImportSource; use OCP\UserMigration\IMigrator; +use OCP\UserMigration\ISizeEstimationMigrator; use OCP\UserMigration\TMigratorBasicVersionHandling; use Symfony\Component\Console\Output\OutputInterface; use Throwable; -class AccountMigrator implements IMigrator { +class AccountMigrator implements IMigrator, ISizeEstimationMigrator { use TMigratorBasicVersionHandling; use TAccountsHelper; -- cgit v1.2.3 From 432bc9a58523c7563d2939d179ef98203ce56f2b Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 29 Apr 2022 01:45:47 +0000 Subject: Update method name Signed-off-by: Christopher Ng --- apps/dav/lib/UserMigration/CalendarMigrator.php | 2 +- apps/dav/lib/UserMigration/ContactsMigrator.php | 2 +- apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php | 2 +- apps/settings/lib/UserMigration/AccountMigrator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index 2345acd43fd..5a296a2b527 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -210,7 +210,7 @@ class CalendarMigrator implements IMigrator, ISizeEstimationMigrator { /** * {@inheritDoc} */ - public function getExportEstimatedSize(IUser $user): int { + public function getEstimatedExportSize(IUser $user): int { $principalUri = $this->getPrincipalUri($user); return array_sum(array_map( diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index 5adf631f65e..fc498288810 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -197,7 +197,7 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator { /** * {@inheritDoc} */ - public function getExportEstimatedSize(IUser $user): int { + public function getEstimatedExportSize(IUser $user): int { $principalUri = $this->getPrincipalUri($user); return array_sum(array_map( diff --git a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php index 658f5015b0e..9c0334aa2f3 100644 --- a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php +++ b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php @@ -67,7 +67,7 @@ class TrashbinMigrator implements IMigrator, ISizeEstimationMigrator { /** * {@inheritDoc} */ - public function getExportEstimatedSize(IUser $user): int { + public function getEstimatedExportSize(IUser $user): int { $uid = $user->getUID(); try { diff --git a/apps/settings/lib/UserMigration/AccountMigrator.php b/apps/settings/lib/UserMigration/AccountMigrator.php index 79955a59fde..321889788b8 100644 --- a/apps/settings/lib/UserMigration/AccountMigrator.php +++ b/apps/settings/lib/UserMigration/AccountMigrator.php @@ -72,7 +72,7 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { /** * {@inheritDoc} */ - public function getExportEstimatedSize(IUser $user): int { + public function getEstimatedExportSize(IUser $user): int { $uid = $user->getUID(); $size = 100; // 100KiB for account JSON -- cgit v1.2.3 From f2850a6c0634fb7a06896ce1eb501b8105cba0fb Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 29 Apr 2022 01:53:41 +0000 Subject: Skip avatar on failure Signed-off-by: Christopher Ng --- apps/settings/lib/UserMigration/AccountMigrator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'apps') diff --git a/apps/settings/lib/UserMigration/AccountMigrator.php b/apps/settings/lib/UserMigration/AccountMigrator.php index 321889788b8..bf1af10d464 100644 --- a/apps/settings/lib/UserMigration/AccountMigrator.php +++ b/apps/settings/lib/UserMigration/AccountMigrator.php @@ -73,8 +73,6 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { * {@inheritDoc} */ public function getEstimatedExportSize(IUser $user): int { - $uid = $user->getUID(); - $size = 100; // 100KiB for account JSON try { @@ -84,7 +82,7 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { $size += $avatarFile->getSize() / 1024; } } catch (Throwable $e) { - return 0; + // Skip avatar in size estimate on failure } return (int)ceil($size); -- cgit v1.2.3 From 9fbbbc7ca6767ac401d94ee035dd57ae070aae24 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 29 Apr 2022 02:33:45 +0000 Subject: Update contacts estimation Signed-off-by: Christopher Ng --- apps/dav/lib/UserMigration/ContactsMigrator.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'apps') diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index fc498288810..ae1a61ce4f4 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -48,6 +48,7 @@ use Sabre\VObject\Splitter\VCard as VCardSplitter; use Sabre\VObject\UUIDUtil; use Safe\Exceptions\ArrayException; use Safe\Exceptions\StringsException; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Throwable; @@ -198,15 +199,21 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator { * {@inheritDoc} */ public function getEstimatedExportSize(IUser $user): int { - $principalUri = $this->getPrincipalUri($user); + $addressBookExports = $this->getAddressBookExports($user, new NullOutput()); + $addressBookCount = count($addressBookExports); - 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), + // 50B for each metadata JSON + $size = ($addressBookCount * 50) / 1024; + + $contactsCount = array_sum(array_map( + fn (array $data): int => count($data['vCards']), + $addressBookExports, )); + + // 350B for each contact + $size += ($contactsCount * 350) / 1024; + + return (int)ceil($size); } /** -- cgit v1.2.3 From aaedc95e817c55576ed7413bc2220800bb66ef85 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 29 Apr 2022 03:03:01 +0000 Subject: Update calendar estimation Signed-off-by: Christopher Ng --- apps/dav/lib/UserMigration/CalendarMigrator.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index 5a296a2b527..057f7dce77d 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -51,6 +51,7 @@ use Sabre\VObject\Property\ICalendar\DateTime; use Sabre\VObject\Reader as VObjectReader; use Sabre\VObject\UUIDUtil; use Safe\Exceptions\StringsException; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Throwable; @@ -211,15 +212,25 @@ class CalendarMigrator implements IMigrator, ISizeEstimationMigrator { * {@inheritDoc} */ public function getEstimatedExportSize(IUser $user): int { - $principalUri = $this->getPrincipalUri($user); + $calendarExports = $this->getCalendarExports($user, new NullOutput()); + $calendarCount = count($calendarExports); + + // 150B for top-level properties + $size = ($calendarCount * 150) / 1024; - 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; + $componentCount = array_sum(array_map( + function (array $data): int { + /** @var VCalendar $vCalendar */ + $vCalendar = $data['vCalendar']; + return count($vCalendar->getComponents()); }, - $this->calendarManager->getCalendarsForPrincipal($principalUri), + $calendarExports, )); + + // 450B for each component (events, todos, alarms, etc.) + $size += ($componentCount * 450) / 1024; + + return (int)ceil($size); } /** -- cgit v1.2.3