Completed model updates for Services
This commit is contained in:
parent
09d23deed6
commit
323f1d943f
26 changed files with 299 additions and 167 deletions
|
@ -53,7 +53,7 @@ class ServiceController extends BaseController
|
|||
return [
|
||||
'service' => $service,
|
||||
'options' => Models\ServiceOptions::select('id', 'name', 'description', 'tag', 'docker_image')
|
||||
->where('parent_service', $service->id)
|
||||
->where('service_id', $service->id)
|
||||
->with('variables')
|
||||
->with('packs')
|
||||
->get(),
|
||||
|
|
|
@ -42,64 +42,29 @@ class PackController extends Controller
|
|||
//
|
||||
}
|
||||
|
||||
protected function formatServices()
|
||||
{
|
||||
$options = Models\ServiceOptions::select(
|
||||
'services.name AS p_service',
|
||||
'service_options.id',
|
||||
'service_options.name'
|
||||
)->join('services', 'services.id', '=', 'service_options.parent_service')->get();
|
||||
|
||||
$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,
|
||||
]]);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function listAll(Request $request)
|
||||
{
|
||||
return view('admin.services.packs.index', [
|
||||
'services' => Models\Service::all(),
|
||||
]);
|
||||
return view('admin.services.packs.index', ['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' => Models\ServiceOptions::with('service', 'packs')->findOrFail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
public function listByService(Request $request, $id)
|
||||
{
|
||||
return view('admin.services.packs.byservice', [
|
||||
'service' => Models\Service::findOrFail($id),
|
||||
'options' => Models\ServiceOptions::select(
|
||||
'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(),
|
||||
'service' => Models\Service::with('options', 'options.packs')->findOrFail($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function new(Request $request, $opt = null)
|
||||
{
|
||||
return view('admin.services.packs.new', [
|
||||
'services' => $this->formatServices(),
|
||||
'packFor' => $opt,
|
||||
'services' => Models\Service::with('options')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -107,12 +72,18 @@ class PackController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$id = $repo->create($request->except([
|
||||
'_token',
|
||||
$pack = $repo->create($request->only([
|
||||
'name',
|
||||
'version',
|
||||
'description',
|
||||
'option',
|
||||
'selectable',
|
||||
'visible',
|
||||
'file_upload',
|
||||
]));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $id)->withInput();
|
||||
return redirect()->route('admin.services.packs.edit', $pack->id)->withInput();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.packs.new', $request->input('option'))->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
|
@ -127,15 +98,12 @@ class PackController extends Controller
|
|||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$pack = Models\ServicePack::findOrFail($id);
|
||||
$option = Models\ServiceOptions::select('id', 'parent_service', 'name')->where('id', $pack->option)->first();
|
||||
$pack = Models\ServicePack::with('option.service')->findOrFail($id);
|
||||
|
||||
return view('admin.services.packs.edit', [
|
||||
'pack' => $pack,
|
||||
'services' => $this->formatServices(),
|
||||
'services' => Models\Service::all()->load('options'),
|
||||
'files' => Storage::files('packs/' . $pack->uuid),
|
||||
'service' => Models\Service::findOrFail($option->parent_service),
|
||||
'option' => $option,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -159,8 +127,13 @@ class PackController extends Controller
|
|||
} else {
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$repo->update($id, $request->except([
|
||||
'_token',
|
||||
$repo->update($id, $request->only([
|
||||
'name',
|
||||
'version',
|
||||
'description',
|
||||
'option',
|
||||
'selectable',
|
||||
'visible',
|
||||
]));
|
||||
Alert::success('Service pack has been successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
|
@ -215,8 +188,7 @@ class PackController extends Controller
|
|||
public function uploadForm(Request $request, $for = null)
|
||||
{
|
||||
return view('admin.services.packs.upload', [
|
||||
'services' => $this->formatServices(),
|
||||
'for' => $for,
|
||||
'services' => Models\Service::all()->load('options'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -224,12 +196,10 @@ class PackController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$id = $repo->createWithTemplate($request->except([
|
||||
'_token',
|
||||
]));
|
||||
$pack = $repo->createWithTemplate($request->only(['option', 'file_upload']));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $id)->withInput();
|
||||
return redirect()->route('admin.services.packs.edit', $pack->id)->withInput();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->back()->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
|
|
|
@ -244,7 +244,7 @@ class ServersController extends Controller
|
|||
|
||||
$service = Models\Service::select('executable', 'startup')->where('id', $request->input('service'))->first();
|
||||
|
||||
return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get());
|
||||
return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('service_id', $request->input('service'))->orderBy('name', 'asc')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,7 +264,7 @@ class ServersController extends Controller
|
|||
$option = Models\ServiceOptions::select(
|
||||
DB::raw('COALESCE(service_options.executable, services.executable) as executable'),
|
||||
DB::raw('COALESCE(service_options.startup, services.startup) as startup')
|
||||
)->leftJoin('services', 'services.id', '=', 'service_options.parent_service')
|
||||
)->leftJoin('services', 'services.id', '=', 'service_options.service_id')
|
||||
->where('service_options.id', $request->input('option'))
|
||||
->first();
|
||||
|
||||
|
|
|
@ -45,10 +45,7 @@ class ServiceController extends Controller
|
|||
public function getIndex(Request $request)
|
||||
{
|
||||
return view('admin.services.index', [
|
||||
'services' => Models\Service::select(
|
||||
'services.*',
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.service = services.id) as c_servers')
|
||||
)->get(),
|
||||
'services' => Models\Service::withCount('servers')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -61,12 +58,16 @@ class ServiceController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Service;
|
||||
$id = $repo->create($request->except([
|
||||
'_token',
|
||||
$service = $repo->create($request->only([
|
||||
'name',
|
||||
'description',
|
||||
'file',
|
||||
'executable',
|
||||
'startup',
|
||||
]));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.service', $id);
|
||||
return redirect()->route('admin.services.service', $service->id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
|
@ -82,11 +83,7 @@ class ServiceController extends Controller
|
|||
public function getService(Request $request, $service)
|
||||
{
|
||||
return view('admin.services.view', [
|
||||
'service' => Models\Service::findOrFail($service),
|
||||
'options' => Models\ServiceOptions::select(
|
||||
'service_options.*',
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.option = service_options.id) as c_servers')
|
||||
)->where('parent_service', $service)->get(),
|
||||
'service' => Models\Service::with('options', 'options.servers')->findOrFail($service),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -94,8 +91,12 @@ class ServiceController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Service;
|
||||
$repo->update($service, $request->except([
|
||||
'_token',
|
||||
$repo->update($service, $request->only([
|
||||
'name',
|
||||
'description',
|
||||
'file',
|
||||
'executable',
|
||||
'startup',
|
||||
]));
|
||||
Alert::success('Successfully updated this service.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
|
@ -130,16 +131,11 @@ class ServiceController extends Controller
|
|||
|
||||
public function getOption(Request $request, $service, $option)
|
||||
{
|
||||
$opt = Models\ServiceOptions::findOrFail($option);
|
||||
$option = Models\ServiceOptions::with('service', 'variables')->findOrFail($option);
|
||||
$option->setRelation('servers', $option->servers()->with('user')->paginate(25));
|
||||
|
||||
return view('admin.services.options.view', [
|
||||
'service' => Models\Service::findOrFail($opt->parent_service),
|
||||
'option' => $opt,
|
||||
'variables' => Models\ServiceVariables::where('option_id', $option)->get(),
|
||||
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail')
|
||||
->join('users', 'users.id', '=', 'servers.owner_id')
|
||||
->where('option', $option)
|
||||
->paginate(10),
|
||||
'option' => $option,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -147,8 +143,13 @@ class ServiceController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Option;
|
||||
$repo->update($option, $request->except([
|
||||
'_token',
|
||||
$repo->update($option, $request->only([
|
||||
'name',
|
||||
'description',
|
||||
'tag',
|
||||
'executable',
|
||||
'docker_image',
|
||||
'startup',
|
||||
]));
|
||||
Alert::success('Option settings successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
|
@ -164,13 +165,12 @@ class ServiceController extends Controller
|
|||
public function deleteOption(Request $request, $service, $option)
|
||||
{
|
||||
try {
|
||||
$service = Models\ServiceOptions::select('parent_service')->where('id', $option)->first();
|
||||
$repo = new ServiceRepository\Option;
|
||||
$repo->delete($option);
|
||||
|
||||
Alert::success('Successfully deleted that option.')->flash();
|
||||
|
||||
return redirect()->route('admin.services.service', $service->parent_service);
|
||||
return redirect()->route('admin.services.service', $service);
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
|
@ -218,8 +218,7 @@ class ServiceController extends Controller
|
|||
public function getNewVariable(Request $request, $service, $option)
|
||||
{
|
||||
return view('admin.services.options.variable', [
|
||||
'service' => Models\Service::findOrFail($service),
|
||||
'option' => Models\ServiceOptions::where('parent_service', $service)->where('id', $option)->firstOrFail(),
|
||||
'option' => Models\ServiceOptions::with('service')->findOrFail($option),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -227,8 +226,15 @@ class ServiceController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Variable;
|
||||
$repo->create($option, $request->except([
|
||||
'_token',
|
||||
$repo->create($option, $request->only([
|
||||
'name',
|
||||
'description',
|
||||
'env_variable',
|
||||
'default_value',
|
||||
'user_viewable',
|
||||
'user_editable',
|
||||
'required',
|
||||
'regex',
|
||||
]));
|
||||
Alert::success('Successfully added new variable to this option.')->flash();
|
||||
|
||||
|
@ -305,8 +311,9 @@ class ServiceController extends Controller
|
|||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Service;
|
||||
$repo->updateFile($serviceId, $request->except([
|
||||
'_token',
|
||||
$repo->updateFile($serviceId, $request->only([
|
||||
'file',
|
||||
'contents',
|
||||
]));
|
||||
|
||||
return response('', 204);
|
||||
|
|
|
@ -224,7 +224,7 @@ class ServerController extends Controller
|
|||
|
||||
$service = Models\Service::select(
|
||||
DB::raw('IFNULL(service_options.executable, services.executable) as executable')
|
||||
)->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
|
||||
)->leftJoin('service_options', 'service_options.service_id', '=', 'services.id')
|
||||
->where('service_options.id', $server->option_id)
|
||||
->where('services.id', $server->service_id)
|
||||
->first();
|
||||
|
|
|
@ -40,5 +40,38 @@ class Service extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
protected $fillable = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Gets all service options associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function options()
|
||||
{
|
||||
return $this->hasMany(ServiceOptions::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the packs associated with a service, regardless of the service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function packs()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
'Pterodactyl\Models\ServicePack', 'Pterodactyl\Models\ServiceOptions',
|
||||
'service_id', 'option_id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all servers associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,29 @@ class ServiceOptions extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'parent_service' => 'integer',
|
||||
'service_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets service associated with a service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all servers associated with this service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class, 'option_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all variables associated with this service.
|
||||
*
|
||||
|
@ -68,6 +88,6 @@ class ServiceOptions extends Model
|
|||
*/
|
||||
public function packs()
|
||||
{
|
||||
return $this->hasMany(ServicePack::class, 'option');
|
||||
return $this->hasMany(ServicePack::class, 'option_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,4 +56,14 @@ class ServicePack extends Model
|
|||
'selectable' => 'boolean',
|
||||
'visible' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets option associated with a service pack.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
return $this->belongsTo(ServiceOptions::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,4 +53,9 @@ class ServiceVariables extends Model
|
|||
'user_editable' => 'integer',
|
||||
'required' => 'integer',
|
||||
];
|
||||
|
||||
public function serverVariables()
|
||||
{
|
||||
return $this->hasMany(ServerVariables::class, 'variable_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class ServerObserver
|
|||
$user = Models\User::findOrFail($server->owner_id);
|
||||
$node = Models\Node::select('name')->where('id', $server->node_id)->first();
|
||||
$service = Models\Service::select('services.name', 'service_options.name as optionName')
|
||||
->join('service_options', 'service_options.parent_service', '=', 'services.id')
|
||||
->join('service_options', 'service_options.service_id', '=', 'services.id')
|
||||
->where('services.id', $server->service_id)
|
||||
->where('service_options.id', $server->option_id)
|
||||
->first();
|
||||
|
|
|
@ -163,7 +163,7 @@ class ServerRepository
|
|||
// We know the service and option exists because of the validation.
|
||||
// We need to verify that the option exists for the service, and then check for
|
||||
// any required variable fields. (fields are labeled env_<env_variable>)
|
||||
$option = Models\ServiceOptions::where('id', $data['option'])->where('parent_service', $data['service'])->first();
|
||||
$option = Models\ServiceOptions::where('id', $data['option'])->where('service_id', $data['service'])->first();
|
||||
if (! $option) {
|
||||
throw new DisplayException('The requested service option does not exist for the specified service.');
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ class ServerRepository
|
|||
}
|
||||
|
||||
// Load up the Service Information
|
||||
$service = Models\Service::find($option->parent_service);
|
||||
$service = Models\Service::find($option->service_id);
|
||||
|
||||
// Check those Variables
|
||||
$variables = Models\ServiceVariables::where('option_id', $data['option'])->get();
|
||||
|
|
|
@ -63,7 +63,7 @@ class Option
|
|||
}
|
||||
|
||||
$option = new Models\ServiceOptions;
|
||||
$option->parent_service = $service->id;
|
||||
$option->service_id = $service->id;
|
||||
$option->fill($data);
|
||||
$option->save();
|
||||
|
||||
|
|
|
@ -69,8 +69,8 @@ class Pack
|
|||
try {
|
||||
$uuid = new UuidService;
|
||||
$pack = Models\ServicePack::create([
|
||||
'option' => $data['option'],
|
||||
'uuid' => $uuid->generate('servers', 'uuid'),
|
||||
'option_id' => $data['option'],
|
||||
'uuid' => $uuid->generate('service_packs', 'uuid'),
|
||||
'name' => $data['name'],
|
||||
'version' => $data['version'],
|
||||
'description' => (empty($data['description'])) ? null : $data['description'],
|
||||
|
@ -89,7 +89,7 @@ class Pack
|
|||
throw $ex;
|
||||
}
|
||||
|
||||
return $pack->id;
|
||||
return $pack;
|
||||
}
|
||||
|
||||
public function createWithTemplate(array $data)
|
||||
|
@ -123,7 +123,7 @@ class Pack
|
|||
}
|
||||
|
||||
$json = json_decode($zip->getFromName('import.json'));
|
||||
$id = $this->create([
|
||||
$pack = $this->create([
|
||||
'name' => $json->name,
|
||||
'version' => $json->version,
|
||||
'description' => $json->description,
|
||||
|
@ -132,7 +132,6 @@ class Pack
|
|||
'visible' => $json->visible,
|
||||
]);
|
||||
|
||||
$pack = Models\ServicePack::findOrFail($id);
|
||||
if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) {
|
||||
$pack->delete();
|
||||
throw new DisplayException('Unable to extract the archive file to the correct location.');
|
||||
|
@ -140,7 +139,7 @@ class Pack
|
|||
|
||||
$zip->close();
|
||||
|
||||
return $pack->id;
|
||||
return $pack;
|
||||
} else {
|
||||
$json = json_decode(file_get_contents($data['file_upload']->path()));
|
||||
|
||||
|
@ -170,18 +169,16 @@ class Pack
|
|||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($id, $data) {
|
||||
Models\ServicePack::findOrFail($id)->update([
|
||||
'option' => $data['option'],
|
||||
'name' => $data['name'],
|
||||
'version' => $data['version'],
|
||||
'description' => (empty($data['description'])) ? null : $data['description'],
|
||||
'selectable' => isset($data['selectable']),
|
||||
'visible' => isset($data['visible']),
|
||||
]);
|
||||
Models\ServicePack::findOrFail($id)->update([
|
||||
'option_id' => $data['option'],
|
||||
'name' => $data['name'],
|
||||
'version' => $data['version'],
|
||||
'description' => (empty($data['description'])) ? null : $data['description'],
|
||||
'selectable' => isset($data['selectable']),
|
||||
'visible' => isset($data['visible']),
|
||||
]);
|
||||
|
||||
return true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
|
|
|
@ -55,23 +55,18 @@ class Service
|
|||
|
||||
$data['author'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
|
||||
|
||||
$service = new Models\Service;
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$service->fill($data);
|
||||
$service->save();
|
||||
|
||||
Storage::put('services/' . $data['file'] . '/main.json', '{}');
|
||||
Storage::copy('services/.templates/index.js', 'services/' . $data['file'] . '/index.js');
|
||||
|
||||
$service = Models\Service::create($data);
|
||||
Storage::put('services/' . $service->file . '/main.json', '{}');
|
||||
Storage::copy('services/.templates/index.js', 'services/' . $service->file . '/index.js');
|
||||
DB::commit();
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return $service->id;
|
||||
return $service;
|
||||
}
|
||||
|
||||
public function update($id, array $data)
|
||||
|
@ -99,7 +94,7 @@ class Service
|
|||
{
|
||||
$service = Models\Service::findOrFail($id);
|
||||
$servers = Models\Server::where('service', $service->id)->get();
|
||||
$options = Models\ServiceOptions::select('id')->where('parent_service', $service->id);
|
||||
$options = Models\ServiceOptions::select('id')->where('service_id', $service->id);
|
||||
|
||||
if (count($servers) !== 0) {
|
||||
throw new DisplayException('You cannot delete a service that has servers associated with it.');
|
||||
|
|
|
@ -39,7 +39,7 @@ class Variable
|
|||
|
||||
public function create($id, array $data)
|
||||
{
|
||||
$option = Models\ServiceOptions::findOrFail($id);
|
||||
$option = Models\ServiceOptions::select('id')->findOrFail($id);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'required|string|min:1|max:255',
|
||||
|
@ -67,21 +67,22 @@ class Variable
|
|||
$data['user_viewable'] = (isset($data['user_viewable']) && in_array((int) $data['user_viewable'], [0, 1])) ? $data['user_viewable'] : 0;
|
||||
$data['user_editable'] = (isset($data['user_editable']) && in_array((int) $data['user_editable'], [0, 1])) ? $data['user_editable'] : 0;
|
||||
$data['required'] = (isset($data['required']) && in_array((int) $data['required'], [0, 1])) ? $data['required'] : 0;
|
||||
$data['option_id'] = $option->id;
|
||||
|
||||
$variable = new Models\ServiceVariables;
|
||||
$variable->option_id = $option->id;
|
||||
$variable->fill($data);
|
||||
$variable = Models\ServiceVariables::create($data);
|
||||
|
||||
return $variable->save();
|
||||
return $variable;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$variable = Models\ServiceVariables::findOrFail($id);
|
||||
$variable = Models\ServiceVariables::with('serverVariables')->findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
Models\ServerVariables::where('variable_id', $variable->id)->delete();
|
||||
foreach($variable->serverVariables as $svar) {
|
||||
$svar->delete();
|
||||
}
|
||||
$variable->delete();
|
||||
|
||||
DB::commit();
|
||||
|
@ -125,7 +126,18 @@ class Variable
|
|||
$data['user_editable'] = (isset($data['user_editable']) && in_array((int) $data['user_editable'], [0, 1])) ? $data['user_editable'] : $variable->user_editable;
|
||||
$data['required'] = (isset($data['required']) && in_array((int) $data['required'], [0, 1])) ? $data['required'] : $variable->required;
|
||||
|
||||
$variable->fill($data);
|
||||
// Not using $data because the function that passes into this function
|
||||
// can't do $requst->only() due to the page setup.
|
||||
$variable->fill([
|
||||
'name' => $data['name'],
|
||||
'description' => $data['description'],
|
||||
'env_variable' => $data['env_variable'],
|
||||
'default_value' => $data['default_value'],
|
||||
'user_viewable' => $data['user_viewable'],
|
||||
'user_editable' => $data['user_editable'],
|
||||
'required' => $data['required'],
|
||||
'regex' => $data['regex'],
|
||||
]);
|
||||
|
||||
return $variable->save();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue