From 958c29cfbfc40f7d0349e61f37f7800c067c665b Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 1 Jan 2018 12:23:45 -0600 Subject: [PATCH] Fix empty server descriptions throwing SQL errors, closes #842 --- app/Models/Server.php | 2 +- app/Services/Servers/DetailsModificationService.php | 6 +++--- app/Services/Servers/ServerCreationService.php | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Models/Server.php b/app/Models/Server.php index 04ac19e43..6b5af5112 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -76,7 +76,7 @@ class Server extends Model implements CleansAttributes, ValidableContract 'owner_id' => 'exists:users,id', 'name' => 'regex:/^([\w .-]{1,200})$/', 'node_id' => 'exists:nodes,id', - 'description' => 'nullable|string', + 'description' => 'string', 'memory' => 'numeric|min:0', 'swap' => 'numeric|min:-1', 'io' => 'numeric|between:10,1000', diff --git a/app/Services/Servers/DetailsModificationService.php b/app/Services/Servers/DetailsModificationService.php index 5149a8864..d18bccd73 100644 --- a/app/Services/Servers/DetailsModificationService.php +++ b/app/Services/Servers/DetailsModificationService.php @@ -95,9 +95,9 @@ class DetailsModificationService $this->connection->beginTransaction(); $this->repository->withoutFresh()->update($server->id, [ - 'owner_id' => array_get($data, 'owner_id') ?? $server->owner_id, - 'name' => array_get($data, 'name') ?? $server->name, - 'description' => array_get($data, 'description') ?? $server->description, + 'owner_id' => array_get($data, 'owner_id'), + 'name' => array_get($data, 'name'), + 'description' => array_get($data, 'description', ''), ], true, true); if (array_get($data, 'owner_id') != $server->owner_id) { diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index 86e580a22..5aa1d7b24 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -106,6 +106,7 @@ class ServerCreationService * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Validation\ValidationException */ public function create(array $data) { @@ -117,7 +118,7 @@ class ServerCreationService 'uuidShort' => str_random(8), 'node_id' => array_get($data, 'node_id'), 'name' => array_get($data, 'name'), - 'description' => array_get($data, 'description'), + 'description' => array_get($data, 'description', ''), 'skip_scripts' => isset($data['skip_scripts']), 'suspended' => false, 'owner_id' => array_get($data, 'owner_id'),