mirror of
https://github.com/pelican-dev/panel.git
synced 2025-10-29 23:26:52 +01:00
Make sure default variable value is set and that variables are created when viewing server (#1758)
This commit is contained in:
parent
ec5fd3262a
commit
2fc30e14fd
@ -14,7 +14,6 @@ use App\Models\Allocation;
|
||||
use App\Models\Egg;
|
||||
use App\Models\Node;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerVariable;
|
||||
use App\Models\User;
|
||||
use App\Repositories\Daemon\DaemonServerRepository;
|
||||
use App\Services\Eggs\EggChangerService;
|
||||
@ -637,14 +636,7 @@ class EditServer extends EditRecord
|
||||
/** @var Server $server */
|
||||
$server = $this->getRecord();
|
||||
|
||||
foreach ($server->variables as $variable) {
|
||||
ServerVariable::query()->firstOrCreate([
|
||||
'server_id' => $server->id,
|
||||
'variable_id' => $variable->id,
|
||||
], [
|
||||
'variable_value' => $variable->server_value ?? '',
|
||||
]);
|
||||
}
|
||||
$server->ensureVariablesExist();
|
||||
|
||||
return $query->orderByPowerJoins('variable.sort');
|
||||
})
|
||||
|
||||
@ -102,7 +102,11 @@ class Startup extends ServerFormPage
|
||||
->schema([
|
||||
Repeater::make('server_variables')
|
||||
->hiddenLabel()
|
||||
->relationship('serverVariables', fn (Builder $query) => $query->where('egg_variables.user_viewable', true)->orderByPowerJoins('variable.sort'))
|
||||
->relationship('serverVariables', function (Builder $query, Server $server) {
|
||||
$server->ensureVariablesExist();
|
||||
|
||||
return $query->where('egg_variables.user_viewable', true)->orderByPowerJoins('variable.sort');
|
||||
})
|
||||
->grid()
|
||||
->disabled(fn (Server $server) => !auth()->user()->can(Permission::ACTION_STARTUP_UPDATE, $server))
|
||||
->reorderable(false)->addable(false)->deletable(false)
|
||||
|
||||
@ -325,6 +325,18 @@ class Server extends Model implements Validatable
|
||||
return $this->hasMany(ServerVariable::class);
|
||||
}
|
||||
|
||||
public function ensureVariablesExist(): void
|
||||
{
|
||||
foreach ($this->eggVariables as $variable) {
|
||||
ServerVariable::firstOrCreate([
|
||||
'server_id' => $this->id,
|
||||
'variable_id' => $variable->id,
|
||||
], [
|
||||
'variable_value' => $variable->default_value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information for the node associated with this server.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user