Skip to content

Commit

Permalink
Prevent connection exception
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Jun 14, 2021
1 parent 5e654bc commit caaa3d0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.5.6

* Prevent connection exception when accessing settings in CLI mode

# 2.5.5

* Suppress logging when redirect rules file is empty
Expand Down
31 changes: 26 additions & 5 deletions models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use October\Rain\Database\Model;
use System\Behaviors\SettingsModel;
use Throwable;

/**
* @property array $implement
Expand Down Expand Up @@ -39,26 +40,46 @@ public function __construct(array $attributes = [])

public static function isLoggingEnabled(): bool
{
return (bool) (new self)->get('logging_enabled', true);
try {
return (bool) (new self)->get('logging_enabled', true);
} catch (Throwable $e) {
return true;
}
}

public static function isStatisticsEnabled(): bool
{
return (bool) (new self)->get('statistics_enabled', true);
try {
return (bool) (new self)->get('statistics_enabled', true);
} catch (Throwable $e) {
return true;
}
}

public static function isTestLabEnabled(): bool
{
return (bool) (new self)->get('test_lab_enabled', true);
try {
return (bool) (new self)->get('test_lab_enabled', true);
} catch (Throwable $e) {
return true;
}
}

public static function isCachingEnabled(): bool
{
return (bool) (new self)->get('caching_enabled', false);
try {
return (bool) (new self)->get('caching_enabled', false);
} catch (Throwable $e) {
return false;
}
}

public static function isRelativePathsEnabled(): bool
{
return (bool) (new self)->get('relative_paths_enabled', false);
try {
return (bool) (new self)->get('relative_paths_enabled', false);
} catch (Throwable $e) {
return false;
}
}
}
9 changes: 4 additions & 5 deletions updates/20180718_0001_create_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ public function up(): void
$settings->test_lab_enabled = '1';
$settings->save();
} catch (Throwable $e) {
resolve(LoggerInterface::class)
->error(sprintf(
'Vdlp.Redirect: Unable to save default settings: %s',
$e->getMessage()
));
resolve(LoggerInterface::class)->error(sprintf(
'Vdlp.Redirect: Unable to save default settings: %s',
$e->getMessage()
));
}
}

Expand Down
2 changes: 2 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@
- "Add support for symfony/stopwatch:^5.0 (version 4.0 is still supported) -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.5.4"
2.5.5:
- "Suppress logging when redirect rules file is empty -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.5.5"
2.5.6:
- "Prevent connection exception when accessing settings in CLI mode -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.5.6"

0 comments on commit caaa3d0

Please sign in to comment.