Skip to content

Commit 76d176f

Browse files
committed
Implement getExportEstimatedSize in migrators
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 15022ad commit 76d176f

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

apps/dav/lib/UserMigration/CalendarMigrator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri):
206206
return $calendarUri;
207207
}
208208

209+
/**
210+
* {@inheritDoc}
211+
*/
212+
public function getExportEstimatedSize(IUser $user): int {
213+
$principalUri = $this->getPrincipalUri($user);
214+
215+
return array_sum(array_map(
216+
function (ICalendar $calendar) use ($user): int {
217+
// FIXME 1MiB by calendar, no idea if this is accurate and if we should go into more details
218+
return 1000;
219+
},
220+
$this->calendarManager->getCalendarsForPrincipal($principalUri),
221+
));
222+
}
223+
209224
/**
210225
* {@inheritDoc}
211226
*/

apps/dav/lib/UserMigration/ContactsMigrator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ private function serializeCards(array $vCards): string {
193193
);
194194
}
195195

196+
/**
197+
* {@inheritDoc}
198+
*/
199+
public function getExportEstimatedSize(IUser $user): int {
200+
$principalUri = $this->getPrincipalUri($user);
201+
202+
return array_sum(array_map(
203+
function (array $addressBookInfo) use ($user): int {
204+
// FIXME 1MiB by addressbook, no idea if this is accurate and if we should go into more details
205+
return 1000;
206+
},
207+
$this->cardDavBackend->getAddressBooksForUser($principalUri),
208+
));
209+
}
210+
196211
/**
197212
* {@inheritDoc}
198213
*/

apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ public function __construct(
6363
$this->l10n = $l10n;
6464
}
6565

66+
/**
67+
* {@inheritDoc}
68+
*/
69+
public function getExportEstimatedSize(IUser $user): int {
70+
$uid = $user->getUID();
71+
72+
try {
73+
$trashbinFolder = $this->root->get('/'.$uid.'/files_trashbin');
74+
if (!$trashbinFolder instanceof Folder) {
75+
return 0;
76+
}
77+
return (int)ceil($trashbinFolder->getSize() / 1024);
78+
} catch (\Throwable $e) {
79+
return 0;
80+
}
81+
}
82+
6683
/**
6784
* {@inheritDoc}
6885
*/

apps/settings/lib/UserMigration/AccountMigrator.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ public function __construct(
6868
$this->l10n = $l10n;
6969
}
7070

71+
/**
72+
* {@inheritDoc}
73+
*/
74+
public function getExportEstimatedSize(IUser $user): int {
75+
$uid = $user->getUID();
76+
77+
$size = 100; // 100KiB for account JSON
78+
79+
try {
80+
$avatar = $this->avatarManager->getAvatar($user->getUID());
81+
if ($avatar->isCustomAvatar()) {
82+
$avatarFile = $avatar->getFile(-1);
83+
$size += $avatarFile->getSize() / 1024;
84+
}
85+
} catch (Throwable $e) {
86+
return 0;
87+
}
88+
89+
return (int)ceil($size);
90+
}
91+
7192
/**
7293
* {@inheritDoc}
7394
*/

lib/public/UserMigration/IMigrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getVersion(): int;
9393
*
9494
* @since 24.0.0
9595
*/
96-
public function getExportEstimatedSize(): int;
96+
public function getExportEstimatedSize(IUser $user): int;
9797

9898
/**
9999
* Checks whether it is able to import a version of the export format for this migrator

0 commit comments

Comments
 (0)