mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
fix(dav): Create SAB at installation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
b44f1568f2
commit
ec664b0aea
6 changed files with 89 additions and 4 deletions
|
|
@ -49,6 +49,9 @@
|
|||
<live-migration>
|
||||
<step>OCA\DAV\Migration\ChunkCleanup</step>
|
||||
</live-migration>
|
||||
<install>
|
||||
<step>OCA\DAV\Migration\CreateSystemAddressBookStep</step>
|
||||
</install>
|
||||
</repair-steps>
|
||||
|
||||
<commands>
|
||||
|
|
|
|||
|
|
@ -306,6 +306,7 @@ return array(
|
|||
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
|
||||
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => $baseDir . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
|
||||
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
|
||||
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php',
|
||||
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php',
|
||||
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
|
||||
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ class ComposerStaticInitDAV
|
|||
'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php',
|
||||
'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => __DIR__ . '/..' . '/../lib/Migration/CalDAVRemoveEmptyValue.php',
|
||||
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
|
||||
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php',
|
||||
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php',
|
||||
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
|
||||
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
|
||||
|
|
|
|||
|
|
@ -119,6 +119,12 @@ class SyncService {
|
|||
}
|
||||
}
|
||||
|
||||
public function ensureLocalSystemAddressBookExists(): ?array {
|
||||
return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
|
||||
]);
|
||||
}
|
||||
|
||||
private function prepareUri(string $host, string $path): string {
|
||||
/*
|
||||
* The trailing slash is important for merging the uris together.
|
||||
|
|
@ -275,10 +281,7 @@ class SyncService {
|
|||
*/
|
||||
public function getLocalSystemAddressBook() {
|
||||
if (is_null($this->localSystemAddressBook)) {
|
||||
$systemPrincipal = 'principals/system/system';
|
||||
$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
|
||||
]);
|
||||
$this->localSystemAddressBook = $this->ensureLocalSystemAddressBookExists();
|
||||
}
|
||||
|
||||
return $this->localSystemAddressBook;
|
||||
|
|
|
|||
30
apps/dav/lib/Migration/CreateSystemAddressBookStep.php
Normal file
30
apps/dav/lib/Migration/CreateSystemAddressBookStep.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Migration;
|
||||
|
||||
use OCA\DAV\CardDAV\SyncService;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
|
||||
class CreateSystemAddressBookStep implements IRepairStep {
|
||||
|
||||
public function __construct(
|
||||
private SyncService $syncService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Create system address book';
|
||||
}
|
||||
|
||||
public function run(IOutput $output): void {
|
||||
$this->syncService->ensureLocalSystemAddressBookExists();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Tests\Unit\Migration;
|
||||
|
||||
use OCA\DAV\CardDAV\SyncService;
|
||||
use OCA\DAV\Migration\CreateSystemAddressBookStep;
|
||||
use OCP\Migration\IOutput;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CreateSystemAddressBookStepTest extends TestCase {
|
||||
|
||||
private SyncService|MockObject $syncService;
|
||||
private CreateSystemAddressBookStep $step;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->syncService = $this->createMock(SyncService::class);
|
||||
|
||||
$this->step = new CreateSystemAddressBookStep(
|
||||
$this->syncService,
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetName(): void {
|
||||
$name = $this->step->getName();
|
||||
|
||||
self::assertEquals('Create system address book', $name);
|
||||
}
|
||||
|
||||
public function testRun(): void {
|
||||
$output = $this->createMock(IOutput::class);
|
||||
|
||||
$this->step->run($output);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue