diff --git a/app/Models/Mount.php b/app/Models/Mount.php index ac0b5da9a..81e9a57c1 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -2,6 +2,9 @@ namespace Pterodactyl\Models; +use MountNode; +use MountServer; + /** * @property int $id * @property string $uuid @@ -45,11 +48,6 @@ class Mount extends Model */ protected $attributes = [ 'id' => 'int', - 'uuid' => 'string', - 'name' => 'string', - 'description' => 'string', - 'source' => 'string', - 'target' => 'string', 'read_only' => 'bool', 'user_mountable' => 'bool', ]; @@ -89,20 +87,18 @@ class Mount extends Model /** * Returns all nodes that have this mount assigned. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough */ public function nodes() { - return $this->belongsToMany(Node::class); + return $this->hasManyThrough(Server::class, MountNode::class); } /** - * Returns all servers that have this mount assigned. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough */ public function servers() { - return $this->belongsToMany(Server::class); + return $this->hasManyThrough(Server::class, MountServer::class); } } diff --git a/app/Models/MountNode.php b/app/Models/MountNode.php new file mode 100644 index 000000000..77f8bf3d5 --- /dev/null +++ b/app/Models/MountNode.php @@ -0,0 +1,39 @@ +belongsTo(Node::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function mount() + { + return $this->belongsTo(Mount::class); + } +} diff --git a/app/Models/MountServer.php b/app/Models/MountServer.php new file mode 100644 index 000000000..77b60208c --- /dev/null +++ b/app/Models/MountServer.php @@ -0,0 +1,39 @@ +belongsTo(Server::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function mount() + { + return $this->belongsTo(Mount::class); + } +} diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index fea2eaac0..ec8bbf560 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -9,6 +9,7 @@ namespace Pterodactyl\Services\Servers; +use Pterodactyl\Models\Mount; use Pterodactyl\Models\Server; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; @@ -71,17 +72,6 @@ class ServerConfigurationStructureService */ 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 [ 'uuid' => $server->uuid, 'suspended' => (bool) $server->suspended, @@ -112,7 +102,9 @@ class ServerConfigurationStructureService ], 'mappings' => $server->getAllocationMappings(), ], - 'mounts' => $mounts, + 'mounts' => $server->mounts->map(function (Mount $mount) { + return $mount->only('uuid', 'source', 'description', 'read_only'); + })->toArray(), ]; }