Handle allocation assignment using services

Function is significantly quicker and uses 1 SQL query per IP rather than 1 query per port.
This commit is contained in:
Dane Everitt 2017-08-05 21:10:32 -05:00
parent 396b5c22d9
commit 669119c8f8
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
17 changed files with 754 additions and 5915 deletions

View file

@ -26,7 +26,7 @@ namespace Pterodactyl\Http\Requests\Admin;
use Pterodactyl\Models\Location;
class LocationRequest extends AdminFormRequest
class LocationFormRequest extends AdminFormRequest
{
/**
* Setup the validation rules to use for these requests.
@ -36,7 +36,7 @@ class LocationRequest extends AdminFormRequest
public function rules()
{
if ($this->method() === 'PATCH') {
return Location::getUpdateRulesForId($this->location->id);
return Location::getUpdateRulesForId($this->route()->parameter('location')->id);
}
return Location::getCreateRules();

View file

@ -0,0 +1,41 @@
<?php
/*
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin\Node;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class AllocationAliasFormRequest extends AdminFormRequest
{
/**
* @return array
*/
public function rules()
{
return [
'alias' => 'required|nullable|string',
'allocation_id' => 'required|numeric|exists:allocations,id',
];
}
}

View file

@ -0,0 +1,42 @@
<?php
/*
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin\Node;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class AllocationFormRequest extends AdminFormRequest
{
/**
* @return array
*/
public function rules()
{
return [
'allocation_ip' => 'required|string',
'allocation_alias' => 'sometimes|string|max:255',
'allocation_ports' => 'required|array',
];
}
}

View file

@ -22,9 +22,10 @@
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin;
namespace Pterodactyl\Http\Requests\Admin\Node;
use Pterodactyl\Models\Node;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class NodeFormRequest extends AdminFormRequest
{

View file

@ -34,7 +34,7 @@ class UserFormRequest extends AdminFormRequest
public function rules()
{
if ($this->method() === 'PATCH') {
return User::getUpdateRulesForId($this->user->id);
return User::getUpdateRulesForId($this->route()->parameter('user')->id);
}
return User::getCreateRules();