|
42 | 42 | use OCP\UserMigration\IExportDestination; |
43 | 43 | use OCP\UserMigration\IImportSource; |
44 | 44 | use OCP\UserMigration\IMigrator; |
| 45 | +use OCP\UserMigration\ISizeEstimationMigrator; |
45 | 46 | use OCP\UserMigration\TMigratorBasicVersionHandling; |
46 | 47 | use Sabre\VObject\Component as VObjectComponent; |
47 | 48 | use Sabre\VObject\Component\VCalendar; |
|
50 | 51 | use Sabre\VObject\Reader as VObjectReader; |
51 | 52 | use Sabre\VObject\UUIDUtil; |
52 | 53 | use Safe\Exceptions\StringsException; |
| 54 | +use Symfony\Component\Console\Output\NullOutput; |
53 | 55 | use Symfony\Component\Console\Output\OutputInterface; |
54 | 56 | use Throwable; |
55 | 57 |
|
56 | | -class CalendarMigrator implements IMigrator { |
| 58 | +class CalendarMigrator implements IMigrator, ISizeEstimationMigrator { |
57 | 59 |
|
58 | 60 | use TMigratorBasicVersionHandling; |
59 | 61 |
|
@@ -206,6 +208,31 @@ private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri): |
206 | 208 | return $calendarUri; |
207 | 209 | } |
208 | 210 |
|
| 211 | + /** |
| 212 | + * {@inheritDoc} |
| 213 | + */ |
| 214 | + public function getEstimatedExportSize(IUser $user): int { |
| 215 | + $calendarExports = $this->getCalendarExports($user, new NullOutput()); |
| 216 | + $calendarCount = count($calendarExports); |
| 217 | + |
| 218 | + // 150B for top-level properties |
| 219 | + $size = ($calendarCount * 150) / 1024; |
| 220 | + |
| 221 | + $componentCount = array_sum(array_map( |
| 222 | + function (array $data): int { |
| 223 | + /** @var VCalendar $vCalendar */ |
| 224 | + $vCalendar = $data['vCalendar']; |
| 225 | + return count($vCalendar->getComponents()); |
| 226 | + }, |
| 227 | + $calendarExports, |
| 228 | + )); |
| 229 | + |
| 230 | + // 450B for each component (events, todos, alarms, etc.) |
| 231 | + $size += ($componentCount * 450) / 1024; |
| 232 | + |
| 233 | + return (int)ceil($size); |
| 234 | + } |
| 235 | + |
209 | 236 | /** |
210 | 237 | * {@inheritDoc} |
211 | 238 | */ |
|
0 commit comments