Skip to content

Commit 446dc8b

Browse files
committed
Block creation of backups if it would put the server over it's limit
1 parent f1c3762 commit 446dc8b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Pterodactyl\Exceptions\Service\Backup;
4+
5+
use Pterodactyl\Exceptions\DisplayException;
6+
7+
class TooManyBackupsException extends DisplayException
8+
{
9+
/**
10+
* TooManyBackupsException constructor.
11+
*
12+
* @param int $backupLimit
13+
*/
14+
public function __construct(int $backupLimit)
15+
{
16+
parent::__construct(
17+
sprintf('Cannot create a new backup, this server has reached its limit of %d backups.', $backupLimit)
18+
);
19+
}
20+
}

app/Services/Backups/InitiateBackupService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Database\ConnectionInterface;
1212
use Pterodactyl\Repositories\Eloquent\BackupRepository;
1313
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
14+
use Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException;
1415
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
1516

1617
class InitiateBackupService
@@ -84,9 +85,16 @@ public function setIgnoredFiles(?array $ignored)
8485
* @return \Pterodactyl\Models\Backup
8586
*
8687
* @throws \Throwable
88+
* @throws \Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException
89+
* @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
8790
*/
8891
public function handle(Server $server, string $name = null): Backup
8992
{
93+
// Do not allow the user to continue if this server is already at its limit.
94+
if (! $server->backup_limit || $server->backups()->count() >= $server->backup_limit) {
95+
throw new TooManyBackupsException($server->backup_limit);
96+
}
97+
9098
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10);
9199
if ($previous->count() >= 2) {
92100
throw new TooManyRequestsHttpException(

0 commit comments

Comments
 (0)