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:
authorPytal <24800714+Pytal@users.noreply.github.com>2022-06-02 21:32:31 +0300
committerGitHub <noreply@github.com>2022-06-02 21:32:31 +0300
commit4ca4228ff6f1ec5fb365bd471385d82ae71a43b8 (patch)
treebbb4ee6b951b5065c488a0ff7c80eb59e83b855c /apps
parent01ae33f4bb9743c67d5af7c15ce4b3eecbb005a0 (diff)
parenta541f97dcccefe92ac51c5d7849b1596d4733747 (diff)
Merge pull request #32664 from nextcloud/backport/32206/stable24
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/UserMigration/CalendarMigrator.php29
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php25
-rw-r--r--apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php20
-rw-r--r--apps/settings/lib/UserMigration/AccountMigrator.php22
4 files changed, 92 insertions, 4 deletions
diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php
index 015ce6faa86..057f7dce77d 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;
@@ -50,10 +51,11 @@ 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;
-class CalendarMigrator implements IMigrator {
+class CalendarMigrator implements IMigrator, ISizeEstimationMigrator {
use TMigratorBasicVersionHandling;
@@ -209,6 +211,31 @@ class CalendarMigrator implements IMigrator {
/**
* {@inheritDoc}
*/
+ public function getEstimatedExportSize(IUser $user): int {
+ $calendarExports = $this->getCalendarExports($user, new NullOutput());
+ $calendarCount = count($calendarExports);
+
+ // 150B for top-level properties
+ $size = ($calendarCount * 150) / 1024;
+
+ $componentCount = array_sum(array_map(
+ function (array $data): int {
+ /** @var VCalendar $vCalendar */
+ $vCalendar = $data['vCalendar'];
+ return count($vCalendar->getComponents());
+ },
+ $calendarExports,
+ ));
+
+ // 450B for each component (events, todos, alarms, etc.)
+ $size += ($componentCount * 450) / 1024;
+
+ return (int)ceil($size);
+ }
+
+ /**
+ * {@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..ae1a61ce4f4 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;
@@ -47,10 +48,11 @@ 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;
-class ContactsMigrator implements IMigrator {
+class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
use TMigratorBasicVersionHandling;
@@ -196,6 +198,27 @@ class ContactsMigrator implements IMigrator {
/**
* {@inheritDoc}
*/
+ public function getEstimatedExportSize(IUser $user): int {
+ $addressBookExports = $this->getAddressBookExports($user, new NullOutput());
+ $addressBookCount = count($addressBookExports);
+
+ // 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);
+ }
+
+ /**
+ * {@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..9c0334aa2f3 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;
@@ -66,6 +67,23 @@ class TrashbinMigrator implements IMigrator {
/**
* {@inheritDoc}
*/
+ public function getEstimatedExportSize(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..bf1af10d464 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;
@@ -71,6 +72,25 @@ class AccountMigrator implements IMigrator {
/**
* {@inheritDoc}
*/
+ public function getEstimatedExportSize(IUser $user): int {
+ $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) {
+ // Skip avatar in size estimate on failure
+ }
+
+ 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 . '…');