diff --git a/app/Services/Servers/TransferServerService.php b/app/Services/Servers/TransferServerService.php index f6a2c80c9..91214a496 100644 --- a/app/Services/Servers/TransferServerService.php +++ b/app/Services/Servers/TransferServerService.php @@ -2,7 +2,10 @@ namespace App\Services\Servers; +use App\Extensions\BackupAdapter\BackupAdapterService; +use App\Extensions\BackupAdapter\Schemas\WingsBackupSchema; use App\Models\Allocation; +use App\Models\Backup; use App\Models\Node; use App\Models\Server; use App\Models\ServerTransfer; @@ -19,16 +22,28 @@ class TransferServerService * TransferService constructor. */ public function __construct( - private ConnectionInterface $connection, - private NodeJWTService $nodeJWTService, + private readonly ConnectionInterface $connection, + private readonly NodeJWTService $nodeJWTService, + private readonly BackupAdapterService $backupService ) {} - /** - * @param string[] $backup_uuids - */ + /** @param string[] $backup_uuids */ // TODO: add backup uuids to ServerTransfer model private function notify(ServerTransfer $transfer, UnencryptedToken $token, array $backup_uuids = []): void { - $backups = []; // TODO + $backups = []; + + // Make sure only wings backups are forwarded in the wings request + foreach ($backup_uuids as $uuid) { + $backup = Backup::find($uuid); + + if ($backup) { + $schema = $this->backupService->get($backup->backupHost->schema); + + if ($schema instanceof WingsBackupSchema) { + $backups[] = $uuid; + } + } + } Http::daemon($transfer->oldNode)->post("/api/servers/{$transfer->server->uuid}/transfer", [ 'url' => $transfer->newNode->getConnectionAddress() . '/api/transfers', @@ -45,11 +60,11 @@ class TransferServerService * Starts a transfer of a server to a new node. * * @param int[] $additional_allocations - * @param string[] $backup_uuid + * @param string[] $backup_uuids * * @throws Throwable */ - public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = [], ?array $backup_uuid = []): bool + public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = [], ?array $backup_uuids = []): bool { $additional_allocations = array_map(intval(...), $additional_allocations); @@ -100,7 +115,7 @@ class TransferServerService ->handle($transfer->newNode, $server->uuid, 'sha256'); // Notify the source node of the pending outgoing transfer. - $this->notify($transfer, $token, $backup_uuid); + $this->notify($transfer, $token, $backup_uuids); return true; }