1
0

EmailTestSuccessful.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\IConfig;
  9. use OCP\IL10N;
  10. use OCP\IURLGenerator;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. class EmailTestSuccessful implements ISetupCheck {
  14. public function __construct(
  15. private IL10N $l10n,
  16. private IConfig $config,
  17. private IURLGenerator $urlGenerator,
  18. ) {
  19. }
  20. public function getName(): string {
  21. return $this->l10n->t('Email test');
  22. }
  23. public function getCategory(): string {
  24. return 'config';
  25. }
  26. protected function wasEmailTestSuccessful(): bool {
  27. // 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
  28. if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '' && $this->config->getSystemValue('mail_domain', '') === '') {
  29. return false;
  30. }
  31. // The mail test was unsuccessful or the config was changed using the UI without verifying with a testmail, hence return false
  32. if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '0') {
  33. return false;
  34. }
  35. return true;
  36. }
  37. public function run(): SetupResult {
  38. if ($this->wasEmailTestSuccessful()) {
  39. return SetupResult::success($this->l10n->t('Email test was successfully sent'));
  40. } else {
  41. // If setup check could link to settings pages, this one should link to OC.generateUrl('/settings/admin')
  42. return SetupResult::info(
  43. $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.'),
  44. $this->urlGenerator->linkToDocs('admin-email')
  45. );
  46. }
  47. }
  48. }