Apply fixes from StyleCI
This commit is contained in:
parent
fc38b09e1f
commit
efda0dd009
9 changed files with 98 additions and 88 deletions
app/Http/Controllers/Admin
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue