fix: logdrain settings

This commit is contained in:
Andras Bacsai
2024-11-25 17:48:01 +01:00
parent 16763372fc
commit 40cc49537e

View File

@@ -49,33 +49,73 @@ class LogDrains extends Component
} }
} }
public function syncData(bool $toModel = false) public function syncDataNewRelic(bool $toModel = false)
{
if ($toModel) {
$this->server->settings->is_logdrain_newrelic_enabled = $this->isLogDrainNewRelicEnabled;
$this->server->settings->logdrain_newrelic_license_key = $this->logDrainNewRelicLicenseKey;
$this->server->settings->logdrain_newrelic_base_uri = $this->logDrainNewRelicBaseUri;
} else {
$this->isLogDrainNewRelicEnabled = $this->server->settings->is_logdrain_newrelic_enabled;
$this->logDrainNewRelicLicenseKey = $this->server->settings->logdrain_newrelic_license_key;
$this->logDrainNewRelicBaseUri = $this->server->settings->logdrain_newrelic_base_uri;
}
}
public function syncDataAxiom(bool $toModel = false)
{
if ($toModel) {
$this->server->settings->is_logdrain_axiom_enabled = $this->isLogDrainAxiomEnabled;
$this->server->settings->logdrain_axiom_dataset_name = $this->logDrainAxiomDatasetName;
$this->server->settings->logdrain_axiom_api_key = $this->logDrainAxiomApiKey;
} else {
$this->isLogDrainAxiomEnabled = $this->server->settings->is_logdrain_axiom_enabled;
$this->logDrainAxiomDatasetName = $this->server->settings->logdrain_axiom_dataset_name;
$this->logDrainAxiomApiKey = $this->server->settings->logdrain_axiom_api_key;
}
}
public function syncDataCustom(bool $toModel = false)
{
if ($toModel) {
$this->server->settings->is_logdrain_custom_enabled = $this->isLogDrainCustomEnabled;
$this->server->settings->logdrain_custom_config = $this->logDrainCustomConfig;
$this->server->settings->logdrain_custom_config_parser = $this->logDrainCustomConfigParser;
} else {
$this->isLogDrainCustomEnabled = $this->server->settings->is_logdrain_custom_enabled;
$this->logDrainCustomConfig = $this->server->settings->logdrain_custom_config;
$this->logDrainCustomConfigParser = $this->server->settings->logdrain_custom_config_parser;
}
}
public function syncData(bool $toModel = false, ?string $type = null)
{ {
if ($toModel) { if ($toModel) {
$this->customValidation(); $this->customValidation();
$this->server->settings->is_logdrain_newrelic_enabled = $this->isLogDrainNewRelicEnabled; if ($type === 'newrelic') {
$this->server->settings->is_logdrain_axiom_enabled = $this->isLogDrainAxiomEnabled; $this->syncDataNewRelic($toModel);
$this->server->settings->is_logdrain_custom_enabled = $this->isLogDrainCustomEnabled; } elseif ($type === 'axiom') {
$this->syncDataAxiom($toModel);
$this->server->settings->logdrain_newrelic_license_key = $this->logDrainNewRelicLicenseKey; } elseif ($type === 'custom') {
$this->server->settings->logdrain_newrelic_base_uri = $this->logDrainNewRelicBaseUri; $this->syncDataCustom($toModel);
$this->server->settings->logdrain_axiom_dataset_name = $this->logDrainAxiomDatasetName; } else {
$this->server->settings->logdrain_axiom_api_key = $this->logDrainAxiomApiKey; $this->syncDataNewRelic($toModel);
$this->server->settings->logdrain_custom_config = $this->logDrainCustomConfig; $this->syncDataAxiom($toModel);
$this->server->settings->logdrain_custom_config_parser = $this->logDrainCustomConfigParser; $this->syncDataCustom($toModel);
}
$this->server->settings->save(); $this->server->settings->save();
} else { } else {
$this->isLogDrainNewRelicEnabled = $this->server->settings->is_logdrain_newrelic_enabled; if ($type === 'newrelic') {
$this->isLogDrainAxiomEnabled = $this->server->settings->is_logdrain_axiom_enabled; $this->syncDataNewRelic($toModel);
$this->isLogDrainCustomEnabled = $this->server->settings->is_logdrain_custom_enabled; } elseif ($type === 'axiom') {
$this->syncDataAxiom($toModel);
$this->logDrainNewRelicLicenseKey = $this->server->settings->logdrain_newrelic_license_key; } elseif ($type === 'custom') {
$this->logDrainNewRelicBaseUri = $this->server->settings->logdrain_newrelic_base_uri; $this->syncDataCustom($toModel);
$this->logDrainAxiomDatasetName = $this->server->settings->logdrain_axiom_dataset_name; } else {
$this->logDrainAxiomApiKey = $this->server->settings->logdrain_axiom_api_key; $this->syncDataNewRelic($toModel);
$this->logDrainCustomConfig = $this->server->settings->logdrain_custom_config; $this->syncDataAxiom($toModel);
$this->logDrainCustomConfigParser = $this->server->settings->logdrain_custom_config_parser; $this->syncDataCustom($toModel);
}
} }
} }
@@ -136,7 +176,7 @@ class LogDrains extends Component
public function submit(string $type) public function submit(string $type)
{ {
try { try {
$this->syncData(true); $this->syncData(true, $type);
$this->dispatch('success', 'Settings saved.'); $this->dispatch('success', 'Settings saved.');
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);