]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(CardDAV): only run upgrade sync if 1000 users or less 40066/head
authorAnna Larch <anna@nextcloud.com>
Thu, 17 Aug 2023 08:19:10 +0000 (10:19 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Sun, 27 Aug 2023 14:04:44 +0000 (14:04 +0000)
Signed-off-by: Anna Larch <anna@nextcloud.com>
apps/dav/lib/Command/SyncSystemAddressBook.php
apps/dav/lib/Migration/Version1027Date20230504122946.php
apps/settings/composer/composer/autoload_classmap.php
apps/settings/composer/composer/autoload_static.php
apps/settings/lib/Controller/CheckSetupController.php
apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php [new file with mode: 0644]
apps/settings/tests/Controller/CheckSetupControllerTest.php
core/js/setupchecks.js

index 272cca5a08ed11c68a4be738e1ebf7c93f96129f..86a9ea26b73fe0c1eaa852b4871d6b16ef5e6b59 100644 (file)
 namespace OCA\DAV\Command;
 
 use OCA\DAV\CardDAV\SyncService;
+use OCP\IConfig;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Helper\ProgressBar;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class SyncSystemAddressBook extends Command {
-
-       /** @var SyncService */
-       private $syncService;
-
        /**
         * @param SyncService $syncService
         */
-       public function __construct(SyncService $syncService) {
+       public function __construct(private SyncService $syncService, private IConfig $config) {
                parent::__construct();
-               $this->syncService = $syncService;
        }
 
        protected function configure() {
@@ -62,6 +58,7 @@ class SyncSystemAddressBook extends Command {
 
                $progress->finish();
                $output->writeln('');
+               $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
                return 0;
        }
 }
index be3d19e8a80daba64c7921cad0f7782177fd28c1..998be8111ca1bfef2510e87ae3c6513d74df6160 100644 (file)
@@ -29,6 +29,8 @@ namespace OCA\DAV\Migration;
 use Closure;
 use OCA\DAV\CardDAV\SyncService;
 use OCP\DB\ISchemaWrapper;
+use OCP\IConfig;
+use OCP\IUserManager;
 use OCP\Migration\IOutput;
 use OCP\Migration\SimpleMigrationStep;
 use Psr\Container\ContainerExceptionInterface;
@@ -37,22 +39,27 @@ use Psr\Log\LoggerInterface;
 use Throwable;
 
 class Version1027Date20230504122946 extends SimpleMigrationStep {
-       private SyncService $syncService;
-       private LoggerInterface $logger;
-
-       public function __construct(SyncService $syncService, LoggerInterface $logger) {
-               $this->syncService = $syncService;
-               $this->logger = $logger;
-       }
+       public function __construct(private SyncService $syncService,
+                                                               private LoggerInterface $logger,
+                                                               private IUserManager $userManager,
+                                                               private IConfig $config) {}
        /**
         * @param IOutput $output
         * @param Closure(): ISchemaWrapper $schemaClosure
         * @param array $options
         */
        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
+               if($this->userManager->countUsers() > 1000) {
+                       $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
+                       $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.');
+                       return;
+               }
+
                try {
                        $this->syncService->syncInstance();
+                       $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
                } catch (Throwable $e) {
+                       $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
                        $this->logger->error('Could not sync system address books during update', [
                                'exception' => $e,
                        ]);
index a2d62b530179e38abcde22f02af2ae7c6b1ba536..674b92b7cac36a82e7779879c5306d1a107cc5a1 100644 (file)
@@ -75,6 +75,7 @@ return array(
     'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php',
     'OCA\\Settings\\SetupChecks\\LdapInvalidUuids' => $baseDir . '/../lib/SetupChecks/LdapInvalidUuids.php',
     'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
+    'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
     'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
     'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
     'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
index c76e3d84ae31763e1c436b414ce5e6620c8b4b07..d78aa56c60642c02136de928461ee687f0f9860e 100644 (file)
@@ -90,6 +90,7 @@ class ComposerStaticInitSettings
         'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php',
         'OCA\\Settings\\SetupChecks\\LdapInvalidUuids' => __DIR__ . '/..' . '/../lib/SetupChecks/LdapInvalidUuids.php',
         'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
+        'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
         'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
         'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
         'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
index 29ef0343399c11b0291c7b20f0654a4ca0892714..bf8de16a2b9b5f988dfdda43a2ca30bac14afdea 100644 (file)
@@ -62,6 +62,7 @@ use OC\Lock\NoopLockingProvider;
 use OC\Lock\DBLockingProvider;
 use OC\MemoryInfo;
 use OCA\Settings\SetupChecks\CheckUserCertificates;
+use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
 use OCA\Settings\SetupChecks\LdapInvalidUuids;
 use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
 use OCA\Settings\SetupChecks\PhpDefaultCharset;
@@ -900,6 +901,7 @@ Raw output
                $checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
                $supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
                $ldapInvalidUuids = new LdapInvalidUuids($this->appManager, $this->l10n, $this->serverContainer);
+               $needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n);
 
                return new DataResponse(
                        [
@@ -955,6 +957,7 @@ Raw output
                                SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
                                'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
                                LdapInvalidUuids::class => ['pass' => $ldapInvalidUuids->run(), 'description' => $ldapInvalidUuids->description(), 'severity' => $ldapInvalidUuids->severity()],
+                               NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()],
                        ]
                );
        }
diff --git a/apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php b/apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php
new file mode 100644 (file)
index 0000000..4c7c182
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Settings\SetupChecks;
+
+use OCP\IConfig;
+use OCP\IL10N;
+
+class NeedsSystemAddressBookSync {
+       public function __construct(private IConfig $config, private IL10N $l10n) {}
+
+       public function description(): string {
+               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.');
+       }
+
+       public function severity(): string {
+               return 'warning';
+       }
+
+       public function run(): bool {
+               return $this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no';
+       }
+}
index 2d2d43434b17e024c1d7cbb475279491bc6f92ea..50723703c5672e0e6bed158a55051f53983d4385 100644 (file)
@@ -95,6 +95,7 @@ class CheckSetupControllerTest extends TestCase {
        private $dispatcher;
        /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
        private $db;
+       private IThrottler $throttler;
        /** @var ILockingProvider|\PHPUnit\Framework\MockObject\MockObject */
        private $lockingProvider;
        /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
@@ -441,6 +442,7 @@ class CheckSetupControllerTest extends TestCase {
                        ->willReturnMap([
                                ['files_external', 'user_certificate_scan', '', '["a", "b"]'],
                                ['core', 'cronErrors', '', ''],
+                               ['dav', 'needs_system_address_book_sync', 'no', 'no'],
                        ]);
                $this->config->expects($this->any())
                        ->method('getSystemValue')
@@ -668,6 +670,7 @@ class CheckSetupControllerTest extends TestCase {
                                'isFairUseOfFreePushService' => false,
                                'temporaryDirectoryWritable' => false,
                                \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'],
+                               \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'],
                                'isBruteforceThrottled' => false,
                                'bruteforceRemoteAddress' => '',
                        ]
index c3e892de2945d7982b8a97b5e46c60a85a560eef..eb5a20c596614933de525b50c62f4872cbf7e613 100644 (file)
                                        OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\CheckUserCertificates', messages)
                                        OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SupportedDatabase', messages)
                                        OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LdapInvalidUuids', messages)
-
+                                       OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync', messages)
                                } else {
                                        messages.push({
                                                msg: t('core', 'Error occurred while checking server setup'),