backups: default is_successful to false (#3522)

* backups: default is_successful to false
* backups: properly query backups
This commit is contained in:
Matthew Penner 2021-08-03 20:45:25 -06:00 committed by GitHub
parent b19a1640f0
commit 970f281859
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 10 deletions

View file

@ -63,7 +63,7 @@ class DeleteBackupService
// I also don't really see any reason you'd have a locked, failed backup to keep
// around. The logic that updates the backup to the failed state will also remove
// the lock, so this condition should really never happen.
if ($backup->is_locked && ($backup->completed_at && $backup->is_successful)) {
if ($backup->is_locked && ($backup->is_successful && !is_null($backup->completed_at))) {
throw new BackupLockedException();
}

View file

@ -132,8 +132,12 @@ class InitiateBackupService
}
}
// Check if the server has reached or exceeded it's backup limit.
$successful = $server->backups()->where('is_successful', true);
// Check if the server has reached or exceeded its backup limit.
// completed_at == null will cover any ongoing backups, while is_successful == true will cover any completed backups.
$successful = $server->backups()->where(function ($query) {
$query->whereNull('completed_at')
->orWhere('is_successful', true);
});
if (!$server->backup_limit || $successful->count() >= $server->backup_limit) {
// Do not allow the user to continue if this server is already at its limit and can't override.
if (!$override || $server->backup_limit <= 0) {