diff --git a/app/Http/Controllers/Admin/Servers/ServerTransferController.php b/app/Http/Controllers/Admin/Servers/ServerTransferController.php index b4afa2cab..9166ae3e9 100644 --- a/app/Http/Controllers/Admin/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Admin/Servers/ServerTransferController.php @@ -97,6 +97,8 @@ class ServerTransferController extends Controller // Check if the selected daemon is online. $this->daemonConfigurationRepository->setNode($node)->getSystemInformation(); + $server->validateTransferState(); + // Create a new ServerTransfer entry. $transfer = new ServerTransfer(); diff --git a/app/Models/Server.php b/app/Models/Server.php index fa690d353..b1560bb28 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -400,4 +400,21 @@ class Server extends Model throw new ServerStateConflictException($this); } } + + /** + * Checks if the server is currently in a transferable state. If not, an + * exception is raised. This should be called whenever something needs to make + * sure the server is able to be transferred and is not currently being transferred + * or installed. + */ + public function validateTransferState() + { + if ( + !$this->isInstalled() || + $this->status === self::STATUS_RESTORING_BACKUP || + !is_null($this->transfer) + ) { + throw new ServerStateConflictException($this); + } + } }