mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
init
This commit is contained in:
55
app/Actions/Server/EditServer.php
Executable file
55
app/Actions/Server/EditServer.php
Executable file
@ -0,0 +1,55 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user