backups: default is_successful to false (#3522)
* backups: default is_successful to false * backups: properly query backups
This commit is contained in:
parent
b19a1640f0
commit
970f281859
8 changed files with 54 additions and 10 deletions
|
@ -225,7 +225,7 @@ class BackupController extends ClientApiController
|
|||
throw new BadRequestHttpException('This server is not currently in a state that allows for a backup to be restored.');
|
||||
}
|
||||
|
||||
if (!$backup->is_successful && !$backup->completed_at) {
|
||||
if (!$backup->is_successful && is_null($backup->completed_at)) {
|
||||
throw new BadRequestHttpException('This backup cannot be restored at this time: not completed or failed.');
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class ReportBackupCompleteRequest extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
'successful' => 'present|boolean',
|
||||
'successful' => 'required|boolean',
|
||||
'checksum' => 'nullable|string|required_if:successful,true',
|
||||
'checksum_type' => 'nullable|string|required_if:successful,true',
|
||||
'size' => 'nullable|numeric|required_if:successful,true',
|
||||
|
|
|
@ -64,7 +64,7 @@ class Backup extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'is_successful' => true,
|
||||
'is_successful' => false,
|
||||
'is_locked' => false,
|
||||
'checksum' => null,
|
||||
'bytes' => 0,
|
||||
|
|
|
@ -25,7 +25,10 @@ class BackupRepository extends EloquentRepository
|
|||
return $this->getBuilder()
|
||||
->withTrashed()
|
||||
->where('server_id', $server)
|
||||
->where('is_successful', true)
|
||||
->where(function ($query) {
|
||||
$query->whereNull('completed_at')
|
||||
->orWhere('is_successful', '=', true);
|
||||
})
|
||||
->where('created_at', '>=', Carbon::now()->subSeconds($seconds)->toDateTimeString())
|
||||
->get()
|
||||
->toBase();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue