diff --git a/app/Helpers/SettingsHelper.php b/app/Helpers/SettingsHelper.php index cf1e2df4..5c44084e 100644 --- a/app/Helpers/SettingsHelper.php +++ b/app/Helpers/SettingsHelper.php @@ -172,4 +172,25 @@ class SettingsHelper { 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 ]); + } + } } diff --git a/app/Http/Controllers/IntegrationsController.php b/app/Http/Controllers/IntegrationsController.php index 3aa9a243..8878ff92 100644 --- a/app/Http/Controllers/IntegrationsController.php +++ b/app/Http/Controllers/IntegrationsController.php @@ -30,17 +30,17 @@ class IntegrationsController extends Controller $methodResp = 'test healthchecks \'' . $method . '\' endpoint'; try { - $hc = new Healthchecks(config('integrations.healthchecks_uuid')); + // SettingsHelper::loadIntegrationConfig(); if($method == 'success') { - $hc->success(); + Healthcheck::success(); } if($method == 'fail') { - $hc->fail(); + Healthcheck::fail(); } if($method == 'start') { - $hc->start(); + Healthcheck::start(); } return response()->json([ diff --git a/app/Providers/IntegrationsServiceProvider.php b/app/Providers/IntegrationsServiceProvider.php index b7dd11fe..e896ef13 100644 --- a/app/Providers/IntegrationsServiceProvider.php +++ b/app/Providers/IntegrationsServiceProvider.php @@ -37,28 +37,12 @@ class IntegrationsServiceProvider extends ServiceProvider { if(File::exists(env('DB_DATABASE'))) { if(Schema::hasTable('settings')) { - $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, - ]; + $setting = SettingsHelper::get('healthchecks_uuid'); - foreach($settings as $key => $value) { - $key = 'integrations.' . $key; - - if($value === "") { - $value = null; - } - - config()->set([ $key => $value ]); - } - - if($settings['healthchecks_enabled']) { + if($setting !== false) { try { - App::bind('healthcheck', function() use ($settings) { - return new Healthchecks($settings['healthchecks_uuid']); + App::bind('healthcheck', function() use ($setting) { + return new Healthchecks($setting->value); }); } catch(InvalidUuidStringException $e) { Log::error('Invalid healthchecks UUID');