Fix exception when adjusting mail settings, closes #907

This commit is contained in:
Dane Everitt 2018-02-03 12:28:39 -06:00
parent 48c933fa0f
commit d9355b93b4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 14 additions and 12 deletions

View file

@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### Fixed ### Fixed
* `[rc.1]` — Fixes exception thrown when revoking user sessions. * `[rc.1]` — Fixes exception thrown when revoking user sessions.
* `[rc.1]` — Fixes exception that would occur when trying to delete allocations from a node. * `[rc.1]` — Fixes exception that would occur when trying to delete allocations from a node.
* `[rc.1]` — Fixes exception thown when attempting to adjust mail settings as well as a validation error thrown afterwards.
## v0.7.0-rc.1 (Derelict Dermodactylus) ## v0.7.0-rc.1 (Derelict Dermodactylus)
### Fixed ### Fixed

View file

@ -8,12 +8,12 @@ interface SettingsRepositoryInterface extends RepositoryInterface
* Store a new persistent setting in the database. * Store a new persistent setting in the database.
* *
* @param string $key * @param string $key
* @param string $value * @param string|null $value
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function set(string $key, string $value); public function set(string $key, string $value = null);
/** /**
* Retrieve a persistent setting from the database. * Retrieve a persistent setting from the database.

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Requests\Admin\Settings; namespace Pterodactyl\Http\Requests\Admin\Settings;
use Illuminate\Validation\Rule;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest; use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class MailSettingsFormRequest extends AdminFormRequest class MailSettingsFormRequest extends AdminFormRequest
@ -16,11 +17,11 @@ class MailSettingsFormRequest extends AdminFormRequest
return [ return [
'mail:host' => 'required|string', 'mail:host' => 'required|string',
'mail:port' => 'required|integer|between:1,65535', 'mail:port' => 'required|integer|between:1,65535',
'mail:encryption' => 'present|string|in:"",tls,ssl', 'mail:encryption' => ['present', Rule::in([null, 'tls', 'ssl'])],
'mail:username' => 'string|max:255', 'mail:username' => 'nullable|string|max:255',
'mail:password' => 'string|max:255', 'mail:password' => 'nullable|string|max:255',
'mail:from:address' => 'required|string|email', 'mail:from:address' => 'required|string|email',
'mail:from:name' => 'string|max:255', 'mail:from:name' => 'nullable|string|max:255',
]; ];
} }
@ -31,7 +32,7 @@ class MailSettingsFormRequest extends AdminFormRequest
* @param array $only * @param array $only
* @return array * @return array
*/ */
public function normalize($only = []) public function normalize(array $only = null)
{ {
$keys = array_flip(array_keys($this->rules())); $keys = array_flip(array_keys($this->rules()));

View file

@ -31,16 +31,16 @@ class SettingsRepository extends EloquentRepository implements SettingsRepositor
* Store a new persistent setting in the database. * Store a new persistent setting in the database.
* *
* @param string $key * @param string $key
* @param string $value * @param string|null $value
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function set(string $key, string $value) public function set(string $key, string $value = null)
{ {
// Clear item from the cache. // Clear item from the cache.
$this->clearCache($key); $this->clearCache($key);
$this->withoutFreshModel()->updateOrCreate(['key' => $key], ['value' => $value]); $this->withoutFreshModel()->updateOrCreate(['key' => $key], ['value' => $value ?? '']);
self::$cache[$key] = $value; self::$cache[$key] = $value;
} }