-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
ChangeTrackArtist.pm
88 lines (74 loc) · 2.38 KB
/
ChangeTrackArtist.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package MusicBrainz::Server::Edit::Historic::ChangeTrackArtist;
use strict;
use warnings;
use MusicBrainz::Server::Constants qw( $EDIT_HISTORIC_CHANGE_TRACK_ARTIST );
use MusicBrainz::Server::Translation qw( N_l );
use MusicBrainz::Server::Edit::Historic::Base;
use aliased 'MusicBrainz::Server::Entity::Artist';
use aliased 'MusicBrainz::Server::Entity::Recording';
sub edit_name { N_l('Edit track (historic)') }
sub edit_kind { 'edit' }
sub edit_type { $EDIT_HISTORIC_CHANGE_TRACK_ARTIST }
sub historic_type { 10 }
sub edit_template { 'historic/edit_track' }
sub _build_related_entities {
my $self = shift;
return {
artist => [ $self->data->{new_artist_id}, $self->data->{old_artist_id} ],
recording => [ $self->data->{recording_id} ]
}
}
sub foreign_keys
{
my $self = shift;
return {
Artist => [ $self->data->{new_artist_id}, $self->data->{old_artist_id} ],
Recording => [ $self->data->{recording_id} ]
}
}
sub build_display_data
{
my ($self, $loaded) = @_;
return {
recording => $loaded->{Recording}->{ $self->data->{recording_id} } ||
Recording->new(
id => $self->data->{recording_id},
),
artist => {
old => $loaded->{Artist}->{ $self->data->{old_artist_id} } ||
Artist->new(
id => $self->data->{old_artist_id},
name => $self->data->{old_artist_name}
),
new => $loaded->{Artist}->{ $self->data->{new_artist_id} } ||
Artist->new(
id => $self->data->{new_artist_id},
name => $self->data->{new_artist_name}
),
}
}
}
sub upgrade
{
my $self = shift;
$self->data({
recording_id => $self->resolve_recording_id($self->row_id),
old_artist_id => $self->artist_id,
old_artist_name => $self->previous_value,
new_artist_id => $self->new_value->{artist_id},
new_artist_name => $self->new_value->{name},
});
return $self;
}
sub deserialize_previous_value { return $_[1] }
sub deserialize_new_value
{
my ($self, $value) = @_;
my ($name, $sort_name, $id) = split /\n/, $value;
return {
name => $name,
sort_name => $sort_name,
artist_id => $id || 0 # Some edits appear to lack this - 1792375
}
}
1;