Skip to content

Commit f1c3762

Browse files
committed
Add base support for definining the number of backups that can be created for a server
1 parent bed51b5 commit f1c3762

File tree

10 files changed

+65
-23
lines changed

10 files changed

+65
-23
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function updateBuild(Request $request, Server $server)
263263
$this->buildModificationService->handle($server, $request->only([
264264
'allocation_id', 'add_allocations', 'remove_allocations',
265265
'memory', 'swap', 'io', 'cpu', 'threads', 'disk',
266-
'database_limit', 'allocation_limit', 'oom_disabled',
266+
'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled',
267267
]));
268268
$this->alert->success(trans('admin/server.alerts.build_updated'))->flash();
269269

app/Models/Server.php

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

33
namespace Pterodactyl\Models;
44

5-
use Schema;
65
use Illuminate\Notifications\Notifiable;
76
use Pterodactyl\Models\Traits\Searchable;
87
use Znck\Eloquent\Traits\BelongsToThrough;
@@ -34,6 +33,7 @@
3433
* @property int $installed
3534
* @property int $allocation_limit
3635
* @property int $database_limit
36+
* @property int $backup_limit
3737
* @property \Carbon\Carbon $created_at
3838
* @property \Carbon\Carbon $updated_at
3939
*
@@ -127,6 +127,7 @@ class Server extends Model
127127
'installed' => 'in:0,1,2',
128128
'database_limit' => 'present|nullable|integer|min:0',
129129
'allocation_limit' => 'sometimes|nullable|integer|min:0',
130+
'backup_limit' => 'present|nullable|integer|min:0',
130131
];
131132

132133
/**
@@ -152,6 +153,7 @@ class Server extends Model
152153
'installed' => 'integer',
153154
'database_limit' => 'integer',
154155
'allocation_limit' => 'integer',
156+
'backup_limit' => 'integer',
155157
];
156158

157159
/**
@@ -170,16 +172,6 @@ class Server extends Model
170172
'pack.name' => 10,
171173
];
172174

173-
/**
174-
* Return the columns available for this table.
175-
*
176-
* @return array
177-
*/
178-
public function getTableColumns()
179-
{
180-
return Schema::getColumnListing($this->getTable());
181-
}
182-
183175
/**
184176
* Returns the format for server allocations when communicating with the Daemon.
185177
*

app/Services/Servers/BuildModificationService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ public function handle(Server $server, array $data)
101101
'threads' => array_get($data, 'threads'),
102102
'disk' => array_get($data, 'disk'),
103103
'allocation_id' => array_get($data, 'allocation_id'),
104-
'database_limit' => array_get($data, 'database_limit'),
105-
'allocation_limit' => array_get($data, 'allocation_limit'),
104+
'database_limit' => array_get($data, 'database_limit', 0),
105+
'allocation_limit' => array_get($data, 'allocation_limit', 0),
106+
'backup_limit' => array_get($data, 'backup_limit', 0),
106107
]);
107108

108109
$updateData = $this->structureService->handle($server);

app/Services/Servers/ServerCreationService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ private function createModel(array $data): Server
249249
'pack_id' => empty($data['pack_id']) ? null : $data['pack_id'],
250250
'startup' => Arr::get($data, 'startup'),
251251
'image' => Arr::get($data, 'image'),
252-
'database_limit' => Arr::get($data, 'database_limit'),
253-
'allocation_limit' => Arr::get($data, 'allocation_limit'),
252+
'database_limit' => Arr::get($data, 'database_limit', 0),
253+
'allocation_limit' => Arr::get($data, 'allocation_limit', 0),
254+
'backup_limit' => Arr::get($data, 'backup_limit', 0),
254255
]);
255256

256257
return $model;

app/Transformers/Api/Application/ServerTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function transform(Server $server): array
8080
'feature_limits' => [
8181
'databases' => $server->database_limit,
8282
'allocations' => $server->allocation_limit,
83+
'backups' => $server->backup_limit,
8384
],
8485
'user' => $server->owner_id,
8586
'node' => $server->node_id,

app/Transformers/Api/Client/ServerTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function transform(Server $server): array
5555
'feature_limits' => [
5656
'databases' => $server->database_limit,
5757
'allocations' => $server->allocation_limit,
58+
'backups' => $server->backup_limit,
5859
],
5960
'is_suspended' => $server->suspended !== 0,
6061
'is_installing' => $server->installed !== 1,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddBackupLimitToServers extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('servers', function (Blueprint $table) {
17+
$table->unsignedInteger('backup_limit')->default(0)->after('database_limit');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('servers', function (Blueprint $table) {
29+
$table->dropColumn('backup_limit');
30+
});
31+
}
32+
}

resources/scripts/api/server/getServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface Server {
2929
featureLimits: {
3030
databases: number;
3131
allocations: number;
32+
backups: number;
3233
};
3334
isSuspended: boolean;
3435
isInstalling: boolean;

resources/views/admin/servers/new.blade.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,21 @@
118118
<div>
119119
<input type="text" id="pDatabaseLimit" name="database_limit" class="form-control" value="{{ old('database_limit', 0) }}"/>
120120
</div>
121-
<p class="text-muted small">The total number of databases a user is allowed to create for this server. Leave blank to allow unlimited.</p>
121+
<p class="text-muted small">The total number of databases a user is allowed to create for this server.</p>
122122
</div>
123-
124123
<div class="form-group col-xs-6">
125124
<label for="pAllocationLimit" class="control-label">Allocation Limit</label>
126125
<div>
127126
<input type="text" id="pAllocationLimit" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', 0) }}"/>
128127
</div>
129-
<p class="text-muted small">The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.</p>
128+
<p class="text-muted small">The total number of allocations a user is allowed to create for this server.</p>
129+
</div>
130+
<div class="form-group col-xs-6">
131+
<label for="pBackupLimit" class="control-label">Backup Limit</label>
132+
<div>
133+
<input type="text" id="pBackupLimit" name="backup_limit" class="form-control" value="{{ old('backup_limit', 0) }}"/>
134+
</div>
135+
<p class="text-muted small">The total number of backups that can be created for this server.</p>
130136
</div>
131137
</div>
132138
</div>

resources/views/admin/servers/view/build.blade.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,25 @@
104104
<div class="box-body">
105105
<div class="row">
106106
<div class="form-group col-xs-6">
107-
<label for="cpu" class="control-label">Database Limit</label>
107+
<label for="database_limit" class="control-label">Database Limit</label>
108108
<div>
109109
<input type="text" name="database_limit" class="form-control" value="{{ old('database_limit', $server->database_limit) }}"/>
110110
</div>
111-
<p class="text-muted small">The total number of databases a user is allowed to create for this server. Leave blank to allow unlimited.</p>
111+
<p class="text-muted small">The total number of databases a user is allowed to create for this server.</p>
112112
</div>
113113
<div class="form-group col-xs-6">
114-
<label for="cpu" class="control-label">Allocation Limit</label>
114+
<label for="allocation_limit" class="control-label">Allocation Limit</label>
115115
<div>
116116
<input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/>
117117
</div>
118-
<p class="text-muted small"><strong>This feature is not currently implemented.</strong> The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.</p>
118+
<p class="text-muted small"><strong>This feature is not currently implemented.</strong> The total number of allocations a user is allowed to create for this server.</p>
119+
</div>
120+
<div class="form-group col-xs-6">
121+
<label for="backup_limit" class="control-label">Backup Limit</label>
122+
<div>
123+
<input type="text" name="backup_limit" class="form-control" value="{{ old('backup_limit', $server->backup_limit) }}"/>
124+
</div>
125+
<p class="text-muted small">The total number of backups that can be created for this server.</p>
119126
</div>
120127
</div>
121128
</div>

0 commit comments

Comments
 (0)