This repository has been archived by the owner on Jun 24, 2018. It is now read-only.
/
Artist.pm
81 lines (63 loc) · 2.01 KB
/
Artist.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
package MusicBrainz::Schema::Result::Artist;
use Moose;
extends 'DBIx::Class', 'Moose::Object';
with 'MusicBrainz::Role::Quality';
use Data::UUID;
use Readonly;
__PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/
id name gid modpending sortname resolution begindate
enddate type quality modpending_qual page
/);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(releases => 'MusicBrainz::Schema::Result::Release', 'artist');
__PACKAGE__->has_many(aliases => 'MusicBrainz::Schema::Result::Alias::Artist', 'ref');
__PACKAGE__->has_many(
artist_subscribed_editors => 'MusicBrainz::Schema::Result::Subscribe::Artist', 'artist'
);
__PACKAGE__->many_to_many(subscribed_editors => 'artist_subscribed_editors', 'editor');
Readonly::Scalar our $ARTIST_TYPE_UNKNOWN => 0;
Readonly::Scalar our $ARTIST_TYPE_PERSON => 1;
Readonly::Scalar our $ARTIST_TYPE_GROUP => 2;
my %artist_type_names = (
$ARTIST_TYPE_UNKNOWN => [ 'Unknown', 'Begin Date', 'End Date' ],
$ARTIST_TYPE_PERSON => [ 'Person', 'Born', 'Deceased' ],
$ARTIST_TYPE_GROUP => [ 'Group', 'Founded', 'Dissolved' ],
);
sub new {
my ($class, $attrs) = @_;
$attrs->{gid} = lc Data::UUID->new->create_str
unless defined $attrs->{foo};
return $class->next::method($attrs);
}
sub type_name
{
my $self = shift;
return $artist_type_names{$self->type}->[0];
}
sub begin_date_label
{
my $self = shift;
return $artist_type_names{$self->type}->[1];
}
sub end_date_label
{
my $self = shift;
return $artist_type_names{$self->type}->[2];
}
sub merge_into {
my ($self, $destination) = @_;
my $d_id = $destination->id;
$self->aliases->update({ ref => $d_id });
$self->releases->update({ artist => $d_id });
$self->annotations->update({ rowid => $d_id });
$self->delete;
return $destination;
}
sub annotations {
my ($self) = @_;
my $schema = $self->result_source->schema;
$schema->resultset('Annotation')->for_artist($self);
}
1;