Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-04-28 12:47:04 +0300
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2022-05-31 03:19:13 +0300
commitdde192da4ae7e359b2869b8869daa02c89c4b2a9 (patch)
tree1d7f2872f088c71438282be8bc9de3b76eb62298 /apps
parentc16b72f588ffeae0ac58e646d0574b9121bfe0dc (diff)
Implement getExportEstimatedSize in migrators
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/UserMigration/CalendarMigrator.php15
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php15
-rw-r--r--apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php17
-rw-r--r--apps/settings/lib/UserMigration/AccountMigrator.php21
4 files changed, 68 insertions, 0 deletions
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
@@ -209,6 +209,21 @@ class CalendarMigrator implements IMigrator {
/**
* {@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}
+ */
public function export(IUser $user, IExportDestination $exportDestination, OutputInterface $output): void {
$output->writeln('Exporting calendars into ' . CalendarMigrator::EXPORT_ROOT . '…');
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
@@ -196,6 +196,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}
+ */
public function export(IUser $user, IExportDestination $exportDestination, OutputInterface $output): void {
$output->writeln('Exporting contacts into ' . ContactsMigrator::PATH_ROOT . '…');
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
@@ -66,6 +66,23 @@ class TrashbinMigrator implements IMigrator {
/**
* {@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}
+ */
public function export(IUser $user, IExportDestination $exportDestination, OutputInterface $output): void {
$output->writeln('Exporting trashbin into ' . Application::APP_ID . '…');
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
@@ -71,6 +71,27 @@ class AccountMigrator implements IMigrator {
/**
* {@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}
+ */
public function export(IUser $user, IExportDestination $exportDestination, OutputInterface $output): void {
$output->writeln('Exporting account information in ' . AccountMigrator::PATH_ACCOUNT_FILE . '…');