Files
ploi-core/app/Actions/Server/SynchronizeServerAction.php
Dennis be00824f59 wip
2023-01-12 11:44:17 +01:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Actions\Server;
use App\Models\Server;
use App\Services\Ploi\Ploi;
use Filament\Notifications\Notification;
class SynchronizeServerAction
{
public function execute(int $ploiServerId): Server|null
{
try {
$serverData = Ploi::make()->server()->get($ploiServerId)->getData();
} catch (\Throwable $exception) {
Notification::make()
->body('An error has occurred: ' . $exception->getMessage())
->danger()
->send();
return null;
}
try {
$server = Server::query()
->updateOrCreate([
'ploi_id' => $serverData->id,
], [
'status' => $serverData->status,
'name' => $serverData->name,
'ip' => $serverData->ip_address,
'ssh_port' => $serverData->ssh_port,
'internal_ip' => $serverData->internal_ip,
'available_php_versions' => $serverData->installed_php_versions,
]);
} catch (\Throwable $exception) {
Notification::make()
->body('An error has occurred: ' . $exception->getMessage())
->danger()
->send();
return null;
}
Notification::make()
->body(__('Server :server synchronized successfully.', ['server' => $server->name]))
->success()
->send();
return $server;
}
}