Use daemonRepository instead of BuildModificationService (#1053)

This commit is contained in:
MartinOscar 2025-03-04 00:48:22 +01:00 committed by GitHub
parent 5331c5abfa
commit 5512c10ee1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 16 deletions

View File

@ -17,9 +17,9 @@ use App\Models\Mount;
use App\Models\Server;
use App\Models\ServerVariable;
use App\Models\User;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Services\Databases\DatabaseManagementService;
use App\Services\Eggs\EggChangerService;
use App\Services\Servers\BuildModificationService;
use App\Services\Servers\RandomWordService;
use App\Services\Servers\ReinstallServerService;
use App\Services\Servers\ServerDeletionService;
@ -52,6 +52,7 @@ use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Validator;
use LogicException;
use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction;
@ -62,11 +63,11 @@ class EditServer extends EditRecord
private bool $errored = false;
private BuildModificationService $buildModificationService;
private DaemonServerRepository $daemonServerRepository;
public function boot(BuildModificationService $buildModificationService): void
public function boot(DaemonServerRepository $daemonServerRepository): void
{
$this->buildModificationService = $buildModificationService;
$this->daemonServerRepository = $daemonServerRepository;
}
public function form(Form $form): Form
@ -964,11 +965,12 @@ class EditServer extends EditRecord
return $record;
}
try {
$this->record = $this->buildModificationService->handle($record, $data, true);
/** @var Server $record */
$record = parent::handleRecordUpdate($record, $data);
return $this->record;
} catch (Exception $exception) {
try {
$this->daemonServerRepository->setServer($record)->sync();
} catch (ConnectionException) {
$this->errored = true;
Notification::make()
@ -978,9 +980,9 @@ class EditServer extends EditRecord
->icon('tabler-database')
->warning()
->send();
return parent::handleRecordUpdate($record, $data);
}
return $record;
}
protected function getSavedNotification(): ?Notification

View File

@ -8,7 +8,6 @@ use App\Models\Allocation;
use Illuminate\Database\ConnectionInterface;
use App\Exceptions\DisplayException;
use App\Repositories\Daemon\DaemonServerRepository;
use Exception;
use Illuminate\Http\Client\ConnectionException;
class BuildModificationService
@ -30,7 +29,7 @@ class BuildModificationService
* @throws \Throwable
* @throws \App\Exceptions\DisplayException
*/
public function handle(Server $server, array $data, ?bool $shouldThrow = false): Server
public function handle(Server $server, array $data): Server
{
/** @var \App\Models\Server $server */
$server = $this->connection->transaction(function () use ($server, $data) {
@ -69,10 +68,6 @@ class BuildModificationService
$this->daemonServerRepository->setServer($server)->sync();
} catch (ConnectionException $exception) {
logger()->warning($exception, ['server_id' => $server->id]);
if ($shouldThrow) {
throw $exception;
}
}
}