Added check for db migration when loading IntegrationServiceProvider

This commit is contained in:
Henry Whitaker
2020-08-15 15:44:13 +01:00
parent dc2ee05344
commit 640a62eed7

View File

@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Ramsey\Uuid\Exception\InvalidUuidStringException; use Ramsey\Uuid\Exception\InvalidUuidStringException;
use Schema;
/** /**
* This class updates the integrations.php config with the relevant values * This class updates the integrations.php config with the relevant values
@@ -33,33 +34,35 @@ class IntegrationsServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
$settings = [ if(Schema::hasTable('settings')) {
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value, $settings = [
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value, 'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
'slack_webhook' => SettingsHelper::get('slack_webhook')->value, 'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value, 'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value, 'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
]; 'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
];
foreach($settings as $key => $value) { foreach($settings as $key => $value) {
$key = 'integrations.' . $key; $key = 'integrations.' . $key;
if($value === "") { if($value === "") {
$value = null; $value = null;
}
config()->set([ $key => $value ]);
} }
config()->set([ $key => $value ]); if($settings['healthchecks_enabled']) {
} try {
App::bind('healthcheck', function() use ($settings) {
if($settings['healthchecks_enabled']) { return new Healthchecks($settings['healthchecks_uuid']);
try { });
App::bind('healthcheck', function() use ($settings) { } catch(InvalidUuidStringException $e) {
return new Healthchecks($settings['healthchecks_uuid']); Log::error('Invalid healthchecks UUID');
}); } catch(Exception $e) {
} catch(InvalidUuidStringException $e) { Log::error($e->getMessage());
Log::error('Invalid healthchecks UUID'); }
} catch(Exception $e) {
Log::error($e->getMessage());
} }
} }
} }