Merge pull request #2801 from pterodactyl/issue/2800

Delete the oldest backup, not the newest backup
This commit is contained in:
Dane Everitt 2020-12-08 14:57:04 -08:00 committed by GitHub
commit 76b9fae4e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,6 @@ use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
use Pterodactyl\Services\Backups\DeleteBackupService;
class InitiateBackupService
{
@ -124,8 +123,11 @@ class InitiateBackupService
throw new TooManyBackupsException($server->backup_limit);
}
// Remove oldest backup
$oldestBackup = $server->backups()->where('is_successful', true)->orderByDesc('created_at')->first();
// Get the oldest backup the server has.
/** @var \Pterodactyl\Models\Backup $oldestBackup */
$oldestBackup = $server->backups()->where('is_successful', true)->orderBy('created_at')->first();
// Delete the oldest backup.
$this->deleteBackupService->handle($oldestBackup);
}