Skip to content

Commit 6539391

Browse files
committed
Send mounts when wings fetches server information, fix issue with mount fields not being updated
1 parent e601b35 commit 6539391

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

app/Http/Controllers/Admin/MountController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Http\Controllers\Admin;
44

55
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Log;
67
use Pterodactyl\Models\Mount;
78
use Prologue\Alerts\AlertsMessageBag;
89
use Pterodactyl\Exceptions\DisplayException;

app/Http/Controllers/Admin/ServersController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
namespace Pterodactyl\Http\Controllers\Admin;
1111

12+
use GuzzleHttp\Exception\RequestException;
1213
use Illuminate\Http\Request;
14+
use Illuminate\Support\Arr;
15+
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
1316
use Pterodactyl\Models\User;
1417
use Pterodactyl\Models\Server;
1518
use Prologue\Alerts\AlertsMessageBag;
1619
use Pterodactyl\Exceptions\DisplayException;
1720
use Pterodactyl\Http\Controllers\Controller;
21+
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
22+
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
1823
use Pterodactyl\Services\Servers\SuspensionService;
1924
use Pterodactyl\Repositories\Eloquent\MountRepository;
2025
use Pterodactyl\Services\Servers\ServerDeletionService;
@@ -54,6 +59,11 @@ class ServersController extends Controller
5459
*/
5560
protected $config;
5661

62+
/**
63+
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
64+
*/
65+
private $daemonServerRepository;
66+
5767
/**
5868
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
5969
*/
@@ -104,6 +114,11 @@ class ServersController extends Controller
104114
*/
105115
protected $repository;
106116

117+
/**
118+
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
119+
*/
120+
private $serverConfigurationStructureService;
121+
107122
/**
108123
* @var \Pterodactyl\Services\Servers\StartupModificationService
109124
*/
@@ -121,6 +136,7 @@ class ServersController extends Controller
121136
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
122137
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
123138
* @param \Illuminate\Contracts\Config\Repository $config
139+
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
124140
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
125141
* @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService
126142
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
@@ -131,6 +147,7 @@ class ServersController extends Controller
131147
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
132148
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $mountRepository
133149
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository
150+
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $serverConfigurationStructureService
134151
* @param \Pterodactyl\Services\Servers\StartupModificationService $startupModificationService
135152
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
136153
*/
@@ -139,6 +156,7 @@ public function __construct(
139156
AllocationRepositoryInterface $allocationRepository,
140157
BuildModificationService $buildModificationService,
141158
ConfigRepository $config,
159+
DaemonServerRepository $daemonServerRepository,
142160
DatabaseManagementService $databaseManagementService,
143161
DatabasePasswordService $databasePasswordService,
144162
DatabaseRepositoryInterface $databaseRepository,
@@ -149,13 +167,15 @@ public function __construct(
149167
ServerRepositoryInterface $repository,
150168
MountRepository $mountRepository,
151169
NestRepositoryInterface $nestRepository,
170+
ServerConfigurationStructureService $serverConfigurationStructureService,
152171
StartupModificationService $startupModificationService,
153172
SuspensionService $suspensionService
154173
) {
155174
$this->alert = $alert;
156175
$this->allocationRepository = $allocationRepository;
157176
$this->buildModificationService = $buildModificationService;
158177
$this->config = $config;
178+
$this->daemonServerRepository = $daemonServerRepository;
159179
$this->databaseHostRepository = $databaseHostRepository;
160180
$this->databaseManagementService = $databaseManagementService;
161181
$this->databasePasswordService = $databasePasswordService;
@@ -166,6 +186,7 @@ public function __construct(
166186
$this->reinstallService = $reinstallService;
167187
$this->repository = $repository;
168188
$this->mountRepository = $mountRepository;
189+
$this->serverConfigurationStructureService = $serverConfigurationStructureService;
169190
$this->startupModificationService = $startupModificationService;
170191
$this->suspensionService = $suspensionService;
171192
}
@@ -390,6 +411,16 @@ public function addMount(Server $server, int $mount_id)
390411
{
391412
$server->mounts()->attach($mount_id);
392413

414+
$data = $this->serverConfigurationStructureService->handle($server);
415+
416+
try {
417+
$this->daemonServerRepository
418+
->setServer($server)
419+
->update(Arr::only($data, ['mounts']));
420+
} catch (RequestException $exception) {
421+
throw new DaemonConnectionException($exception);
422+
}
423+
393424
$this->alert->success('Mount was added successfully.')->flash();
394425

395426
return redirect()->route('admin.servers.view.mounts', $server->id);
@@ -401,11 +432,24 @@ public function addMount(Server $server, int $mount_id)
401432
* @param Server $server
402433
* @param int $mount_id
403434
* @return \Illuminate\Http\RedirectResponse
435+
*
436+
* @throws DaemonConnectionException
437+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
404438
*/
405439
public function deleteMount(Server $server, int $mount_id)
406440
{
407441
$server->mounts()->detach($mount_id);
408442

443+
$data = $this->serverConfigurationStructureService->handle($server);
444+
445+
try {
446+
$this->daemonServerRepository
447+
->setServer($server)
448+
->update(Arr::only($data, ['mounts']));
449+
} catch (RequestException $exception) {
450+
throw new DaemonConnectionException($exception);
451+
}
452+
409453
$this->alert->success('Mount was removed successfully.')->flash();
410454

411455
return redirect()->route('admin.servers.view.mounts', $server->id);

app/Models/Mount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Mount extends Model
3636
*
3737
* @var array
3838
*/
39-
protected $guarded = ['id', 'uuid', 'name', 'description', 'source', 'target'];
39+
protected $guarded = ['id', 'uuid'];
4040

4141
/**
4242
* Default values for specific fields in the database.

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ public function handle(Server $server, bool $legacy = false): array
7171
*/
7272
protected function returnCurrentFormat(Server $server)
7373
{
74+
$mounts = $server->mounts;
75+
foreach ($mounts as $mount) {
76+
unset($mount->id);
77+
unset($mount->uuid);
78+
unset($mount->name);
79+
unset($mount->description);
80+
$mount->read_only = $mount->read_only == 1;
81+
unset($mount->user_mountable);
82+
unset($mount->pivot);
83+
}
84+
7485
return [
7586
'uuid' => $server->uuid,
7687
'suspended' => (bool) $server->suspended,
@@ -101,6 +112,7 @@ protected function returnCurrentFormat(Server $server)
101112
],
102113
'mappings' => $server->getAllocationMappings(),
103114
],
115+
'mounts' => $mounts,
104116
];
105117
}
106118

0 commit comments

Comments
 (0)