backups: properly query backups

This commit is contained in:
Matthew Penner 2021-08-03 16:37:14 -06:00
parent c46131e7ad
commit 07617bcd27
2 changed files with 8 additions and 3 deletions

View file

@ -25,8 +25,10 @@ class BackupRepository extends EloquentRepository
return $this->getBuilder()
->withTrashed()
->where('server_id', $server)
->whereNull('completed_at')
->orWhere('is_successful', '=', true)
->where(function ($query) {
$query->whereNull('completed_at')
->orWhere('is_successful', '=', true);
})
->where('created_at', '>=', Carbon::now()->subSeconds($seconds)->toDateTimeString())
->get()
->toBase();

View file

@ -134,7 +134,10 @@ class InitiateBackupService
// 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()->whereNull('completed_at')->orWhere('is_successful', true);
$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) {