You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactored entire startup repository code block to be more efficient
and cleaner. Also includes modifications to front-end to make it match
backend name and design.
Alert::success('Startup variables were successfully modified and assigned for this server.')->flash();
493
+
} catch(DisplayException$ex) {
494
+
Alert::danger($ex->getMessage())->flash();
495
+
} catch (TransferException$ex) {
496
+
Log::warning($ex);
497
+
Alert::danger('A TransferException occurred while attempting to update the startup for this server, please ensure the daemon is running. This error has been logged.')->flash();
498
+
} catch (\Exception$ex) {
499
+
Log::error($ex);
500
+
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. This error has been logged.')->flash();
// Variable is required but was not passed into the function.
631
+
if ($variable->required && ! $set) {
632
+
thrownewDisplayException('A required variable (' . $variable->env_variable . ') was not passed in the request.');
648
633
}
649
634
650
-
// Update Empty but skip validation
651
-
if (empty($data[$variable->env_variable])) {
652
-
$variableList[] = [
653
-
'id' => $variable->id,
654
-
'env' => $variable->env_variable,
655
-
'val' => null,
656
-
];
635
+
// If user is not an admin and are trying to edit a non-editable field
636
+
// or an invisible field just silently skip the variable.
637
+
if (! $admin && (! $variable->user_editable || ! $variable->user_viewable)) {
657
638
continue;
658
639
}
659
640
660
-
// Is the variable required?
661
-
// @TODO: is this even logical to perform this check?
662
-
if (isset($data[$variable->env_variable]) && empty($data[$variable->env_variable])) {
663
-
if ($variable->required) {
664
-
thrownewDisplayException('A required service option variable field (' . $variable->env_variable . ') was included in this request but was left blank.');
641
+
// Confirm value is valid when compared aganist regex.
642
+
// @TODO: switch to Laravel validation rules.
643
+
if ($set && ! is_null($variable->regex)) {
644
+
if (! preg_match($variable->regex, $data['env_' . $variable->id])) {
645
+
thrownewDisplayException('The value passed for a variable (' . $variable->env_variable . ') could not be matched aganist the regex for that field (' . $variable->regex . ').');
665
646
}
666
647
}
667
648
668
-
// Variable hidden and/or not user editable
669
-
if ((! $variable->user_viewable || ! $variable->user_editable) && ! $admin) {
670
-
thrownewDisplayException('A service option variable field (' . $variable->env_variable . ') does not exist or you do not have permission to edit it.');
671
-
}
649
+
$svar = Models\ServerVariable::firstOrNew([
650
+
'server_id' => $server->id,
651
+
'variable_id' => $variable->id,
652
+
]);
653
+
654
+
// Set the value; if one was not passed set it to the default value
<pclass="small text-muted">Edit your server's startup command here. The following variables are available by default: <code>@{{SERVER_MEMORY}}</code>, <code>@{{SERVER_IP}}</code>, and <code>@{{SERVER_PORT}}</code>.</p>
0 commit comments