Block creation of backups if it would put the server over it's limit

This commit is contained in:
Dane Everitt 2020-04-26 12:21:14 -07:00
parent f1c3762f4d
commit 446dc8b33d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 28 additions and 0 deletions

View file

@ -11,6 +11,7 @@ use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
class InitiateBackupService
@ -84,9 +85,16 @@ class InitiateBackupService
* @return \Pterodactyl\Models\Backup
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException
* @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
*/
public function handle(Server $server, string $name = null): Backup
{
// Do not allow the user to continue if this server is already at its limit.
if (! $server->backup_limit || $server->backups()->count() >= $server->backup_limit) {
throw new TooManyBackupsException($server->backup_limit);
}
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10);
if ($previous->count() >= 2) {
throw new TooManyRequestsHttpException(