From 93dc082ab105a3f4a4928377d3e781e4495cbaeb Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 19 Oct 2022 18:48:04 +0200 Subject: [PATCH] Add option to skip diagnostic checks (#1558) --- .env.example | 3 +++ app/Actions/Diagnostics/Errors.php | 9 +++++++-- app/Console/Commands/Diagnostics.php | 12 ++++++++++-- .../Administration/DiagnosticsController.php | 2 +- config/app.php | 10 ++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 80c983bfa5..d54c9e9d2d 100644 --- a/.env.example +++ b/.env.example @@ -89,3 +89,6 @@ MAIL_FROM_ADDRESS= # - `*`: any proxy # - [,]: a comma-seperated list of IP addresses TRUSTED_PROXIES=null + +# Comma-separated list of class names of diagnostics checks that should be skipped. +#SKIP_DIAGNOSTICS_CHECKS= diff --git a/app/Actions/Diagnostics/Errors.php b/app/Actions/Diagnostics/Errors.php index f6fe5d7a78..a044933403 100644 --- a/app/Actions/Diagnostics/Errors.php +++ b/app/Actions/Diagnostics/Errors.php @@ -16,9 +16,11 @@ public function __construct(DiagnosticsChecksFactory $diagnosticsChecksFactory) /** * Return the list of error which are currently breaking Lychee. * + * @param string[] $skip class names of checks that will be skipped + * * @return string[] array of messages */ - public function get(): array + public function get(array $skip = []): array { /** @var string[] $errors */ $errors = []; @@ -28,7 +30,10 @@ public function get(): array $checks = $this->diagnosticsChecksFactory->makeAll(); foreach ($checks as $check) { - $check->check($errors); + $check_name = (new \ReflectionClass($check))->getShortName(); + if (!in_array($check_name, $skip, true)) { + $check->check($errors); + } } // @codeCoverageIgnoreEnd diff --git a/app/Console/Commands/Diagnostics.php b/app/Console/Commands/Diagnostics.php index 0acc115921..d2185e6229 100644 --- a/app/Console/Commands/Diagnostics.php +++ b/app/Console/Commands/Diagnostics.php @@ -24,7 +24,8 @@ class Diagnostics extends Command * * @var string */ - protected $signature = 'lychee:diagnostics'; + protected $signature = 'lychee:diagnostics + {--skip=* : Skip certain diagnostics check, overrides SKIP_DIAGNOSTICS_CHECKS config}'; /** * The console command description. @@ -73,10 +74,17 @@ private function block(string $str, array $array): void */ public function handle(): int { + /** @var string[] $skip_diagnostics */ + $skip_diagnostics = config('app.skip_diagnostics_checks'); + /** @var string[] $options */ + $options = $this->option('skip'); + if (sizeof($options) > 0) { + $skip_diagnostics = $options; + } try { $this->line(''); $this->line(''); - $this->block('Diagnostics', resolve(Errors::class)->get()); + $this->block('Diagnostics', resolve(Errors::class)->get($skip_diagnostics)); $this->line(''); $this->block('System Information', resolve(Info::class)->get()); $this->line(''); diff --git a/app/Http/Controllers/Administration/DiagnosticsController.php b/app/Http/Controllers/Administration/DiagnosticsController.php index 0ecbf8c58e..c171949d35 100644 --- a/app/Http/Controllers/Administration/DiagnosticsController.php +++ b/app/Http/Controllers/Administration/DiagnosticsController.php @@ -49,7 +49,7 @@ public function get(Errors $checkErrors, Info $collectInfo, Configuration $confi { $authorized = $this->isAuthorized(); - return new DiagnosticInfo($checkErrors->get(), $authorized ? $collectInfo->get() : [self::ERROR_MSG], $authorized ? $config->get() : [self::ERROR_MSG], $checkUpdate->getCode()); + return new DiagnosticInfo($checkErrors->get(config('app.skip_diagnostics_checks')), $authorized ? $collectInfo->get() : [self::ERROR_MSG], $authorized ? $config->get() : [self::ERROR_MSG], $checkUpdate->getCode()); } /** diff --git a/config/app.php b/config/app.php index a7a422b36c..fdced01bb6 100644 --- a/config/app.php +++ b/config/app.php @@ -120,6 +120,16 @@ 'db_log_sql' => (bool) env('DB_LOG_SQL', false), + /* + |-------------------------------------------------------------------------- + | Skip diagnostics checks + |-------------------------------------------------------------------------- + | + | Allows to define class names of diagnostics checks that will be skipped. + | + */ + 'skip_diagnostics_checks' => explode(',', env('SKIP_DIAGNOSTICS_CHECKS', '')), + /* |-------------------------------------------------------------------------- | Encryption Key