Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-13217: Fix displaying cover art edits #3001

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/MusicBrainz/Server/Edit/Release/AddCoverArt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@ sub build_display_data {
my ($self, $loaded) = @_;

my $loaded_release = $loaded->{Release}{ $self->data->{entity}{id} };
my $release = $loaded_release ||

# The release used to link (if it still exists) from the release field.
my $field_release = $loaded_release ||
Release->new(
id => $self->data->{entity}{id},
name => $self->data->{entity}{name},
# Allow linking to release redirecting to still existing release.
$self->c->model('Release')->get_by_gid($self->data->{entity}{mbid}) ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered that the foreign_keys method also supports loading entities by MBID, IIRC. So I believe we can just replace the reference to $self->data->{entity}{id} in foreign_keys, and also in the $loaded_release assignment above, to point to the mbid property instead (unless I am missing something).

gid => $self->data->{entity}{mbid},
id => $self->data->{entity}{id},
) : (),
);

# The release used (even if merged or removed) to load image from the cover art field.
my $artwork_release = $loaded_release ||
Release->new(
gid => $self->data->{entity}{mbid},
Expand All @@ -129,7 +137,7 @@ sub build_display_data {
cover_art_types => [map {$loaded->{CoverArtType}{$_}} @{ $self->data->{cover_art_types} }]);

return {
release => to_json_object($release),
release => to_json_object($field_release),
artwork => to_json_object($artwork),
position => $self->data->{cover_art_position},
};
Expand Down
28 changes: 22 additions & 6 deletions lib/MusicBrainz/Server/Edit/Release/EditCoverArt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,32 @@ sub build_display_data {

my %data;

my $release = (
$loaded->{Release}{ $self->data->{entity}{id} } ||
Release->new( name => $self->data->{entity}{name} )
);
my $loaded_release = $loaded->{Release}{ $self->data->{entity}{id} };

# The release used to link (if it still exists) from the release field.
my $field_release = $loaded_release ||
Release->new(
name => $self->data->{entity}{name},
# Allow linking to release redirecting to still existing release.
$self->c->model('Release')->get_by_gid($self->data->{entity}{mbid}) ? (
id => $self->data->{entity}{id},
gid => $self->data->{entity}{mbid},
) : (),
);

$data{release} = to_json_object($release);
$data{release} = to_json_object($field_release);

# The release used (even if merged or removed) to load image from the cover art field.
my $artwork_release = $loaded_release ||
Release->new(
gid => $self->data->{entity}{mbid},
id => $self->data->{entity}{id},
name => $self->data->{entity}{name},
);

$data{artwork} = to_json_object(
$loaded->{Artwork}{ $self->data->{id} } ||
Artwork->new(release => $release,
Artwork->new(release => $artwork_release,
id => $self->data->{id},
comment => $self->data->{new}{comment} // '',
cover_art_types => [ map {
Expand Down
26 changes: 22 additions & 4 deletions lib/MusicBrainz/Server/Edit/Release/RemoveCoverArt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,30 @@ sub foreign_keys {
sub build_display_data {
my ($self, $loaded) = @_;

my $release = $loaded->{Release}{ $self->data->{entity}{id} } ||
Release->new( name => $self->data->{entity}{name} );
my $loaded_release = $loaded->{Release}{ $self->data->{entity}{id} };

# The release used to link (if it still exists) from the release field.
my $field_release = $loaded_release ||
Release->new(
name => $self->data->{entity}{name},
# Allow linking to release redirecting to still existing release.
$self->c->model('Release')->get_by_gid($self->data->{entity}{mbid}) ? (
id => $self->data->{entity}{id},
gid => $self->data->{entity}{mbid},
) : (),
);

# The release used (even if merged or removed) to load image from the cover art field.
my $artwork_release = $loaded_release ||
Release->new(
gid => $self->data->{entity}{mbid},
id => $self->data->{entity}{id},
name => $self->data->{entity}{name},
);

my $artwork = $loaded->{Artwork}{ $self->data->{cover_art_id} } ||
Artwork->new(
release => $release,
release => $artwork_release,
id => $self->data->{cover_art_id},
comment => $self->data->{cover_art_comment},
exists $self->data->{cover_art_mime_type} ? (mime_type => $self->data->{cover_art_mime_type}) : (),
Expand All @@ -109,7 +127,7 @@ sub build_display_data {
]);

return {
release => to_json_object($release),
release => to_json_object($field_release),
artwork => to_json_object($artwork),
};
}
Expand Down
38 changes: 26 additions & 12 deletions lib/MusicBrainz/Server/Edit/Release/ReorderCoverArt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,41 @@ sub build_display_data {

my %data;

$data{release} = $loaded->{Release}{ $self->data->{entity}{id} };
if (!$data{release} && ($data{release} ||= $self->c->model('Release')->get_by_gid($self->data->{entity}{mbid}))) {
$self->c->model('ArtistCredit')->load($data{release});
}
my $loaded_release = $loaded->{Release}{ $self->data->{entity}{id} };
my $gid_loaded_release = $loaded_release || $self->c->model('Release')->get_by_gid($self->data->{entity}{mbid});

# The release used to link (if it still exists) from the release field.
my $field_release = $loaded_release ||
Release->new(
name => $self->data->{entity}{name},
# Allow linking to release redirecting to still existing release.
defined $gid_loaded_release ? (
id => $self->data->{entity}{id},
gid => $self->data->{entity}{mbid},
) : (),
);

$data{release} = to_json_object($field_release);

# The release used (even if merged or removed) to load image from the cover art field.
my $artwork_release = $loaded_release ||
Release->new(
gid => $self->data->{entity}{mbid},
id => $self->data->{entity}{id},
name => $self->data->{entity}{name},
);

my $artwork;
if ($data{release}) {
$artwork = $self->c->model('Artwork')->find_by_release($data{release});
if ($gid_loaded_release) {
$artwork = $self->c->model('Artwork')->find_by_release($gid_loaded_release);
$self->c->model('CoverArtType')->load_for(@$artwork);
} else {
$data{release} = Release->new( name => $self->data->{entity}{name},
id => $self->data->{entity}{id},
gid => $self->data->{entity}{mbid} );
$artwork = [];
}
my %artwork_by_id = map { $_->id => $_ } @$artwork;

for my $undef_artwork (grep { !defined $artwork_by_id{$_->{id}} } @{ $self->data->{old} }) {
my $fake_artwork = Artwork->new( release => $data{release}, id => $undef_artwork->{id});
my $fake_artwork = Artwork->new( release => $artwork_release, id => $undef_artwork->{id});
push @$artwork, $fake_artwork;
$artwork_by_id{$undef_artwork->{id}} = $fake_artwork;
}
Expand All @@ -135,8 +151,6 @@ sub build_display_data {
$data{old} = [ map { to_json_object($artwork_by_id{$_->{id}}) } @old ];
$data{new} = [ map { to_json_object($artwork_by_id{$_->{id}}) } @new ];

$data{release} = to_json_object($data{release});

return \%data;
}

Expand Down