Skip to content

Commit

Permalink
refactor SourceStatus to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jun 12, 2024
1 parent 80bdfdb commit bab7067
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Enums/SourceStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Spatie\BackupServer\Enums;

enum SourceStatus: string
{
case Active = 'active';
case Deleting = 'deleting';
}
8 changes: 3 additions & 5 deletions src/Models/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\BackupServer\Enums\SourceStatus;
use Spatie\BackupServer\Models\Concerns\HasAsyncDelete;
use Spatie\BackupServer\Models\Concerns\HasBackupRelation;
use Spatie\BackupServer\Models\Concerns\LogsActivity;
Expand All @@ -28,11 +29,8 @@ class Source extends Model

public $guarded = [];

public const STATUS_ACTIVE = 'active';

public const STATUS_DELETING = 'deleting';

public $casts = [
'status' => SourceStatus::class,
'healthy' => 'boolean',
'includes' => 'array',
'excludes' => 'array',
Expand All @@ -43,7 +41,7 @@ class Source extends Model
public static function booted(): void
{
static::creating(function (Source $source) {
$source->status = static::STATUS_ACTIVE;
$source->status = SourceStatus::Active;
});
}

Expand Down

0 comments on commit bab7067

Please sign in to comment.