Fix errors with mounts; closes #2374
This commit is contained in:
parent
b4a9a7205d
commit
99c9682f67
7 changed files with 63 additions and 186 deletions
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Services\Mounts\MountUpdateService;
|
||||
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
|
||||
|
@ -37,21 +39,6 @@ class MountController extends Controller
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Mounts\MountCreationService
|
||||
*/
|
||||
protected $creationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Mounts\MountDeletionService
|
||||
*/
|
||||
protected $deletionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Mounts\MountUpdateService
|
||||
*/
|
||||
protected $updateService;
|
||||
|
||||
/**
|
||||
* MountController constructor.
|
||||
*
|
||||
|
@ -59,26 +46,17 @@ class MountController extends Controller
|
|||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
|
||||
* @param \Pterodactyl\Services\Mounts\MountDeletionService $deletionService
|
||||
* @param \Pterodactyl\Services\Mounts\MountUpdateService $updateService
|
||||
*/
|
||||
public function __construct(
|
||||
AlertsMessageBag $alert,
|
||||
NestRepositoryInterface $nestRepository,
|
||||
LocationRepositoryInterface $locationRepository,
|
||||
MountRepository $repository,
|
||||
MountCreationService $creationService,
|
||||
MountDeletionService $deletionService,
|
||||
MountUpdateService $updateService
|
||||
MountRepository $repository
|
||||
) {
|
||||
$this->alert = $alert;
|
||||
$this->nestRepository = $nestRepository;
|
||||
$this->locationRepository = $locationRepository;
|
||||
$this->repository = $repository;
|
||||
$this->creationService = $creationService;
|
||||
$this->deletionService = $deletionService;
|
||||
$this->updateService = $updateService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,11 +81,8 @@ class MountController extends Controller
|
|||
*/
|
||||
public function view($id)
|
||||
{
|
||||
$nests = $this->nestRepository->all();
|
||||
$nests->load('eggs');
|
||||
|
||||
$locations = $this->locationRepository->all();
|
||||
$locations->load('nodes');
|
||||
$nests = Nest::query()->with('eggs')->get();
|
||||
$locations = Location::query()->with('nodes')->get();
|
||||
|
||||
return view('admin.mounts.view', [
|
||||
'mount' => $this->repository->getWithRelations($id),
|
||||
|
@ -126,7 +101,11 @@ class MountController extends Controller
|
|||
*/
|
||||
public function create(MountFormRequest $request)
|
||||
{
|
||||
$mount = $this->creationService->handle($request->normalize());
|
||||
/** @var \Pterodactyl\Models\Mount $mount */
|
||||
$mount = Mount::query()->create(array_merge($request->validated(), [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
|
||||
$this->alert->success('Mount was created successfully.')->flash();
|
||||
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
|
@ -147,7 +126,8 @@ class MountController extends Controller
|
|||
return $this->delete($mount);
|
||||
}
|
||||
|
||||
$this->updateService->handle($mount->id, $request->normalize());
|
||||
$mount->forceFill($request->validated())->save();
|
||||
|
||||
$this->alert->success('Mount was updated successfully.')->flash();
|
||||
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
|
@ -163,15 +143,9 @@ class MountController extends Controller
|
|||
*/
|
||||
public function delete(Mount $mount)
|
||||
{
|
||||
try {
|
||||
$this->deletionService->handle($mount->id);
|
||||
$mount->delete();
|
||||
|
||||
return redirect()->route('admin.mounts');
|
||||
} catch (DisplayException $ex) {
|
||||
$this->alert->danger($ex->getMessage())->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,11 +162,12 @@ class MountController extends Controller
|
|||
]);
|
||||
|
||||
$eggs = $validatedData['eggs'] ?? [];
|
||||
if (sizeof($eggs) > 0) {
|
||||
$mount->eggs()->attach(array_map('intval', $eggs));
|
||||
$this->alert->success('Mount was updated successfully.')->flash();
|
||||
if (count($eggs) > 0) {
|
||||
$mount->eggs()->attach($eggs);
|
||||
}
|
||||
|
||||
$this->alert->success('Mount was updated successfully.')->flash();
|
||||
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
}
|
||||
|
||||
|
@ -205,16 +180,15 @@ class MountController extends Controller
|
|||
*/
|
||||
public function addNodes(Request $request, Mount $mount)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'nodes' => 'required|exists:nodes,id',
|
||||
]);
|
||||
$data = $request->validate(['nodes' => 'required|exists:nodes,id']);
|
||||
|
||||
$nodes = $validatedData['nodes'] ?? [];
|
||||
if (sizeof($nodes) > 0) {
|
||||
$mount->nodes()->attach(array_map('intval', $nodes));
|
||||
$this->alert->success('Mount was updated successfully.')->flash();
|
||||
$nodes = $data['nodes'] ?? [];
|
||||
if (count($nodes) > 0) {
|
||||
$mount->nodes()->attach($nodes);
|
||||
}
|
||||
|
||||
$this->alert->success('Mount was updated successfully.')->flash();
|
||||
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Pterodactyl\Http\Controllers\Admin;
|
|||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
@ -412,12 +413,18 @@ class ServersController extends Controller
|
|||
* Add a mount to a server.
|
||||
*
|
||||
* @param Server $server
|
||||
* @param int $mount_id
|
||||
* @param \Pterodactyl\Models\Mount $mount
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function addMount(Server $server, int $mount_id)
|
||||
public function addMount(Server $server, Mount $mount)
|
||||
{
|
||||
$server->mounts()->attach($mount_id);
|
||||
$server->mounts()->updateOrCreate([
|
||||
'mount_id' => $mount->id,
|
||||
'server_id' => $server->id,
|
||||
]);
|
||||
|
||||
$data = $this->serverConfigurationStructureService->handle($server);
|
||||
|
||||
|
@ -438,15 +445,18 @@ class ServersController extends Controller
|
|||
* Remove a mount from a server.
|
||||
*
|
||||
* @param Server $server
|
||||
* @param int $mount_id
|
||||
* @param \Pterodactyl\Models\Mount $mount
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws DaemonConnectionException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function deleteMount(Server $server, int $mount_id)
|
||||
public function deleteMount(Server $server, Mount $mount)
|
||||
{
|
||||
$server->mounts()->detach($mount_id);
|
||||
$server->mounts()
|
||||
->where('mount_id', $mount->id)
|
||||
->where('server_id', $server->id)
|
||||
->delete();
|
||||
|
||||
$data = $this->serverConfigurationStructureService->handle($server);
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Admin;
|
||||
|
||||
|
|
21
app/Models/EggMount.php
Normal file
21
app/Models/EggMount.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class EggMount extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'egg_mount';
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Mounts;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||
|
||||
class MountCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* MountCreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||
*/
|
||||
public function __construct(MountRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new mount.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Mount
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data)
|
||||
{
|
||||
return $this->repository->create(array_merge($data, [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]), true, true);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Mounts;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||
|
||||
class MountDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* MountDeletionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||
*/
|
||||
public function __construct(MountRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing location.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Mount $mount
|
||||
* @return int|null
|
||||
*/
|
||||
public function handle($mount)
|
||||
{
|
||||
$mount = ($mount instanceof Mount) ? $mount->id : $mount;
|
||||
|
||||
Assert::integerish($mount, 'First argument passed to handle must be numeric or an instance of ' . Mount::class . ', received %s.');
|
||||
|
||||
return $this->repository->delete($mount);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Mounts;
|
||||
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||
|
||||
class MountUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* MountUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||
*/
|
||||
public function __construct(MountRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing location.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Mount $mount
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Mount
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($mount, array $data)
|
||||
{
|
||||
$mount = ($mount instanceof Mount) ? $mount->id : $mount;
|
||||
|
||||
return $this->repository->update($mount, $data);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue