Skip to content

Commit 60174d0

Browse files
ChristophWurstbackportbot[bot]
authored andcommitted
fix(dav): Create SAB at installation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> [skip ci]
1 parent 80d3ccc commit 60174d0

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

apps/dav/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<live-migration>
4545
<step>OCA\DAV\Migration\ChunkCleanup</step>
4646
</live-migration>
47+
<install>
48+
<step>OCA\DAV\Migration\CreateSystemAddressBookStep</step>
49+
</install>
4750
</repair-steps>
4851

4952
<commands>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
296296
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => $baseDir . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
297297
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
298+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php',
298299
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php',
299300
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
300301
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class ComposerStaticInitDAV
310310
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
311311
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => __DIR__ . '/..' . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
312312
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
313+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php',
313314
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php',
314315
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
315316
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',

apps/dav/lib/CardDAV/SyncService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ public function ensureSystemAddressBookExists(string $principal, string $uri, ar
130130
}, $this->dbConnection);
131131
}
132132

133+
public function ensureLocalSystemAddressBookExists(): ?array {
134+
return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [
135+
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
136+
]);
137+
}
138+
133139
private function prepareUri(string $host, string $path): string {
134140
/*
135141
* The trailing slash is important for merging the uris together.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Migration;
11+
12+
use OCA\DAV\CardDAV\SyncService;
13+
use OCP\Migration\IOutput;
14+
use OCP\Migration\IRepairStep;
15+
16+
class CreateSystemAddressBookStep implements IRepairStep {
17+
18+
public function __construct(
19+
private SyncService $syncService,
20+
) {
21+
}
22+
23+
public function getName(): string {
24+
return 'Create system address book';
25+
}
26+
27+
public function run(IOutput $output): void {
28+
$this->syncService->ensureLocalSystemAddressBookExists();
29+
}
30+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Tests\Unit\Migration;
11+
12+
use OCA\DAV\CardDAV\SyncService;
13+
use OCA\DAV\Migration\CreateSystemAddressBookStep;
14+
use OCP\Migration\IOutput;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class CreateSystemAddressBookStepTest extends TestCase {
19+
20+
private SyncService|MockObject $syncService;
21+
private CreateSystemAddressBookStep $step;
22+
23+
protected function setUp(): void {
24+
parent::setUp();
25+
26+
$this->syncService = $this->createMock(SyncService::class);
27+
28+
$this->step = new CreateSystemAddressBookStep(
29+
$this->syncService,
30+
);
31+
}
32+
33+
public function testGetName(): void {
34+
$name = $this->step->getName();
35+
36+
self::assertEquals('Create system address book', $name);
37+
}
38+
39+
public function testRun(): void {
40+
$output = $this->createMock(IOutput::class);
41+
42+
$this->step->run($output);
43+
44+
$this->addToAssertionCount(1);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)