Skip to content

Commit

Permalink
fix bug where updating settings would remove the header image
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Oct 7, 2024
1 parent 283c74d commit 45bb7bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/Actions/Album/SetHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class SetHeader extends Action
* @param Album $album
* @param bool $is_compact
* @param ?Photo $photo
* @param bool $shall_override
*
* @return Album
*/
public function do(Album $album, bool $is_compact, ?Photo $photo): Album
public function do(Album $album, bool $is_compact, ?Photo $photo, bool $shall_override = false): Album
{
if ($is_compact) {
$album->header_id = AlbumController::COMPACT_HEADER;
} else {
$album->header_id = ($album->header_id === $photo?->id) ? null : $photo?->id;
$album->header_id = ($album->header_id !== $photo?->id || $shall_override) ? $photo?->id : null;
}
$album->save();

Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Gallery/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public function updateAlbum(UpdateAlbumRequest $request, SetHeader $setHeader):
$album->photo_sorting = $request->photoSortingCriterion();
$album->album_sorting = $request->albumSortingCriterion();

$album = $setHeader->do($album, $request->is_compact(), $request->photo());
$album = $setHeader->do(
album: $album,
is_compact: $request->is_compact(),
photo: $request->photo(),
shall_override: true);

return EditableBaseAlbumResource::fromModel($album);
}
Expand Down

0 comments on commit 45bb7bf

Please sign in to comment.