Skip to content

Commit 9d95c5a

Browse files
committed
Less obtuse mounting code
1 parent 96fef94 commit 9d95c5a

File tree

4 files changed

+89
-23
lines changed

4 files changed

+89
-23
lines changed

app/Models/Mount.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Pterodactyl\Models;
44

5+
use MountNode;
6+
use MountServer;
7+
58
/**
69
* @property int $id
710
* @property string $uuid
@@ -45,11 +48,6 @@ class Mount extends Model
4548
*/
4649
protected $attributes = [
4750
'id' => 'int',
48-
'uuid' => 'string',
49-
'name' => 'string',
50-
'description' => 'string',
51-
'source' => 'string',
52-
'target' => 'string',
5351
'read_only' => 'bool',
5452
'user_mountable' => 'bool',
5553
];
@@ -89,20 +87,18 @@ public function eggs()
8987
/**
9088
* Returns all nodes that have this mount assigned.
9189
*
92-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
90+
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
9391
*/
9492
public function nodes()
9593
{
96-
return $this->belongsToMany(Node::class);
94+
return $this->hasManyThrough(Server::class, MountNode::class);
9795
}
9896

9997
/**
100-
* Returns all servers that have this mount assigned.
101-
*
102-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
98+
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
10399
*/
104100
public function servers()
105101
{
106-
return $this->belongsToMany(Server::class);
102+
return $this->hasManyThrough(Server::class, MountServer::class);
107103
}
108104
}

app/Models/MountNode.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Pterodactyl\Models\Node;
4+
use Pterodactyl\Models\Mount;
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class MountNode extends Model
8+
{
9+
/**
10+
* @var bool
11+
*/
12+
public $timestamps = false;
13+
14+
/**
15+
* @var bool
16+
*/
17+
public $incrementing = false;
18+
19+
/**
20+
* @var string
21+
*/
22+
protected $table = 'mount_node';
23+
24+
/**
25+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
26+
*/
27+
public function node()
28+
{
29+
return $this->belongsTo(Node::class);
30+
}
31+
32+
/**
33+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34+
*/
35+
public function mount()
36+
{
37+
return $this->belongsTo(Mount::class);
38+
}
39+
}

app/Models/MountServer.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Pterodactyl\Models\Mount;
4+
use Pterodactyl\Models\Server;
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class MountServer extends Model
8+
{
9+
/**
10+
* @var bool
11+
*/
12+
public $timestamps = false;
13+
14+
/**
15+
* @var bool
16+
*/
17+
public $incrementing = false;
18+
19+
/**
20+
* @var string
21+
*/
22+
protected $table = 'mount_server';
23+
24+
/**
25+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
26+
*/
27+
public function server()
28+
{
29+
return $this->belongsTo(Server::class);
30+
}
31+
32+
/**
33+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34+
*/
35+
public function mount()
36+
{
37+
return $this->belongsTo(Mount::class);
38+
}
39+
}

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Pterodactyl\Services\Servers;
1111

12+
use Pterodactyl\Models\Mount;
1213
use Pterodactyl\Models\Server;
1314
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
1415

@@ -71,17 +72,6 @@ public function handle(Server $server, bool $legacy = false): array
7172
*/
7273
protected function returnCurrentFormat(Server $server)
7374
{
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-
8575
return [
8676
'uuid' => $server->uuid,
8777
'suspended' => (bool) $server->suspended,
@@ -112,7 +102,9 @@ protected function returnCurrentFormat(Server $server)
112102
],
113103
'mappings' => $server->getAllocationMappings(),
114104
],
115-
'mounts' => $mounts,
105+
'mounts' => $server->mounts->map(function (Mount $mount) {
106+
return $mount->only('uuid', 'source', 'description', 'read_only');
107+
})->toArray(),
116108
];
117109
}
118110

0 commit comments

Comments
 (0)