Apply fixes from StyleCI

This commit is contained in:
Dane Everitt 2016-12-14 21:56:25 +00:00 committed by StyleCI Bot
parent fc38b09e1f
commit efda0dd009
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,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
{
@ -52,14 +51,14 @@ class PackController extends Controller
)->join('services', 'services.id', '=', 'service_options.parent_service')->get();
$array = [];
foreach($options as &$option) {
if (!array_key_exists($option->p_service, $array)) {
foreach ($options as &$option) {
if (! array_key_exists($option->p_service, $array)) {
$array[$option->p_service] = [];
}
$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,22 +129,24 @@ 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,
]);
}
public function update(Request $request, $id)
{
if (!is_null($request->input('action_delete'))) {
if (! is_null($request->input('action_delete'))) {
try {
$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,14 +189,14 @@ 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_');
if ((bool) $files) {
$zip = new \ZipArchive;
if (!$zip->open($filename, \ZipArchive::CREATE)) {
if (! $zip->open($filename, \ZipArchive::CREATE)) {
abort(503, 'Unable to open file for writing.');
}
@ -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',
]);
});
}