Skip to content

Commit 4efd119

Browse files
Merge pull request #51144 from nextcloud/fix/dav/create-sab-install
fix(dav): Create SAB at installation
2 parents 103a054 + ec664b0 commit 4efd119

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-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
@@ -306,6 +306,7 @@
306306
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
307307
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => $baseDir . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
308308
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
309+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php',
309310
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php',
310311
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
311312
'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
@@ -321,6 +321,7 @@ class ComposerStaticInitDAV
321321
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
322322
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => __DIR__ . '/..' . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
323323
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
324+
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php',
324325
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php',
325326
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
326327
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',

apps/dav/lib/CardDAV/SyncService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ public function ensureSystemAddressBookExists(string $principal, string $uri, ar
119119
}
120120
}
121121

122+
public function ensureLocalSystemAddressBookExists(): ?array {
123+
return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [
124+
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
125+
]);
126+
}
127+
122128
private function prepareUri(string $host, string $path): string {
123129
/*
124130
* The trailing slash is important for merging the uris together.
@@ -275,10 +281,7 @@ public function deleteUser($userOrCardId) {
275281
*/
276282
public function getLocalSystemAddressBook() {
277283
if (is_null($this->localSystemAddressBook)) {
278-
$systemPrincipal = 'principals/system/system';
279-
$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
280-
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
281-
]);
284+
$this->localSystemAddressBook = $this->ensureLocalSystemAddressBookExists();
282285
}
283286

284287
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)