Skip to content

Commit

Permalink
fix: playlist relation might be null in track when cascade (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Sep 11, 2024
1 parent eeff29b commit 3acac99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Events\Base\List\ListDeletedEvent;
use App\Models\List\ExternalProfile;
use App\Models\List\External\ExternalEntry;
use Illuminate\Support\Str;

/**
* Class ExternalEntryDeleted.
Expand All @@ -18,9 +19,9 @@ class ExternalEntryDeleted extends ListDeletedEvent
/**
* The profile the entry belongs to.
*
* @var ExternalProfile
* @var ExternalProfile|null
*/
protected ExternalProfile $profile;
protected ?ExternalProfile $profile;

/**
* Create a new event instance.
Expand Down Expand Up @@ -62,6 +63,8 @@ public function getModel(): ExternalEntry
*/
protected function getDiscordMessageDescription(): string
{
return "Entry '**{$this->getModel()->getName()}**' has been deleted for External Profile '**{$this->profile->getName()}**'.";
return Str::of("Entry '**{$this->getModel()->getName()}**' has been deleted")
->append($this->profile ? " for External Profile '**{$this->profile->getName()}**'." : '.')
->__toString();
}
}
9 changes: 6 additions & 3 deletions app/Events/List/Playlist/Track/TrackDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Events\Base\List\ListDeletedEvent;
use App\Models\List\Playlist;
use App\Models\List\Playlist\PlaylistTrack;
use Illuminate\Support\Str;

/**
* Class TrackDeleted.
Expand All @@ -18,9 +19,9 @@ class TrackDeleted extends ListDeletedEvent
/**
* The playlist the track belongs to.
*
* @var Playlist
* @var Playlist|null
*/
protected Playlist $playlist;
protected ?Playlist $playlist;

/**
* Create a new event instance.
Expand Down Expand Up @@ -62,6 +63,8 @@ public function getModel(): PlaylistTrack
*/
protected function getDiscordMessageDescription(): string
{
return "Track '**{$this->getModel()->getName()}**' has been deleted for Playlist '**{$this->playlist->getName()}**'.";
return Str::of("Track '**{$this->getModel()->getName()}**' has been deleted")
->append($this->playlist ? " for Playlist '**{$this->playlist->getName()}**'." : '.')
->__toString();
}
}

0 comments on commit 3acac99

Please sign in to comment.