Migrate NeedsSystemAddressBookSync to new ISetupCheck API

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/32550/head
Côme Chilliet 2 years ago
parent 67e7a2635f
commit 8bfa0935b4
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 12
      apps/dav/lib/AppInfo/Application.php
  2. 4
      apps/settings/lib/Controller/CheckSetupController.php
  3. 29
      apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php

@ -91,6 +91,7 @@ use OCA\DAV\Search\EventsSearchProvider;
use OCA\DAV\Search\TasksSearchProvider;
use OCA\DAV\UserMigration\CalendarMigrator;
use OCA\DAV\UserMigration\ContactsMigrator;
use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
@ -101,7 +102,6 @@ use OCP\Config\BeforePreferenceDeletedEvent;
use OCP\Config\BeforePreferenceSetEvent;
use OCP\Contacts\IManager as IContactsManager;
use OCP\Files\AppData\IAppDataFactory;
use OCP\IServerContainer;
use OCP\IUser;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@ -124,12 +124,12 @@ class Application extends App implements IBootstrap {
$c->get(LoggerInterface::class)
);
});
$context->registerService(AppCalendarPlugin::class, function(ContainerInterface $c) {
$context->registerService(AppCalendarPlugin::class, function (ContainerInterface $c) {
return new AppCalendarPlugin(
$c->get(ICalendarManager::class),
$c->get(LoggerInterface::class)
$c->get(ICalendarManager::class),
$c->get(LoggerInterface::class)
);
});
});
/*
* Register capabilities
@ -201,6 +201,8 @@ class Application extends App implements IBootstrap {
$context->registerUserMigrator(CalendarMigrator::class);
$context->registerUserMigrator(ContactsMigrator::class);
$context->registerSetupCheck(NeedsSystemAddressBookSync::class);
}
public function boot(IBootContext $context): void {

@ -61,7 +61,6 @@ use OC\IntegrityCheck\Checker;
use OC\Lock\NoopLockingProvider;
use OC\Lock\DBLockingProvider;
use OC\MemoryInfo;
use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
@ -911,8 +910,6 @@ Raw output
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
*/
public function check() {
$needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n);
return new DataResponse(
[
'isGetenvServerWorking' => !empty(getenv('PATH')),
@ -961,7 +958,6 @@ Raw output
'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()],
]
);
}

@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2023 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
@ -28,19 +29,29 @@ namespace OCA\Settings\SetupChecks;
use OCP\IConfig;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;
class NeedsSystemAddressBookSync implements ISetupCheck {
public function __construct(
private IConfig $config,
private IL10N $l10n,
) {
}
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 occurred. Please run it manually by calling "occ dav:sync-system-addressbook".');
public function getName(): string {
return $this->l10n->t('Checking for DAV system address book');
}
public function severity(): string {
return 'warning';
public function getCategory(): string {
return 'dav';
}
public function run(): bool {
return $this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no';
public function run(): SetupResult {
if ($this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no') {
return new SetupResult(SetupResult::SUCCESS, $this->l10n->t('The address book sync has already run'));
} else {
return new SetupResult(SetupResult::WARNING, $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 occurred. Please run it manually by calling occ dav:sync-system-addressbook.'));
}
}
}

Loading…
Cancel
Save