Merge pull request #214 from Pterodactyl/analysis-zYo1bG
Apply fixes from StyleCI
This commit is contained in:
commit
6d59824d00
9 changed files with 98 additions and 88 deletions
|
@ -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;
|
||||
|
@ -62,7 +63,7 @@ class CleanServiceBackup extends Command
|
|||
{
|
||||
$files = Storage::files('services/.bak');
|
||||
|
||||
foreach($files as $file) {
|
||||
foreach ($files as $file) {
|
||||
$lastModified = Carbon::createFromTimestamp(Storage::lastModified($file));
|
||||
if ($lastModified->diffInMinutes(Carbon::now()) > 5) {
|
||||
$this->info('Deleting ' . $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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -42,11 +42,11 @@ class ServicePack extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'option' => 'integer',
|
||||
'build_memory' => 'integer',
|
||||
|
@ -54,7 +54,6 @@ class ServicePack extends Model
|
|||
'build_cpu' => 'integer',
|
||||
'build_io' => 'integer',
|
||||
'selectable' => 'boolean',
|
||||
'visible' => 'boolean'
|
||||
'visible' => 'boolean',
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -162,9 +162,9 @@ class ServerRepository
|
|||
$data['pack'] = null;
|
||||
}
|
||||
|
||||
if (!is_null($data['pack'])) {
|
||||
if (! is_null($data['pack'])) {
|
||||
$pack = Models\ServicePack::where('id', $data['pack'])->where('option', $data['option'])->first();
|
||||
if (!$pack) {
|
||||
if (! $pack) {
|
||||
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
@ -63,13 +62,13 @@ class Pack
|
|||
}
|
||||
|
||||
if (isset($data['file_upload'])) {
|
||||
if (!$data['file_upload']->isValid()) {
|
||||
if (! $data['file_upload']->isValid()) {
|
||||
throw new DisplayException('The file provided does not appear to be valid.');
|
||||
}
|
||||
|
||||
if (!in_array($data['file_upload']->getMimeType(), [
|
||||
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);
|
||||
|
@ -111,25 +110,25 @@ class Pack
|
|||
|
||||
public function createWithTemplate(array $data)
|
||||
{
|
||||
if (!isset($data['file_upload'])) {
|
||||
if (! isset($data['file_upload'])) {
|
||||
throw new DisplayException('No template file was found submitted with this request.');
|
||||
}
|
||||
|
||||
if (!$data['file_upload']->isValid()) {
|
||||
if (! $data['file_upload']->isValid()) {
|
||||
throw new DisplayException('The file provided does not appear to be valid.');
|
||||
}
|
||||
|
||||
if (!in_array($data['file_upload']->getMimeType(), [
|
||||
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.');
|
||||
}
|
||||
|
||||
if ($data['file_upload']->getMimeType() === 'application/zip') {
|
||||
$zip = new \ZipArchive;
|
||||
if (!$zip->open($data['file_upload']->path())) {
|
||||
if (! $zip->open($data['file_upload']->path())) {
|
||||
throw new DisplayException('The uploaded archive was unable to be opened.');
|
||||
}
|
||||
|
||||
|
@ -153,19 +152,21 @@ 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);
|
||||
if (!$zip->extractTo(storage_path('app/packs/' . $pack->uuid), ($isZip === false) ? 'archive.tar.gz' : 'archive.zip')) {
|
||||
if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), ($isZip === false) ? 'archive.tar.gz' : 'archive.zip')) {
|
||||
$pack->delete();
|
||||
throw new DisplayException('Unable to extract the archive file to the correct location.');
|
||||
}
|
||||
|
||||
$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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ class Service
|
|||
|
||||
$validator = Validator::make($data, [
|
||||
'file' => 'required|in:index,main',
|
||||
'contents' => 'required|string'
|
||||
'contents' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -139,10 +139,9 @@ class Service
|
|||
try {
|
||||
Storage::move($filepath, $backup);
|
||||
Storage::put($filepath, $data['contents']);
|
||||
} catch(\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
Storage::move($backup, $filepath);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue