Skip to content

Commit 73ad6a1

Browse files
fix(dav): Create SAB at installation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent d4027ab commit 73ad6a1

File tree

6 files changed

+95
-4
lines changed

6 files changed

+95
-4
lines changed

apps/dav/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
<live-migration>
5050
<step>OCA\DAV\Migration\ChunkCleanup</step>
5151
</live-migration>
52+
<install>
53+
<step>OCA\DAV\Migration\CreateSystemAddressBookStep</step>
54+
</install>
5255
</repair-steps>
5356

5457
<commands>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
304304
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => $baseDir . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
305305
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
306+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php',
306307
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php',
307308
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
308309
'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
@@ -318,6 +318,7 @@ class ComposerStaticInitDAV
318318
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
319319
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => __DIR__ . '/..' . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
320320
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
321+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php',
321322
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php',
322323
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
323324
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',

apps/dav/lib/CardDAV/SyncService.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public function ensureSystemAddressBookExists(string $principal, string $uri, ar
108108
}, $this->dbConnection);
109109
}
110110

111+
public function ensureLocalSystemAddressBookExists(): ?array {
112+
return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [
113+
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
114+
]);
115+
}
116+
117+
public function ensureLocalSystemAddressBookExists(): ?array {
118+
return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [
119+
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
120+
]);
121+
}
122+
111123
private function prepareUri(string $host, string $path): string {
112124
/*
113125
* The trailing slash is important for merging the uris together.
@@ -263,10 +275,7 @@ public function deleteUser($userOrCardId) {
263275
*/
264276
public function getLocalSystemAddressBook() {
265277
if (is_null($this->localSystemAddressBook)) {
266-
$systemPrincipal = "principals/system/system";
267-
$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
268-
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
269-
]);
278+
$this->localSystemAddressBook = $this->ensureLocalSystemAddressBookExists();
270279
}
271280

272281
return $this->localSystemAddressBook;
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)