Merge pull request #214 from Pterodactyl/analysis-zYo1bG

Apply fixes from StyleCI
This commit is contained in:
Dane Everitt 2016-12-14 16:56:41 -05:00 committed by GitHub
commit 6d59824d00
9 changed files with 98 additions and 88 deletions

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 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
@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Console\Commands;
use Carbon;

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 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
@ -21,20 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Controllers\Admin;
use Alert;
use DB;
use Log;
use Alert;
use Storage;
use Pterodactyl\Models;
use Pterodactyl\Repositories\ServiceRepository\Pack;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Exceptions\DisplayValidationException;
use Pterodactyl\Exceptions\DisplayException;
use Illuminate\Http\Request;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\ServiceRepository\Pack;
use Pterodactyl\Exceptions\DisplayValidationException;
class PackController extends Controller
{
@ -59,7 +58,7 @@ class PackController extends Controller
$array[$option->p_service] = array_merge($array[$option->p_service], [[
'id' => $option->id,
'name' => $option->name
'name' => $option->name,
]]);
}
@ -69,17 +68,18 @@ class PackController extends Controller
public function listAll(Request $request)
{
return view('admin.services.packs.index', [
'services' => Models\Service::all()
'services' => Models\Service::all(),
]);
}
public function listByOption(Request $request, $id)
{
$option = Models\ServiceOptions::findOrFail($id);
return view('admin.services.packs.byoption', [
'packs' => Models\ServicePack::where('option', $option->id)->get(),
'service' => Models\Service::findOrFail($option->parent_service),
'option' => $option
'option' => $option,
]);
}
@ -91,7 +91,7 @@ class PackController extends Controller
'service_options.id',
'service_options.name',
DB::raw('(SELECT COUNT(id) FROM service_packs WHERE service_packs.option = service_options.id) AS p_count')
)->where('parent_service', $id)->get()
)->where('parent_service', $id)->get(),
]);
}
@ -108,9 +108,10 @@ class PackController extends Controller
try {
$repo = new Pack;
$id = $repo->create($request->except([
'_token'
'_token',
]));
Alert::success('Successfully created new service!')->flash();
return redirect()->route('admin.services.packs.edit', $id)->withInput();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.packs.new', $request->input('option'))->withErrors(json_decode($ex->getMessage()))->withInput();
@ -120,6 +121,7 @@ class PackController extends Controller
Log::error($ex);
Alert::danger('An error occured while attempting to add a new service pack.')->flash();
}
return redirect()->route('admin.services.packs.new', $request->input('option'))->withInput();
}
@ -127,12 +129,13 @@ class PackController extends Controller
{
$pack = Models\ServicePack::findOrFail($id);
$option = Models\ServiceOptions::select('id', 'parent_service', 'name')->where('id', $pack->option)->first();
return view('admin.services.packs.edit', [
'pack' => $pack,
'services' => $this->formatServices(),
'files' => Storage::files('packs/' . $pack->uuid),
'service' => Models\Service::findOrFail($option->parent_service),
'option' => $option
'option' => $option,
]);
}
@ -143,6 +146,7 @@ class PackController extends Controller
$repo = new Pack;
$repo->delete($id);
Alert::success('The requested service pack has been deleted from the system.')->flash();
return redirect()->route('admin.services.packs');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
@ -150,12 +154,13 @@ class PackController extends Controller
Log::error($ex);
Alert::danger('An error occured while attempting to delete this pack.')->flash();
}
return redirect()->route('admin.services.packs.edit', $id);
} else {
try {
$repo = new Pack;
$repo->update($id, $request->except([
'_token'
'_token',
]));
Alert::success('Service pack has been successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
@ -164,6 +169,7 @@ class PackController extends Controller
Log::error($ex);
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
}
return redirect()->route('admin.services.packs.edit', $id);
}
}
@ -183,8 +189,8 @@ class PackController extends Controller
'cpu' => $pack->build_cpu,
'io' => $pack->build_io,
'container' => $pack->build_container,
'script' => $pack->build_script
]
'script' => $pack->build_script,
],
];
$filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
@ -207,16 +213,18 @@ class PackController extends Controller
$fp = fopen($filename, 'a+');
fwrite($fp, json_encode($json, JSON_PRETTY_PRINT));
fclose($fp);
return response()->download($filename, 'pack-' . $pack->name . '.json', [
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
])->deleteFileAfterSend(true);
}
}
public function uploadForm(Request $request, $for = null) {
public function uploadForm(Request $request, $for = null)
{
return view('admin.services.packs.upload', [
'services' => $this->formatServices(),
'for' => $for
'for' => $for,
]);
}
@ -225,9 +233,10 @@ class PackController extends Controller
try {
$repo = new Pack;
$id = $repo->createWithTemplate($request->except([
'_token'
'_token',
]));
Alert::success('Successfully created new service!')->flash();
return redirect()->route('admin.services.packs.edit', $id)->withInput();
} catch (DisplayValidationException $ex) {
return redirect()->back()->withErrors(json_decode($ex->getMessage()))->withInput();
@ -237,6 +246,7 @@ class PackController extends Controller
Log::error($ex);
Alert::danger('An error occured while attempting to add a new service pack.')->flash();
}
return redirect()->back();
}
}

View file

@ -28,7 +28,6 @@ use DB;
use Log;
use Alert;
use Storage;
use Validator;
use Pterodactyl\Models;
use Illuminate\Http\Request;
use Pterodactyl\Exceptions\DisplayException;
@ -292,12 +291,13 @@ class ServiceController extends Controller
public function getConfiguration(Request $request, $serviceId)
{
$service = Models\Service::findOrFail($serviceId);
return view('admin.services.config', [
'service' => $service,
'contents' => [
'json' => Storage::get('services/' . $service->file . '/main.json'),
'index' => Storage::get('services/' . $service->file . '/index.js')
]
'index' => Storage::get('services/' . $service->file . '/index.js'),
],
]);
}
@ -306,17 +306,19 @@ class ServiceController extends Controller
try {
$repo = new ServiceRepository\Service;
$repo->updateFile($serviceId, $request->except([
'_token'
'_token',
]));
return response('', 204);
} catch (DisplayException $ex) {
return response()->json([
'error' => $ex->getMessage()
'error' => $ex->getMessage(),
], 503);
} catch (\Exception $ex) {
Log::error($ex);
return response()->json([
'error' => 'An error occured while attempting to save the file.'
'error' => 'An error occured while attempting to save the file.',
], 503);
}
}

View file

@ -148,7 +148,7 @@ class AdminRoutes
]);
$router->post('/new/option-details', [
'uses' => 'Admin\ServersController@postNewServerOptionDetails'
'uses' => 'Admin\ServersController@postNewServerOptionDetails',
]);
// End Assorted Page Helpers
@ -380,11 +380,11 @@ class AdminRoutes
$router->get('/service/{id}/configuration', [
'as' => 'admin.services.service.config',
'uses' => 'Admin\ServiceController@getConfiguration'
'uses' => 'Admin\ServiceController@getConfiguration',
]);
$router->post('/service/{id}/configuration', [
'uses' => 'Admin\ServiceController@postConfiguration'
'uses' => 'Admin\ServiceController@postConfiguration',
]);
$router->get('/service/{service}/option/new', [
@ -435,45 +435,45 @@ class AdminRoutes
'middleware' => [
'auth',
'admin',
'csrf'
]
'csrf',
],
], function () use ($router) {
$router->get('/new/{option?}', [
'as' => 'admin.services.packs.new',
'uses' => 'Admin\PackController@new'
'uses' => 'Admin\PackController@new',
]);
$router->post('/new', [
'uses' => 'Admin\PackController@create'
'uses' => 'Admin\PackController@create',
]);
$router->get('/upload/{option?}', [
'as' => 'admin.services.packs.uploadForm',
'uses' => 'Admin\PackController@uploadForm'
'uses' => 'Admin\PackController@uploadForm',
]);
$router->post('/upload', [
'uses' => 'Admin\PackController@postUpload'
'uses' => 'Admin\PackController@postUpload',
]);
$router->get('/', [
'as' => 'admin.services.packs',
'uses' => 'Admin\PackController@listAll'
'uses' => 'Admin\PackController@listAll',
]);
$router->get('/for/option/{option}', [
'as' => 'admin.services.packs.option',
'uses' => 'Admin\PackController@listByOption'
'uses' => 'Admin\PackController@listByOption',
]);
$router->get('/for/service/{service}', [
'as' => 'admin.services.packs.service',
'uses' => 'Admin\PackController@listByService'
'uses' => 'Admin\PackController@listByService',
]);
$router->get('/edit/{pack}', [
'as' => 'admin.services.packs.edit',
'uses' => 'Admin\PackController@edit'
'uses' => 'Admin\PackController@edit',
]);
$router->post('/edit/{pack}', [
'uses' => 'Admin\PackController@update'
'uses' => 'Admin\PackController@update',
]);
$router->get('/edit/{pack}/export/{archive?}', [
'as' => 'admin.services.packs.export',
'uses' => 'Admin\PackController@export'
'uses' => 'Admin\PackController@export',
]);
});
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 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
@ -21,13 +21,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\Model;
class Checksum extends Model
{
/**
* The table associated with the model.
*
@ -48,7 +48,6 @@ class Checksum extends Model
* @var array
*/
protected $casts = [
'service' => 'integer'
'service' => 'integer',
];
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 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
@ -21,13 +21,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\Model;
class ServicePack extends Model
{
/**
* The table associated with the model.
*
@ -54,7 +54,6 @@ class ServicePack extends Model
'build_cpu' => 'integer',
'build_io' => 'integer',
'selectable' => 'boolean',
'visible' => 'boolean'
'visible' => 'boolean',
];
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 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
@ -21,13 +21,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Repositories\ServiceRepository;
use DB;
use Storage;
use Uuid;
use Storage;
use Validator;
use Pterodactyl\Models;
use Pterodactyl\Services\UuidService;
use Pterodactyl\Exceptions\DisplayException;
@ -35,7 +35,6 @@ use Pterodactyl\Exceptions\DisplayValidationException;
class Pack
{
public function __construct()
{
//
@ -55,7 +54,7 @@ class Pack
'build_cpu' => 'required|integer|min:0',
'build_io' => 'required|integer|min:10|max:1000',
'build_container' => 'required|string',
'build_script' => 'sometimes|nullable|string'
'build_script' => 'sometimes|nullable|string',
]);
if ($validator->fails()) {
@ -69,7 +68,7 @@ class Pack
if (! in_array($data['file_upload']->getMimeType(), [
'application/zip',
'application/gzip'
'application/gzip',
])) {
throw new DisplayException('The file provided does not meet the required filetypes of application/zip or application/gzip.');
}
@ -91,7 +90,7 @@ class Pack
'version' => $data['version'],
'description' => (empty($data['description'])) ? null : $data['description'],
'selectable' => isset($data['selectable']),
'visible' => isset($data['visible'])
'visible' => isset($data['visible']),
]);
Storage::makeDirectory('packs/' . $pack->uuid);
@ -122,7 +121,7 @@ class Pack
if (! in_array($data['file_upload']->getMimeType(), [
'application/zip',
'text/plain',
'application/json'
'application/json',
])) {
throw new DisplayException('The file provided (' . $data['file_upload']->getMimeType() . ') does not meet the required filetypes of application/zip or application/json.');
}
@ -153,7 +152,7 @@ class Pack
'build_cpu' => $json->build->cpu,
'build_io' => $json->build->io,
'build_container' => $json->build->container,
'build_script' => $json->build->script
'build_script' => $json->build->script,
]);
$pack = Models\ServicePack::findOrFail($id);
@ -163,9 +162,11 @@ class Pack
}
$zip->close();
return $pack->id;
} else {
$json = json_decode(file_get_contents($data['file_upload']->path()));
return $this->create([
'name' => $json->name,
'version' => $json->version,
@ -178,10 +179,9 @@ class Pack
'build_cpu' => $json->build->cpu,
'build_io' => $json->build->io,
'build_container' => $json->build->container,
'build_script' => $json->build->script
'build_script' => $json->build->script,
]);
}
}
public function update($id, array $data)
@ -198,7 +198,7 @@ class Pack
'build_cpu' => 'required|integer|min:0',
'build_io' => 'required|integer|min:10|max:1000',
'build_container' => 'required|string',
'build_script' => 'sometimes|string'
'build_script' => 'sometimes|string',
]);
if ($validator->fails()) {
@ -218,14 +218,15 @@ class Pack
'version' => $data['version'],
'description' => (empty($data['description'])) ? null : $data['description'],
'selectable' => isset($data['selectable']),
'visible' => isset($data['visible'])
'visible' => isset($data['visible']),
]);
return true;
});
}
public function delete($id) {
public function delete($id)
{
$pack = Models\ServicePack::findOrFail($id);
// @TODO Check for linked servers; foreign key should block this.
DB::transaction(function () use ($pack) {
@ -233,5 +234,4 @@ class Pack
Storage::deleteDirectory('packs/' . $pack->uuid);
});
}
}

View file

@ -125,7 +125,7 @@ class Service
$validator = Validator::make($data, [
'file' => 'required|in:index,main',
'contents' => 'required|string'
'contents' => 'required|string',
]);
if ($validator->fails()) {
@ -143,6 +143,5 @@ class Service
Storage::move($backup, $filepath);
throw $ex;
}
}
}