[mb-commits] branch, data-nes, updated. Add some very basic support for viewing URL relationships on work index pages
MusicBrainz Git Server <[email protected]> Fri, 01 Feb 2013 13:02:18 +0000
| Newsgroups | gmane.comp.audio.musicbrainz.cvs |
|---|---|
| Message-ID | <E1U1GG2-0005UH-41@wiley> |
The branch, data-nes has been updated
discards http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=5173047b2c110437563c496b72c031e108bb329e (commit)
via http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=d2762d22a43038128404459b15b8f108a0133da0 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (5173047b2c110437563c496b72c031e108bb329e)
\
N -- N -- N (d2762d22a43038128404459b15b8f108a0133da0)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Summary of changes:
lib/MusicBrainz/Server/Data/NES/Work.pm | 1 +
lib/MusicBrainz/Server/Entity/NES/Relationship.pm | 14 +++++++++++++-
2 files changed, 14 insertions(+), 1 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 d2762d22a43038128404459b15b8f108a0133da0
Author: Oliver Charles <[email protected]>
Date: Fri Feb 1 13:59:37 2013 +0000
Add some very basic support for viewing URL relationships on work index pages
diff --git a/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm b/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
index dec899b..2a3ba7c 100644
--- a/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
+++ b/lib/MusicBrainz/Server/Controller/Edit/Relationship.pm
@@ -5,6 +5,7 @@ BEGIN { extends 'MusicBrainz::Server::Controller' };
use MusicBrainz::Server::Constants qw( $EDIT_RELATIONSHIP_DELETE );
use MusicBrainz::Server::Data::Utils qw( type_to_model );
+use MusicBrainz::Server::Entity::Link;
use MusicBrainz::Server::Entity::NES::Relationship;
use MusicBrainz::Server::Entity::Tree::Work;
use MusicBrainz::Server::Edit::Relationship::Delete;
@@ -346,8 +347,11 @@ sub create_url : Local RequireAuth Edit
MusicBrainz::Server::Entity::Tree::Work->new(
relationships => [
MusicBrainz::Server::Entity::NES::Relationship->new(
- link_type_id => $form->field('link_type_id')->value,
- target => $url
+ link => MusicBrainz::Server::Entity::Link->new(
+ type_id => $form->field('link_type_id')->value
+ ),
+ target => $url,
+ target_type => 'url'
)
]
)
diff --git a/lib/MusicBrainz/Server/Controller/Role/Relationship.pm b/lib/MusicBrainz/Server/Controller/Role/Relationship.pm
index 16cb226..8a4b59f 100644
--- a/lib/MusicBrainz/Server/Controller/Role/Relationship.pm
+++ b/lib/MusicBrainz/Server/Controller/Role/Relationship.pm
@@ -66,7 +66,9 @@ after 'load' => sub {
my ($self, $c) = @_;
my $entity = $c->stash->{entity};
if ($c->action->name ne 'relationships') {
- $c->model('Relationship')->load_subset([ 'url' ], $entity);
+ $c->model('MB')->with_nes_transaction(sub {
+ $c->model($self->{model})->load_relationships($entity)
+ });
}
};
diff --git a/lib/MusicBrainz/Server/Controller/Work.pm b/lib/MusicBrainz/Server/Controller/Work.pm
index 8d38260..b2430bd 100644
--- a/lib/MusicBrainz/Server/Controller/Work.pm
+++ b/lib/MusicBrainz/Server/Controller/Work.pm
@@ -27,8 +27,8 @@ with 'MusicBrainz::Server::Controller::Role::Cleanup';
with 'MusicBrainz::Server::Controller::Role::Details';
with 'MusicBrainz::Server::Controller::Role::EditListing';
with 'MusicBrainz::Server::Controller::Role::Rating';
+with 'MusicBrainz::Server::Controller::Role::Relationship';
with 'MusicBrainz::Server::Controller::Role::Tag';
-# with 'MusicBrainz::Server::Controller::Role::Relationship';
# with 'MusicBrainz::Server::Controller::Role::WikipediaExtract';
use aliased 'MusicBrainz::Server::Entity::ArtistCredit';
diff --git a/lib/MusicBrainz/Server/Data/NES/CoreEntity.pm b/lib/MusicBrainz/Server/Data/NES/CoreEntity.pm
index 9df8568..590ece5 100644
--- a/lib/MusicBrainz/Server/Data/NES/CoreEntity.pm
+++ b/lib/MusicBrainz/Server/Data/NES/CoreEntity.pm
@@ -51,7 +51,7 @@ role {
method get_by_gid => sub {
my ($self, $gid) = @_;
return $self->_new_from_core_entity(
- $self->request('/work/find-latest', { mbid => $gid }))
+ $self->request($params->root . '/find-latest', { mbid => $gid }))
};
method _new_from_core_entity => sub {
diff --git a/lib/MusicBrainz/Server/Data/NES/Work.pm b/lib/MusicBrainz/Server/Data/NES/Work.pm
index aae8f8a..555e9af 100644
--- a/lib/MusicBrainz/Server/Data/NES/Work.pm
+++ b/lib/MusicBrainz/Server/Data/NES/Work.pm
@@ -1,7 +1,10 @@
package MusicBrainz::Server::Data::NES::Work;
+use feature 'switch';
use Moose;
+use List::UtilsBy qw( partition_by );
use MusicBrainz::Server::Data::Utils qw( partial_date_to_hash );
+use MusicBrainz::Server::Entity::NES::Relationship;
use MusicBrainz::Server::Entity::Work;
use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw( boolean );
@@ -60,14 +63,12 @@ sub tree_to_json {
}, @{ $tree->aliases }
],
relationships => {
- url => [
+ partition_by { $_->{target_type} }
map +{
target => $_->target->gid,
- type => $_->link_type_id
- }, grep {
- $_->target->isa('MusicBrainz::Server::Entity::URL')
- } @{ $tree->relationships }
- ]
+ type => $_->link_type_id,
+ target_type => $_->target_type
+ }, @{ $tree->relationships }
}
);
}
@@ -126,6 +127,39 @@ sub get_annotation {
)->{annotation};
}
+sub get_relationships {
+ my ($self, $revision) = @_;
+ my @rels =
+ map {
+ my $rel = $_;
+ my $target;
+ given ($rel->{'target-type'}) {
+ when (/url/) {
+ $target = $self->c->model('NES::URL')->get_by_gid($rel->{target});
+ }
+ }
+
+ MusicBrainz::Server::Entity::NES::Relationship->new(
+ target => $target,
+ target_gid => $rel->{target},
+ link => MusicBrainz::Server::Entity::Link->new(
+ type_id => $rel->{type},
+ direction => $MusicBrainz::Server::Entity::NES::Relationship::DIRECTION_BACKWARD
+ ),
+ target_type => $rel->{'target-type'},
+ );
+ } @{
+ $self->request(
+ '/work/view-relationships',
+ { revision => $revision->revision_id }
+ )
+ };
+
+ $self->c->model('LinkType')->load(map { $_->link } @rels);
+
+ return \@rels;
+}
+
sub load_annotation {
my ($self, $work) = @_;
$work->latest_annotation(
@@ -141,5 +175,12 @@ sub is_empty {
)->{eligible};
}
+sub load_relationships {
+ my ($self, @works) = @_;
+ for my $work (@works) {
+ $work->relationships($self->get_relationships($work));
+ }
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/lib/MusicBrainz/Server/Entity/NES/Relationship.pm b/lib/MusicBrainz/Server/Entity/NES/Relationship.pm
index a16a8a2..ba22fb4 100644
--- a/lib/MusicBrainz/Server/Entity/NES/Relationship.pm
+++ b/lib/MusicBrainz/Server/Entity/NES/Relationship.pm
@@ -1,14 +1,110 @@
package MusicBrainz::Server::Entity::NES::Relationship;
use Moose;
+use MusicBrainz::Server::Entity::Types;
+use MusicBrainz::Server::Validation qw( trim_in_place );
+use MusicBrainz::Server::Translation qw( l );
+use Readonly;
+
has target => (
is => 'ro',
- required => 1
);
-has link_type_id => (
+has target_gid => (
+ is => 'ro',
+);
+
+has target_type => (
is => 'ro',
required => 1
);
+has link => (
+ is => 'ro',
+);
+
+has 'phrase' => (
+ is => 'ro',
+ builder => '_build_phrase',
+ lazy => 1
+);
+
+has 'verbose_phrase' => (
+ is => 'ro',
+ builder => '_build_verbose_phrase',
+ lazy => 1
+);
+
+Readonly our $DIRECTION_FORWARD => 1;
+Readonly our $DIRECTION_BACKWARD => 2;
+
+sub _join_attrs
+{
+ my @attrs = map { $_ } @{$_[0]};
+ if (scalar(@attrs) > 1) {
+ my $a = pop(@attrs);
+ my $b = join(l(", "), @attrs);
+ return l("{b} and {a}", {b => $b, a => $a});
+ }
+ elsif (scalar(@attrs) == 1) {
+ return $attrs[0];
+ }
+ return '';
+}
+
+has direction => (
+ default => $DIRECTION_FORWARD,
+ is => 'ro',
+);
+
+sub _build_phrase {
+ my ($self) = @_;
+ $self->_interpolate(
+ $self->direction == $DIRECTION_FORWARD
+ ? $self->link->type->l_link_phrase()
+ : $self->link->type->l_reverse_link_phrase());
+}
+
+sub _build_verbose_phrase {
+ my ($self) = @_;
+ $self->_interpolate($self->link->type->short_link_phrase);
+}
+
+sub _interpolate
+{
+ my ($self, $phrase) = @_;
+
+ my @attrs = $self->link->all_attributes;
+ my %attrs;
+ foreach my $attr (@attrs) {
+ my $name = lc $attr->root->name;
+ my $value = $attr->l_name();
+ if (exists $attrs{$name}) {
+ push @{$attrs{$name}}, $value;
+ }
+ else {
+ $attrs{$name} = [ $value ];
+ }
+ }
+
+ my $replace_attrs = sub {
+ my ($name, $alt) = @_;
+ if (!$alt) {
+ return '' unless exists $attrs{$name};
+ return _join_attrs($attrs{$name});
+ }
+ else {
+ my ($alt1, $alt2) = split /\|/, $alt;
+ return $alt2 || '' unless exists $attrs{$name};
+ my $attr = _join_attrs($attrs{$name});
+ $alt1 =~ s/%/$attr/eg;
+ return $alt1;
+ }
+ };
+ $phrase =~ s/{(.*?)(?::(.*?))?}/$replace_attrs->(lc $1, $2)/eg;
+ trim_in_place($phrase);
+
+ return $phrase;
+}
+
1;
diff --git a/lib/MusicBrainz/Server/Entity/Role/Linkable.pm b/lib/MusicBrainz/Server/Entity/Role/Linkable.pm
index c376c94..357a205 100644
--- a/lib/MusicBrainz/Server/Entity/Role/Linkable.pm
+++ b/lib/MusicBrainz/Server/Entity/Role/Linkable.pm
@@ -6,7 +6,7 @@ use List::UtilsBy qw( sort_by );
has 'relationships' => (
is => 'rw',
- isa => 'ArrayRef[Relationship]',
+ isa => 'ArrayRef',
default => sub { [] },
lazy => 1,
traits => [ 'Array' ],
@@ -25,12 +25,12 @@ sub grouped_relationships
my %groups;
my @relationships = sort {
- my $a_sortname = $a->target->can('sort_name') ?
- $a->target->sort_name :
- $a->target->name;
- my $b_sortname = $b->target->can('sort_name') ?
- $b->target->sort_name :
- $b->target->name;
+ my $a_sortname = $a->target->can('sort_name')
+ ? $a->target->sort_name
+ : $a->target->name;
+ my $b_sortname = $b->target->can('sort_name')
+ ? $b->target->sort_name
+ : $b->target->name;
$a->link->begin_date <=> $b->link->begin_date ||
$a->link->end_date <=> $b->link->end_date ||
$a->link->type->child_order <=> $b->link->type->child_order ||
diff --git a/lib/MusicBrainz/Server/NES.pm b/lib/MusicBrainz/Server/NES.pm
index 3226f08..9118ce9 100644
--- a/lib/MusicBrainz/Server/NES.pm
+++ b/lib/MusicBrainz/Server/NES.pm
@@ -63,6 +63,7 @@ sub with_transaction {
return try {
my $ret = $code->();
$self->request('/close-session', {});
+ $self->clear_session_token;
return $ret;
}
-----------------------------------------------------------------------
hooks/post-receive
--
mb_server