Skip to content

Commit

Permalink
diferentiate between status enum types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jun 12, 2024
1 parent bab7067 commit 220e507
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Models/Concerns/HasAsyncDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace Spatie\BackupServer\Models\Concerns;

use Spatie\BackupServer\Enums\BackupStatus;
use Spatie\BackupServer\Enums\SourceStatus;
use Spatie\BackupServer\Models\Backup;
use Spatie\BackupServer\Models\Destination;
use Spatie\BackupServer\Models\Source;

trait HasAsyncDelete
{
public function asyncDelete(): void
{
$this->update(['status' => BackupStatus::Deleting]);
$this->update(['status' => $this->status($this)]);

$deletionJobClassName = $this->getDeletionJobClassName();

Expand All @@ -17,8 +21,18 @@ public function asyncDelete(): void

public function willBeDeleted(): bool
{
return $this->status === BackupStatus::Deleting;
return $this->status === $this->status($this);
}

abstract public function getDeletionJobClassName(): string;

protected function status(self $class)
{
return match ($class) {
Source::class => SourceStatus::Deleting,
Destination::class => Destination::STATUS_DELETING,
Backup::class => BackupStatus::Deleting,
default => throw new \Exception('Unknown class type'),
};
}
}

0 comments on commit 220e507

Please sign in to comment.