[mb-commits] branch, data-nes, updated. Support selecting attributes when creating relationships
MusicBrainz Git Server <[email protected]> Mon, 04 Feb 2013 11:17:49 +0000
| Newsgroups | gmane.comp.audio.musicbrainz.cvs |
|---|---|
| Message-ID | <E1U2K3Z-0007f9-OP@wiley> |
The branch, data-nes has been updated
via http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=0bc5fd18e725be7147dec7f8c3f9523cf9d27e66 (commit)
from http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=22226df9992faefdb58f3684a57cf72c9b1f77b7 (commit)
Summary of changes:
.../Server/Controller/Edit/Relationship.pm | 42 +++++++++++++-------
lib/MusicBrainz/Server/Data/NES/Work.pm | 12 +++++-
2 files changed, 38 insertions(+), 16 deletions(-)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0bc5fd18e725be7147dec7f8c3f9523cf9d27e66
Author: Oliver Charles <[email protected]>
Date: Mon Feb 4 14:15:57 2013 +0000
Support selecting attributes when creating relationships
diff --git a/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm b/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
index dce1938..ba4d67d 100644
--- a/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
+++ b/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
@@ -206,7 +206,7 @@ sub create : Local RequireAuth Edit
$c->model('MB')->with_nes_transaction(sub {
my ($source, $dest) = ($source_model->get_by_gid($source_gid), $dest_model->get_by_gid($dest_gid));
- if ($type0 eq $type1 && $source->gid == $dest->gid) {
+ if ($type0 eq $type1 && $source->gid eq $dest->gid) {
$c->stash( message => l('A relationship requires 2 different entities') );
$c->detach('/error_500');
}
@@ -258,14 +258,12 @@ sub create : Local RequireAuth Edit
my $rels = shift;
return [
@$rels,
- MusicBrainz::Server::Entity::NES::Relationship->new(
- link => MusicBrainz::Server::Entity::Link->new(
- type_id => $form->field('link_type_id')->value
- ),
- target => $entity1,
- target_type => 'work'
+ form_relationship(
+ $form->field('link_type_id')->value,
+ \@attributes,
+ $type1 => $entity1
)
- ];
+ ];
});
delete $c->session->{relationship};
@@ -347,12 +345,10 @@ sub create_url : Local RequireAuth Edit
my $rels = shift;
return [
@$rels,
- MusicBrainz::Server::Entity::NES::Relationship->new(
- link => MusicBrainz::Server::Entity::Link->new(
- type_id => $form->field('link_type_id')->value
- ),
- target => $url,
- target_type => 'url'
+ form_relationship(
+ $form->field('link_type_id')->value,
+ \@attributes,
+ url => $url
)
]
});
@@ -364,6 +360,24 @@ sub create_url : Local RequireAuth Edit
});
}
+sub form_relationship {
+ my ($link_type_id, $attributes, $target_type, $target) = @_;
+ return MusicBrainz::Server::Entity::NES::Relationship->new(
+ link => MusicBrainz::Server::Entity::Link->new(
+ type_id => $link_type_id,
+ attributes => [
+ map {
+ MusicBrainz::Server::Entity::LinkAttributeType->new(
+ id => $_
+ )
+ } @$attributes
+ ]
+ ),
+ target => $target,
+ target_type => $target_type
+ );
+}
+
sub run_update {
my ($c, $edit, $m, $source, $update) = @_;
diff --git a/lib/MusicBrainz/Server/Data/NES/Work.pm b/lib/MusicBrainz/Server/Data/NES/Work.pm
index 24edac9..9e24d32 100644
--- a/lib/MusicBrainz/Server/Data/NES/Work.pm
+++ b/lib/MusicBrainz/Server/Data/NES/Work.pm
@@ -68,7 +68,8 @@ sub tree_to_json {
map +{
target => $_->target->gid,
type => $_->link->type_id,
- target_type => $_->target_type
+ target_type => $_->target_type,
+ attributes => [ map { $_->id } $_->link->all_attributes ]
}, @{ $tree->relationships }
}
);
@@ -155,7 +156,10 @@ sub get_relationships {
target_gid => $rel->{target},
link => MusicBrainz::Server::Entity::Link->new(
type_id => $rel->{type},
- direction => $MusicBrainz::Server::Entity::NES::Relationship::DIRECTION_BACKWARD
+ direction => $MusicBrainz::Server::Entity::NES::Relationship::DIRECTION_BACKWARD,
+ attributes => [
+ values %{ $self->c->model('LinkAttributeType')->get_by_ids(@{ $rel->{attributes} }) }
+ ]
),
target_type => $rel->{'target-type'},
);
@@ -166,6 +170,10 @@ sub get_relationships {
)
};
+ for my $attribute (map { $_->link->all_attributes } @rels) {
+ $attribute->root($self->c->model('LinkAttributeType')->get_by_id($attribute->root_id));
+ }
+
$self->c->model('LinkType')->load(map { $_->link } @rels);
return \@rels;
-----------------------------------------------------------------------
hooks/post-receive
--
mb_server