From ffc8d4875f198eb3fa1619a8e1a176b8caba00c1 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 1 Jan 2018 12:32:33 -0600 Subject: [PATCH] Fix unability to store '-1' in the database properly --- CHANGELOG.md | 2 ++ .../Servers/BuildModificationService.php | 18 ++++------- ...22821_AllowNegativeValuesForServerSwap.php | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php diff --git a/CHANGELOG.md b/CHANGELOG.md index aace034eb..a623e9d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * `[beta.3]` — Fixes a bug that would cause an error when attempting to create a new user on the Panel. * `[beta.3]` — Fixes error handling of the settings service provider when no migrations have been run. * `[beta.3]` — Fixes validation error when trying to use 'None' as the 'Copy Script From' option for an egg script. +* Fixes a design bug in the database that prevented the storage of negative numbers, thus preventing a server from being assigned unlimited swap. + ### Added * Nest and Egg listings now show the associated ID in order to make API requests easier. diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index bc4cd5333..9aa1fa4c5 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Servers; @@ -113,6 +106,7 @@ class BuildModificationService * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function handle($server, array $data) { @@ -138,11 +132,11 @@ class BuildModificationService } $server = $this->repository->update($server->id, [ - 'memory' => array_get($data, 'memory', $server->memory), - 'swap' => array_get($data, 'swap', $server->swap), - 'io' => array_get($data, 'io', $server->io), - 'cpu' => array_get($data, 'cpu', $server->cpu), - 'disk' => array_get($data, 'disk', $server->disk), + 'memory' => (int) array_get($data, 'memory', $server->memory), + 'swap' => (int) array_get($data, 'swap', $server->swap), + 'io' => (int) array_get($data, 'io', $server->io), + 'cpu' => (int) array_get($data, 'cpu', $server->cpu), + 'disk' => (int) array_get($data, 'disk', $server->disk), 'allocation_id' => array_get($data, 'allocation_id', $server->allocation_id), ]); diff --git a/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php b/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php new file mode 100644 index 000000000..8f9938da1 --- /dev/null +++ b/database/migrations/2018_01_01_122821_AllowNegativeValuesForServerSwap.php @@ -0,0 +1,32 @@ +integer('swap')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->unsignedInteger('swap')->change(); + }); + } +}