mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-17 17:01:37 +00:00
56 lines
1.3 KiB
PHP
Executable File
56 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Actions\Server;
|
|
|
|
use App\Models\Server;
|
|
use App\ValidationRules\RestrictedIPAddressesRule;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class EditServer
|
|
{
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
public function edit(Server $server, array $input): Server
|
|
{
|
|
$this->validate($input);
|
|
|
|
$checkConnection = false;
|
|
if (isset($input['name'])) {
|
|
$server->name = $input['name'];
|
|
}
|
|
if (isset($input['ip'])) {
|
|
if ($server->ip !== $input['ip']) {
|
|
$checkConnection = true;
|
|
}
|
|
$server->ip = $input['ip'];
|
|
}
|
|
if (isset($input['port'])) {
|
|
if ($server->port !== $input['port']) {
|
|
$checkConnection = true;
|
|
}
|
|
$server->port = $input['port'];
|
|
}
|
|
$server->save();
|
|
|
|
if ($checkConnection) {
|
|
$server->checkConnection();
|
|
}
|
|
|
|
return $server;
|
|
}
|
|
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
protected function validate(array $input): void
|
|
{
|
|
Validator::make($input, [
|
|
'ip' => [
|
|
new RestrictedIPAddressesRule(),
|
|
],
|
|
])->validateWithBag('editServer');
|
|
}
|
|
}
|