0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-01-30 22:37:01 +00:00
nextcloud_server/apps/settings/lib/SetupChecks/EmailTestSuccessful.php
Côme Chilliet b8de5e0d09
fix(settings): Fix setup check when mail_smptmode is set to "null"
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2025-01-20 17:12:19 +01:00

61 lines
2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\SetupChecks;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;
class EmailTestSuccessful implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IConfig $config,
private IURLGenerator $urlGenerator,
) {
}
public function getName(): string {
return $this->l10n->t('Email test');
}
public function getCategory(): string {
return 'config';
}
protected function wasEmailTestSuccessful(): bool {
// Handle the case that the configuration was set before the check was introduced or it was only set via command line and not from the UI
if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '' && $this->config->getSystemValue('mail_domain', '') === '') {
return false;
}
// The mail test was unsuccessful or the config was changed using the UI without verifying with a testmail, hence return false
if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '0') {
return false;
}
return true;
}
public function run(): SetupResult {
if ($this->config->getSystemValueString('mail_smtpmode', 'smtp') === 'null') {
return SetupResult::success($this->l10n->t('Mail delivery is disabled by instance config "%s".', ['mail_smtpmode']));
} elseif ($this->wasEmailTestSuccessful()) {
return SetupResult::success($this->l10n->t('Email test was successfully sent'));
} else {
// If setup check could link to settings pages, this one should link to OC.generateUrl('/settings/admin')
return SetupResult::info(
$this->l10n->t('You have not set or verified your email server configuration, yet. Please head over to the "Basic settings" in order to set them. Afterwards, use the "Send email" button below the form to verify your settings.'),
$this->urlGenerator->linkToDocs('admin-email')
);
}
}
}