Send mounts when wings fetches server information, fix issue with mount fields not being updated
This commit is contained in:
parent
e601b35f2f
commit
65393914c3
4 changed files with 58 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace Pterodactyl\Http\Controllers\Admin;
|
namespace Pterodactyl\Http\Controllers\Admin;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Pterodactyl\Models\Mount;
|
use Pterodactyl\Models\Mount;
|
||||||
use Prologue\Alerts\AlertsMessageBag;
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
use Pterodactyl\Exceptions\DisplayException;
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
|
|
|
@ -9,12 +9,17 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Admin;
|
namespace Pterodactyl\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Prologue\Alerts\AlertsMessageBag;
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
use Pterodactyl\Exceptions\DisplayException;
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||||
use Pterodactyl\Services\Servers\SuspensionService;
|
use Pterodactyl\Services\Servers\SuspensionService;
|
||||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
use Pterodactyl\Services\Servers\ServerDeletionService;
|
use Pterodactyl\Services\Servers\ServerDeletionService;
|
||||||
|
@ -54,6 +59,11 @@ class ServersController extends Controller
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||||
|
*/
|
||||||
|
private $daemonServerRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
|
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
|
||||||
*/
|
*/
|
||||||
|
@ -104,6 +114,11 @@ class ServersController extends Controller
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
||||||
|
*/
|
||||||
|
private $serverConfigurationStructureService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Servers\StartupModificationService
|
* @var \Pterodactyl\Services\Servers\StartupModificationService
|
||||||
*/
|
*/
|
||||||
|
@ -121,6 +136,7 @@ class ServersController extends Controller
|
||||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
||||||
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
|
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
|
||||||
* @param \Illuminate\Contracts\Config\Repository $config
|
* @param \Illuminate\Contracts\Config\Repository $config
|
||||||
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||||
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
|
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
|
||||||
* @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService
|
* @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService
|
||||||
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
||||||
|
@ -131,6 +147,7 @@ class ServersController extends Controller
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $mountRepository
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $mountRepository
|
||||||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository
|
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository
|
||||||
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $serverConfigurationStructureService
|
||||||
* @param \Pterodactyl\Services\Servers\StartupModificationService $startupModificationService
|
* @param \Pterodactyl\Services\Servers\StartupModificationService $startupModificationService
|
||||||
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
|
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
|
||||||
*/
|
*/
|
||||||
|
@ -139,6 +156,7 @@ class ServersController extends Controller
|
||||||
AllocationRepositoryInterface $allocationRepository,
|
AllocationRepositoryInterface $allocationRepository,
|
||||||
BuildModificationService $buildModificationService,
|
BuildModificationService $buildModificationService,
|
||||||
ConfigRepository $config,
|
ConfigRepository $config,
|
||||||
|
DaemonServerRepository $daemonServerRepository,
|
||||||
DatabaseManagementService $databaseManagementService,
|
DatabaseManagementService $databaseManagementService,
|
||||||
DatabasePasswordService $databasePasswordService,
|
DatabasePasswordService $databasePasswordService,
|
||||||
DatabaseRepositoryInterface $databaseRepository,
|
DatabaseRepositoryInterface $databaseRepository,
|
||||||
|
@ -149,6 +167,7 @@ class ServersController extends Controller
|
||||||
ServerRepositoryInterface $repository,
|
ServerRepositoryInterface $repository,
|
||||||
MountRepository $mountRepository,
|
MountRepository $mountRepository,
|
||||||
NestRepositoryInterface $nestRepository,
|
NestRepositoryInterface $nestRepository,
|
||||||
|
ServerConfigurationStructureService $serverConfigurationStructureService,
|
||||||
StartupModificationService $startupModificationService,
|
StartupModificationService $startupModificationService,
|
||||||
SuspensionService $suspensionService
|
SuspensionService $suspensionService
|
||||||
) {
|
) {
|
||||||
|
@ -156,6 +175,7 @@ class ServersController extends Controller
|
||||||
$this->allocationRepository = $allocationRepository;
|
$this->allocationRepository = $allocationRepository;
|
||||||
$this->buildModificationService = $buildModificationService;
|
$this->buildModificationService = $buildModificationService;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->daemonServerRepository = $daemonServerRepository;
|
||||||
$this->databaseHostRepository = $databaseHostRepository;
|
$this->databaseHostRepository = $databaseHostRepository;
|
||||||
$this->databaseManagementService = $databaseManagementService;
|
$this->databaseManagementService = $databaseManagementService;
|
||||||
$this->databasePasswordService = $databasePasswordService;
|
$this->databasePasswordService = $databasePasswordService;
|
||||||
|
@ -166,6 +186,7 @@ class ServersController extends Controller
|
||||||
$this->reinstallService = $reinstallService;
|
$this->reinstallService = $reinstallService;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->mountRepository = $mountRepository;
|
$this->mountRepository = $mountRepository;
|
||||||
|
$this->serverConfigurationStructureService = $serverConfigurationStructureService;
|
||||||
$this->startupModificationService = $startupModificationService;
|
$this->startupModificationService = $startupModificationService;
|
||||||
$this->suspensionService = $suspensionService;
|
$this->suspensionService = $suspensionService;
|
||||||
}
|
}
|
||||||
|
@ -390,6 +411,16 @@ class ServersController extends Controller
|
||||||
{
|
{
|
||||||
$server->mounts()->attach($mount_id);
|
$server->mounts()->attach($mount_id);
|
||||||
|
|
||||||
|
$data = $this->serverConfigurationStructureService->handle($server);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->daemonServerRepository
|
||||||
|
->setServer($server)
|
||||||
|
->update(Arr::only($data, ['mounts']));
|
||||||
|
} catch (RequestException $exception) {
|
||||||
|
throw new DaemonConnectionException($exception);
|
||||||
|
}
|
||||||
|
|
||||||
$this->alert->success('Mount was added successfully.')->flash();
|
$this->alert->success('Mount was added successfully.')->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.servers.view.mounts', $server->id);
|
return redirect()->route('admin.servers.view.mounts', $server->id);
|
||||||
|
@ -401,11 +432,24 @@ class ServersController extends Controller
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $mount_id
|
* @param int $mount_id
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*
|
||||||
|
* @throws DaemonConnectionException
|
||||||
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
*/
|
*/
|
||||||
public function deleteMount(Server $server, int $mount_id)
|
public function deleteMount(Server $server, int $mount_id)
|
||||||
{
|
{
|
||||||
$server->mounts()->detach($mount_id);
|
$server->mounts()->detach($mount_id);
|
||||||
|
|
||||||
|
$data = $this->serverConfigurationStructureService->handle($server);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->daemonServerRepository
|
||||||
|
->setServer($server)
|
||||||
|
->update(Arr::only($data, ['mounts']));
|
||||||
|
} catch (RequestException $exception) {
|
||||||
|
throw new DaemonConnectionException($exception);
|
||||||
|
}
|
||||||
|
|
||||||
$this->alert->success('Mount was removed successfully.')->flash();
|
$this->alert->success('Mount was removed successfully.')->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.servers.view.mounts', $server->id);
|
return redirect()->route('admin.servers.view.mounts', $server->id);
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Mount extends Model
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $guarded = ['id', 'uuid', 'name', 'description', 'source', 'target'];
|
protected $guarded = ['id', 'uuid'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default values for specific fields in the database.
|
* Default values for specific fields in the database.
|
||||||
|
|
|
@ -71,6 +71,17 @@ class ServerConfigurationStructureService
|
||||||
*/
|
*/
|
||||||
protected function returnCurrentFormat(Server $server)
|
protected function returnCurrentFormat(Server $server)
|
||||||
{
|
{
|
||||||
|
$mounts = $server->mounts;
|
||||||
|
foreach ($mounts as $mount) {
|
||||||
|
unset($mount->id);
|
||||||
|
unset($mount->uuid);
|
||||||
|
unset($mount->name);
|
||||||
|
unset($mount->description);
|
||||||
|
$mount->read_only = $mount->read_only == 1;
|
||||||
|
unset($mount->user_mountable);
|
||||||
|
unset($mount->pivot);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'uuid' => $server->uuid,
|
'uuid' => $server->uuid,
|
||||||
'suspended' => (bool) $server->suspended,
|
'suspended' => (bool) $server->suspended,
|
||||||
|
@ -101,6 +112,7 @@ class ServerConfigurationStructureService
|
||||||
],
|
],
|
||||||
'mappings' => $server->getAllocationMappings(),
|
'mappings' => $server->getAllocationMappings(),
|
||||||
],
|
],
|
||||||
|
'mounts' => $mounts,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue