summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/UserMigration/ContactsMigrator.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/UserMigration/ContactsMigrator.php')
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php25
1 files changed, 24 insertions, 1 deletions
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 . '…');