Skip to content

Commit b8840c6

Browse files
committed
fix(CardDAV): only run upgrade sync if 1000 users or less
Signed-off-by: Anna Larch <[email protected]>
1 parent 85ff144 commit b8840c6

8 files changed

Lines changed: 72 additions & 14 deletions

File tree

apps/dav/lib/Command/SyncSystemAddressBook.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,18 @@
2424
namespace OCA\DAV\Command;
2525

2626
use OCA\DAV\CardDAV\SyncService;
27+
use OCP\IConfig;
2728
use Symfony\Component\Console\Command\Command;
2829
use Symfony\Component\Console\Helper\ProgressBar;
2930
use Symfony\Component\Console\Input\InputInterface;
3031
use Symfony\Component\Console\Output\OutputInterface;
3132

3233
class SyncSystemAddressBook extends Command {
33-
34-
/** @var SyncService */
35-
private $syncService;
36-
3734
/**
3835
* @param SyncService $syncService
3936
*/
40-
public function __construct(SyncService $syncService) {
37+
public function __construct(private SyncService $syncService, private IConfig $config) {
4138
parent::__construct();
42-
$this->syncService = $syncService;
4339
}
4440

4541
protected function configure() {
@@ -62,6 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6258

6359
$progress->finish();
6460
$output->writeln('');
61+
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
6562
return 0;
6663
}
6764
}

apps/dav/lib/Migration/Version1027Date20230504122946.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use Closure;
3030
use OCA\DAV\CardDAV\SyncService;
3131
use OCP\DB\ISchemaWrapper;
32+
use OCP\IConfig;
33+
use OCP\IUserManager;
3234
use OCP\Migration\IOutput;
3335
use OCP\Migration\SimpleMigrationStep;
3436
use Psr\Container\ContainerExceptionInterface;
@@ -37,22 +39,27 @@
3739
use Throwable;
3840

3941
class Version1027Date20230504122946 extends SimpleMigrationStep {
40-
private SyncService $syncService;
41-
private LoggerInterface $logger;
42-
43-
public function __construct(SyncService $syncService, LoggerInterface $logger) {
44-
$this->syncService = $syncService;
45-
$this->logger = $logger;
46-
}
42+
public function __construct(private SyncService $syncService,
43+
private LoggerInterface $logger,
44+
private IUserManager $userManager,
45+
private IConfig $config) {}
4746
/**
4847
* @param IOutput $output
4948
* @param Closure(): ISchemaWrapper $schemaClosure
5049
* @param array $options
5150
*/
5251
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
52+
if($this->userManager->countUsers() > 1000) {
53+
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
54+
$output->info('Could not sync system address books during update - too many user records have been found. Please call occ dav:sync-system-addressbook manually.');
55+
return;
56+
}
57+
5358
try {
5459
$this->syncService->syncInstance();
60+
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
5561
} catch (Throwable $e) {
62+
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
5663
$this->logger->error('Could not sync system address books during update', [
5764
'exception' => $e,
5865
]);

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php',
7676
'OCA\\Settings\\SetupChecks\\LdapInvalidUuids' => $baseDir . '/../lib/SetupChecks/LdapInvalidUuids.php',
7777
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
78+
'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
7879
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
7980
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
8081
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ComposerStaticInitSettings
9090
'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php',
9191
'OCA\\Settings\\SetupChecks\\LdapInvalidUuids' => __DIR__ . '/..' . '/../lib/SetupChecks/LdapInvalidUuids.php',
9292
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
93+
'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
9394
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
9495
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
9596
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use OC\Lock\DBLockingProvider;
6464
use OC\MemoryInfo;
6565
use OCA\Settings\SetupChecks\CheckUserCertificates;
66+
use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
6667
use OCA\Settings\SetupChecks\LdapInvalidUuids;
6768
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
6869
use OCA\Settings\SetupChecks\PhpDefaultCharset;
@@ -911,6 +912,7 @@ public function check() {
911912
$checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
912913
$supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
913914
$ldapInvalidUuids = new LdapInvalidUuids($this->appManager, $this->l10n, $this->serverContainer);
915+
$needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n);
914916

915917
return new DataResponse(
916918
[
@@ -966,6 +968,7 @@ public function check() {
966968
SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
967969
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
968970
LdapInvalidUuids::class => ['pass' => $ldapInvalidUuids->run(), 'description' => $ldapInvalidUuids->description(), 'severity' => $ldapInvalidUuids->severity()],
971+
NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()],
969972
]
970973
);
971974
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Anna Larch <[email protected]>
7+
*
8+
* @author Anna Larch <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Settings\SetupChecks;
28+
29+
use OCP\IConfig;
30+
use OCP\IL10N;
31+
32+
class NeedsSystemAddressBookSync {
33+
public function __construct(private IConfig $config, private IL10N $l10n) {}
34+
35+
public function description(): string {
36+
return $this->l10n->t('The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occured. Please run it manually by calling occ dav:sync-system-addressbook.');
37+
}
38+
39+
public function severity(): string {
40+
return 'warning';
41+
}
42+
43+
public function run(): bool {
44+
return $this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no';
45+
}
46+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class CheckSetupControllerTest extends TestCase {
9292
private $dispatcher;
9393
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
9494
private $db;
95+
private IThrottler $throttler;
9596
/** @var ILockingProvider|\PHPUnit\Framework\MockObject\MockObject */
9697
private $lockingProvider;
9798
/** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
@@ -435,6 +436,7 @@ public function testCheck() {
435436
->willReturnMap([
436437
['files_external', 'user_certificate_scan', '', '["a", "b"]'],
437438
['core', 'cronErrors', '', ''],
439+
['dav', 'needs_system_address_book_sync', 'no', 'no'],
438440
]);
439441
$this->config->expects($this->any())
440442
->method('getSystemValue')
@@ -662,6 +664,7 @@ public function testCheck() {
662664
'isFairUseOfFreePushService' => false,
663665
'temporaryDirectoryWritable' => false,
664666
\OCA\Settings\SetupChecks\LdapInvalidUuids::class => ['pass' => true, 'description' => 'Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.', 'severity' => 'warning'],
667+
\OCA\Settings\SetupChecks\NeedsSystemAddressBookSync::class => ['pass' => true, 'description' => 'The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occured. Please run it manually by calling occ dav:sync-system-addressbook.', 'severity' => 'warning'],
665668
'isBruteforceThrottled' => false,
666669
'bruteforceRemoteAddress' => '',
667670
]

core/js/setupchecks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@
542542
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\CheckUserCertificates', messages)
543543
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SupportedDatabase', messages)
544544
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LdapInvalidUuids', messages)
545-
545+
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync', messages)
546546
} else {
547547
messages.push({
548548
msg: t('core', 'Error occurred while checking server setup'),

0 commit comments

Comments
 (0)