Skip to content

Commit

Permalink
Change SetupResult API to named constructors
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Oct 19, 2023
1 parent 11ebf46 commit 2e4d154
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 29 deletions.
4 changes: 2 additions & 2 deletions apps/dav/lib/SetupChecks/NeedsSystemAddressBookSync.php
Expand Up @@ -49,9 +49,9 @@ public function getCategory(): string {

public function run(): SetupResult {
if ($this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no') {
return new SetupResult(SetupResult::SUCCESS, $this->l10n->t('No outstanding DAV system address book sync.'));
return SetupResult::success($this->l10n->t('No outstanding DAV system address book sync.'));
} 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.'));
return 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.'));
}
}
}
8 changes: 4 additions & 4 deletions apps/settings/lib/SetupChecks/CheckUserCertificates.php
Expand Up @@ -38,7 +38,7 @@ public function __construct(
private IL10N $l10n,
IConfig $config,
) {
$this->configValue = $config->getAppValue('files_external', 'user_certificate_scan', '');
$this->configValue = $config->getAppValue('files_external', 'user_certificate_scan', '');
}

public function getCategory(): string {
Expand All @@ -52,11 +52,11 @@ public function getName(): string {
public function run(): SetupResult {
// all fine if neither "not-run-yet" nor a result
if ($this->configValue === '') {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
}
if ($this->configValue === 'not-run-yet') {
return new SetupResult(SetupResult::INFO, $this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.'));
return SetupResult::info($this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.'));
}
return new SetupResult(SetupResult::ERROR, $this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.'));
return SetupResult::error($this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.'));
}
}
5 changes: 2 additions & 3 deletions apps/settings/lib/SetupChecks/DefaultPhoneRegionSet.php
Expand Up @@ -47,10 +47,9 @@ public function getCategory(): string {

public function run(): SetupResult {
if ($this->config->getSystemValueString('default_phone_region', '') !== '') {
return new SetupResult(SetupResult::SUCCESS, $this->config->getSystemValueString('default_phone_region', ''));
return SetupResult::success($this->config->getSystemValueString('default_phone_region', ''));
} else {
return new SetupResult(
SetupResult::INFO,
return SetupResult::info(
$this->l10n->t('Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add "default_phone_region" with the respective ISO 3166-1 code of the region to your config file.'),
'https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements'
);
Expand Down
6 changes: 3 additions & 3 deletions apps/settings/lib/SetupChecks/InternetConnectivity.php
Expand Up @@ -57,7 +57,7 @@ public function getName(): string {

public function run(): SetupResult {
if ($this->config->getSystemValue('has_internet_connection', true) === false) {
return new SetupResult(SetupResult::SUCCESS, $this->l10n->t('Internet connectivity is disabled in configuration file.'));
return SetupResult::success($this->l10n->t('Internet connectivity is disabled in configuration file.'));
}

$siteArray = $this->config->getSystemValue('connectivity_check_domains', [
Expand All @@ -66,10 +66,10 @@ public function run(): SetupResult {

foreach ($siteArray as $site) {
if ($this->isSiteReachable($site)) {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
}
}
return new SetupResult(SetupResult::WARNING, $this->l10n->t('This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.'));
return SetupResult::warning($this->l10n->t('This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php
Expand Up @@ -49,8 +49,8 @@ public function getName(): string {

public function run(): SetupResult {
if ($this->config->getSystemValueBool('encryption.legacy_format_support', false) === false) {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
}
return new SetupResult(SetupResult::WARNING, $this->l10n->t('The old server-side-encryption format is enabled. We recommend disabling this.'), $this->urlGenerator->linkToDocs('admin-sse-legacy-format'));
return SetupResult::warning($this->l10n->t('The old server-side-encryption format is enabled. We recommend disabling this.'), $this->urlGenerator->linkToDocs('admin-sse-legacy-format'));
}
}
4 changes: 2 additions & 2 deletions apps/settings/lib/SetupChecks/PhpDefaultCharset.php
Expand Up @@ -45,9 +45,9 @@ public function getCategory(): string {

public function run(): SetupResult {
if (strtoupper(trim(ini_get('default_charset'))) === 'UTF-8') {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
} else {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('PHP configuration option default_charset should be UTF-8'));
return SetupResult::warning($this->l10n->t('PHP configuration option default_charset should be UTF-8'));
}
}
}
4 changes: 2 additions & 2 deletions apps/settings/lib/SetupChecks/PhpOutdated.php
Expand Up @@ -47,8 +47,8 @@ public function getName(): string {

public function run(): SetupResult {
if (PHP_VERSION_ID < 80100) {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('You are currently running PHP %s. PHP 8.0 is now deprecated in Nextcloud 27. Nextcloud 28 may require at least PHP 8.1. Please upgrade to one of the officially supported PHP versions provided by the PHP Group as soon as possible.', [PHP_VERSION]), 'https://secure.php.net/supported-versions.php');
return SetupResult::warning($this->l10n->t('You are currently running PHP %s. PHP 8.0 is now deprecated in Nextcloud 27. Nextcloud 28 may require at least PHP 8.1. Please upgrade to one of the officially supported PHP versions provided by the PHP Group as soon as possible.', [PHP_VERSION]), 'https://secure.php.net/supported-versions.php');
}
return new SetupResult(SetupResult::SUCCESS, $this->l10n->t('You are currently running PHP %s.', [PHP_VERSION]));
return SetupResult::success($this->l10n->t('You are currently running PHP %s.', [PHP_VERSION]));
}
}
4 changes: 2 additions & 2 deletions apps/settings/lib/SetupChecks/PhpOutputBuffering.php
Expand Up @@ -46,9 +46,9 @@ public function getName(): string {
public function run(): SetupResult {
$value = trim(ini_get('output_buffering'));
if ($value === '' || $value === '0') {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
} else {
return new SetupResult(SetupResult::ERROR, $this->l10n->t('PHP configuration option output_buffering must be disabled'));
return SetupResult::error($this->l10n->t('PHP configuration option output_buffering must be disabled'));
}
}
}
4 changes: 2 additions & 2 deletions apps/settings/lib/SetupChecks/ReadOnlyConfig.php
Expand Up @@ -47,9 +47,9 @@ public function getCategory(): string {

public function run(): SetupResult {
if ($this->config->getSystemValueBool('config_is_read_only', false)) {
return new SetupResult(SetupResult::INFO, $this->l10n->t('The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.'));
return SetupResult::info($this->l10n->t('The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.'));
} else {
return new SetupResult(SetupResult::SUCCESS, $this->l10n->t('Nextcloud configuration file is writable'));
return SetupResult::success($this->l10n->t('Nextcloud configuration file is writable'));
}
}
}
8 changes: 4 additions & 4 deletions apps/settings/lib/SetupChecks/SupportedDatabase.php
Expand Up @@ -68,11 +68,11 @@ public function run(): SetupResult {

if (str_contains($version, 'mariadb')) {
if (version_compare($version, '10.2', '<')) {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']));
return SetupResult::warning($this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']));
}
} else {
if (version_compare($version, '8', '<')) {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value']));
return SetupResult::warning($this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value']));
}
}
break;
Expand All @@ -84,13 +84,13 @@ public function run(): SetupResult {
$result->execute();
$row = $result->fetch();
if (version_compare($row['server_version'], '9.6', '<')) {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']));
return SetupResult::warning($this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']));
}
break;
case OraclePlatform::class:
break;
}
// TODO still show db and version on success?
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
}
}
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/SetupChecks/LdapInvalidUuids.php
Expand Up @@ -52,9 +52,9 @@ public function getName(): string {
public function run(): SetupResult {
if (count($this->userMapping->getList(0, 1, true)) === 0
&& count($this->groupMapping->getList(0, 1, true)) === 0) {
return new SetupResult(SetupResult::SUCCESS);
return SetupResult::success();
} else {
return new SetupResult(SetupResult::WARNING, $this->l10n->t('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.'));
return SetupResult::warning($this->l10n->t('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.'));
}
}
}
35 changes: 34 additions & 1 deletion lib/public/SetupCheck/SetupResult.php
Expand Up @@ -38,16 +38,49 @@ class SetupResult implements \JsonSerializable {
public const ERROR = 'error';

/**
* @brief Private constructor, use success()/info()/warning()/error() instead
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
* @since 28.0.0
*/
public function __construct(
private function __construct(
private string $severity,
private ?string $description = null,
private ?string $linkToDoc = null,
) {
}

/**
* @brief Create a success result object
* @since 28.0.0
*/
public static function success(?string $description = null, ?string $linkToDoc = null): self {
return new self(self::SUCCESS, $description, $linkToDoc);
}

/**
* @brief Create an info result object
* @since 28.0.0
*/
public static function info(?string $description = null, ?string $linkToDoc = null): self {
return new self(self::INFO, $description, $linkToDoc);
}

/**
* @brief Create a warning result object
* @since 28.0.0
*/
public static function warning(?string $description = null, ?string $linkToDoc = null): self {
return new self(self::WARNING, $description, $linkToDoc);
}

/**
* @brief Create an error result object
* @since 28.0.0
*/
public static function error(?string $description = null, ?string $linkToDoc = null): self {
return new self(self::ERROR, $description, $linkToDoc);
}

/**
* @brief Get the severity for the setup check result
*
Expand Down

0 comments on commit 2e4d154

Please sign in to comment.