backend: support is_successful state for backups rather than deleting it when failing

This allows the UI to correctly show failed backups to the user and require them to manually delete those backups, rather than them mysteriously disappearing.

We can also hook into this later to send a notification to the user when the backup fails.
This commit is contained in:
Dane Everitt 2020-08-20 21:07:53 -07:00
parent 6066fa40f4
commit e3178ba6f0
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 58 additions and 25 deletions

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Services\Backups;
use Carbon\Carbon;
use Ramsey\Uuid\Uuid;
use Carbon\CarbonImmutable;
use Webmozart\Assert\Assert;
@ -101,14 +100,14 @@ class InitiateBackupService
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) {
if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) {
throw new TooManyBackupsException($server->backup_limit);
}
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10);
if ($previous->count() >= 2) {
throw new TooManyRequestsHttpException(
Carbon::now()->diffInSeconds($previous->last()->created_at->addMinutes(10)),
CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addMinutes(10)),
'Only two backups may be generated within a 10 minute span of time.'
);
}