]> source.dussan.org Git - nextcloud-server.git/commitdiff
Implement getExportEstimatedSize in migrators
authorCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 28 Apr 2022 09:47:04 +0000 (11:47 +0200)
committerCôme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com>
Mon, 30 May 2022 07:36:13 +0000 (07:36 +0000)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/dav/lib/UserMigration/CalendarMigrator.php
apps/dav/lib/UserMigration/ContactsMigrator.php
apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
apps/settings/lib/UserMigration/AccountMigrator.php
lib/public/UserMigration/IMigrator.php

index 015ce6faa86d16d0ccc5be6fa83510626240bbd1..e6383bcc1ddcd90485152100edd22cf015df6ca5 100644 (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}
         */
index aed41e5c82f4fe7ec3695be33b717aede18f6257..068500a1ba7ba730443a62a7fbb0588a05de5ea7 100644 (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}
         */
index dbc6267eb3aae44676367b7af515931d16e11b31..721ca59f9299ef2dcffaa6aca3c42a76245729fe 100644 (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}
         */
index 7b60a101ceeb9a6b2527e99de417621c629413b4..733d4a0b75d62bde3bb92cdff4affcf7ff85164b 100644 (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}
         */
index b7ad382bef22cf068b7723ab24cc50e7821f9520..6915e9b18a7541e41ca70e9d3e3de1ca3bf52e43 100644 (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