Skip to content

Commit

Permalink
Add option to skip diagnostic checks (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored Oct 19, 2022
1 parent 37faf16 commit 93dc082
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ MAIL_FROM_ADDRESS=
# - `*`: any proxy
# - <ip address>[,<ip address>]: 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=
9 changes: 7 additions & 2 deletions app/Actions/Diagnostics/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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

Expand Down
12 changes: 10 additions & 2 deletions app/Console/Commands/Diagnostics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
10 changes: 10 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93dc082

Please sign in to comment.