Moved int config loading into helper

This commit is contained in:
Henry Whitaker
2020-08-25 19:08:32 +01:00
parent 0eff685277
commit 7da1d3d760
3 changed files with 29 additions and 24 deletions

View File

@@ -172,4 +172,25 @@ class SettingsHelper {
return false; return false;
} }
public static function loadIntegrationConfig()
{
$settings = [
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
];
foreach($settings as $key => $value) {
$key = 'integrations.' . $key;
if($value === "") {
$value = null;
}
config()->set([ $key => $value ]);
}
}
} }

View File

@@ -30,17 +30,17 @@ class IntegrationsController extends Controller
$methodResp = 'test healthchecks \'' . $method . '\' endpoint'; $methodResp = 'test healthchecks \'' . $method . '\' endpoint';
try { try {
$hc = new Healthchecks(config('integrations.healthchecks_uuid')); // SettingsHelper::loadIntegrationConfig();
if($method == 'success') { if($method == 'success') {
$hc->success(); Healthcheck::success();
} }
if($method == 'fail') { if($method == 'fail') {
$hc->fail(); Healthcheck::fail();
} }
if($method == 'start') { if($method == 'start') {
$hc->start(); Healthcheck::start();
} }
return response()->json([ return response()->json([

View File

@@ -37,28 +37,12 @@ class IntegrationsServiceProvider extends ServiceProvider
{ {
if(File::exists(env('DB_DATABASE'))) { if(File::exists(env('DB_DATABASE'))) {
if(Schema::hasTable('settings')) { if(Schema::hasTable('settings')) {
$settings = [ $setting = SettingsHelper::get('healthchecks_uuid');
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
];
foreach($settings as $key => $value) { if($setting !== false) {
$key = 'integrations.' . $key;
if($value === "") {
$value = null;
}
config()->set([ $key => $value ]);
}
if($settings['healthchecks_enabled']) {
try { try {
App::bind('healthcheck', function() use ($settings) { App::bind('healthcheck', function() use ($setting) {
return new Healthchecks($settings['healthchecks_uuid']); return new Healthchecks($setting->value);
}); });
} catch(InvalidUuidStringException $e) { } catch(InvalidUuidStringException $e) {
Log::error('Invalid healthchecks UUID'); Log::error('Invalid healthchecks UUID');