[mb-commits] r9778 - in mb_server/branches/ReleaseTrack: cgi-bin cgi-bin/MusicBrainz/Server cgi-bin/MusicBrainz/Server/Moderation htdocs/comp htdocs/comp/moderation htdocs/edit/track htdocs/show/artist htdocs/show/edit
root at musicbrainz.org
root at musicbrainz.org
Sun Mar 16 18:56:14 UTC 2008
Author: luks
Date: 2008-03-16 18:56:13 +0000 (Sun, 16 Mar 2008)
New Revision: 9778
Added:
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_MERGE_TRACKS.pm
mb_server/branches/ReleaseTrack/htdocs/comp/moderation/MOD_MERGE_TRACKS
Modified:
mb_server/branches/ReleaseTrack/cgi-bin/ModDefs.pm
mb_server/branches/ReleaseTrack/cgi-bin/Moderation.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_CHANGE_TRACK_ARTIST.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNAME.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNUM.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Release.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/ReleaseTrack.pm
mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Track.pm
mb_server/branches/ReleaseTrack/htdocs/comp/linktrack
mb_server/branches/ReleaseTrack/htdocs/edit/track/edit.html
mb_server/branches/ReleaseTrack/htdocs/show/artist/tracks.html
mb_server/branches/ReleaseTrack/htdocs/show/edit/index.html
Log:
Track merging
Modified: mb_server/branches/ReleaseTrack/cgi-bin/ModDefs.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/ModDefs.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/ModDefs.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -137,7 +137,8 @@
use constant MOD_REMOVE_LABELALIAS => 62;
use constant MOD_CHANGE_RELEASE_QUALITY => 63;
use constant MOD_ADD_TRACK_ANNOTATION => 64;
-use constant MOD_LAST => 64;
+use constant MOD_MERGE_TRACKS => 65;
+use constant MOD_LAST => 65;
# Values used for edit levels (quality)
use constant QUALITY_UNKNOWN => -1;
Modified: mb_server/branches/ReleaseTrack/cgi-bin/Moderation.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/Moderation.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/Moderation.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -80,6 +80,7 @@
require MusicBrainz::Server::Moderation::MOD_MERGE_RELEASE_MAC;
require MusicBrainz::Server::Moderation::MOD_MERGE_ARTIST;
require MusicBrainz::Server::Moderation::MOD_MERGE_LABEL;
+require MusicBrainz::Server::Moderation::MOD_MERGE_TRACKS;
# require MusicBrainz::Server::Moderation::MOD_MERGE_LINK_TYPE; -- not implemented
require MusicBrainz::Server::Moderation::MOD_MOVE_RELEASE;
require MusicBrainz::Server::Moderation::MOD_MOVE_DISCID;
@@ -1730,12 +1731,14 @@
{
$this->{"trackid"} = $track->GetId;
$this->{"trackname"} = $track->GetName;
- $this->{"trackseq"} = $track->GetSequence;
+ # FIXME-TRACKMERGING
+ #$this->{"trackseq"} = $track->GetSequence;
# assume that the release needs to be loaded from
# the album-track core relationship, if it not
# has been set explicitly.
- $this->{"albumid"} = $track->GetRelease if ($this->{"checkexists-album"} && not defined $this->{"albumid"});
+ # FIXME-TRACKMERGING
+ #$this->{"albumid"} = $track->GetRelease if ($this->{"checkexists-album"} && not defined $this->{"albumid"});
}
}
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_CHANGE_TRACK_ARTIST.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_CHANGE_TRACK_ARTIST.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_CHANGE_TRACK_ARTIST.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -131,8 +131,9 @@
# since the track exists, we can see if can load the
# corresponding release.
- $this->{"albumid"} = $track->GetRelease;
- $this->{"checkexists-album"} = 1;
+ # FIXME-TRACKMERGING
+ #$this->{"albumid"} = $track->GetRelease;
+ #$this->{"checkexists-album"} = 1;
# try to guess artist id.
if (!$this->{'new.exists'})
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNAME.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNAME.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNAME.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -81,12 +81,13 @@
$tr->SetId($self->{trackid});
if ($tr->LoadFromId())
{
- my $rel = MusicBrainz::Server::Release->new($self->{DBH});
- $rel->SetId($tr->GetRelease());
- if ($rel->LoadFromId())
- {
- return $rel->GetQuality();
- }
+ # FIXME-TRACKMERGING
+ # my $rel = MusicBrainz::Server::Release->new($self->{DBH});
+ # $rel->SetId($tr->GetRelease());
+ # if ($rel->LoadFromId())
+ # {
+ # return $rel->GetQuality();
+ # }
}
# if that fails, go by the artist
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNUM.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNUM.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_TRACKNUM.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -52,18 +52,18 @@
{
my $self = shift;
- # load track and release object
- require MusicBrainz::Server::Track;
- my $track = MusicBrainz::Server::Track->new($self->{DBH});
+ require MusicBrainz::Server::ReleaseTrack;
+ my $rtrack = MusicBrainz::Server::ReleaseTrack->new($self->{DBH});
- if ($self->{'trackexists'} = $track->LoadFromAlbumJoin($self->GetRowId))
+ $rtrack->SetId($self->GetRowId);
+ if ($self->{'trackexists'} = $rtrack->LoadFromId(1))
{
- $self->{'trackid'} = $track->GetId;
- $self->{'trackname'} = $track->GetName;
+ $self->{'trackid'} = $rtrack->GetTrack->GetId;
+ $self->{'trackname'} = $rtrack->GetTrack->GetName;
require MusicBrainz::Server::Release;
my $release = MusicBrainz::Server::Release->new($self->{DBH});
- $release->SetId($track->GetRelease);
+ $release->SetId($rtrack->GetRelease);
if ($self->{'albumexists'} = $release->LoadFromId)
{
$self->{'albumid'} = $release->GetId;
Added: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_MERGE_TRACKS.pm
Property changes on: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Moderation/MOD_MERGE_TRACKS.pm
___________________________________________________________________
Name: svn:mime-type
+ text/x-perl
Name: svn:eol-style
+ native
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Release.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Release.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Release.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -880,10 +880,10 @@
# get the list of tracks and get their respective
# artistid.
- $tracks = $self->GetTracks;
- foreach my $t (@$tracks)
+ $tracks = $self->FindTracks;
+ foreach my $t (@$tracks)
{
- $ar{$t->GetArtist} = 1;
+ $ar{$t->GetTrack->GetArtist} = 1;
}
$self->{"_isva"} = (keys %ar > 1);
}
@@ -1539,7 +1539,7 @@
sub _GetTrackNumbersHash
{
my $self = shift;
- my $tracks = $self->GetTracks
+ my $tracks = $self->FindTracks
or return +{};
my %h;
@@ -1574,8 +1574,13 @@
{
my $self = shift;
- require MusicBrainz::Server::ReleaseTrack;
- return MusicBrainz::Server::ReleaseTrack->FindByReleaseId($self->{DBH}, $self->GetId);
+ if (!defined($self->{_rtracks})) {
+ require MusicBrainz::Server::ReleaseTrack;
+ $self->{_rtracks} = MusicBrainz::Server::ReleaseTrack->FindByReleaseId($self->{DBH}, $self->GetId);
+ }
+
+ return $self->{_rtracks};
}
+
1;
# eof Release.pm
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/ReleaseTrack.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/ReleaseTrack.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/ReleaseTrack.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -48,7 +48,7 @@
sub SetSequence { $_[0]->{sequence} = $_[1] }
sub LoadFromId {
- my ($self) = @_;
+ my ($self, $loadtrack) = @_;
my $id = $self->GetId;
if (!$id) {
@@ -57,15 +57,39 @@
}
my $sql = Sql->new($self->{DBH});
- my $row = $sql->SelectSingleRowHash("
- SELECT id, album, track, sequence, modpending
- FROM albumjoin WHERE id = ?", $id);
+
+ my $query;
+ if ($loadtrack) {
+ $query = "
+ SELECT
+ a.id, a.album, a.track, a.sequence, a.modpending,
+ t.id AS track_id,
+ t.gid AS track_gid,
+ t.name AS track_name,
+ t.artist AS track_artist,
+ t.length AS track_length,
+ t.modpending AS track_modpending
+ FROM albumjoin a JOIN track t ON a.track = t.id
+ WHERE a.id = ?"
+ }
+ else {
+ $query = "
+ SELECT id, album, track, sequence, modpending
+ FROM albumjoin WHERE id = ?";
+ }
+
+ my $row = $sql->SelectSingleRowHash($query, $id);
if (!defined($row)) {
return undef;
}
$self->LoadFromRow($row);
+ if ($loadtrack) {
+ my $track = MusicBrainz::Server::Track->new($self->{DBH});
+ $track->LoadFromRow($row, "track_");
+ $self->SetTrack($track);
+ }
return 1;
}
@@ -88,6 +112,14 @@
$self->GetSequence, $self->GetId);
}
+sub MergeTracks
+{
+ my ($self, $old, $new) = @_;
+
+ my $sql = Sql->new($self->{DBH});
+ $sql->Do("UPDATE albumjoin SET track = ? WHERE track = ?", $new, $old);
+}
+
# Find all tracks by a release ID
sub FindByReleaseId {
my ($class, $dbh, $releaseid) = @_;
Modified: mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Track.pm
===================================================================
--- mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Track.pm 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/cgi-bin/MusicBrainz/Server/Track.pm 2008-03-16 18:56:13 UTC (rev 9778)
@@ -111,99 +111,44 @@
# Accessor functions. Return true on success, undef otherwise
sub LoadFromId
{
- my ($this) = @_;
+ my ($self) = @_;
- my $id = $this->GetId;
- my $mbid = $this->GetMBId;
+ my $id = $self->GetId;
+ my $mbid = $self->GetMBId;
- if (not $id and not $mbid)
- {
+ if (not $id and not $mbid) {
carp "No ID / MBID specified";
return undef;
}
- my $sql = Sql->new($this->{DBH});
+ my $sql = Sql->new($self->{DBH});
my $row;
- if (my $albumid = $this->{album})
- {
- if ($id)
- {
- $row = $sql->SelectSingleRowArray(
- "SELECT t.id, t.name, t.gid, j.sequence, t.length, t.artist, t.modpending,
- j.modpending, j.id, j.album
- FROM track t, albumjoin j
- WHERE j.track = t.id
- AND j.track = ?
- AND j.album = ?",
- $id,
- $albumid,
- );
- }
- elsif ($mbid)
- {
- $row = $sql->SelectSingleRowArray(
- "SELECT t.id, t.name, t.gid, j.sequence, t.length, t.artist, t.modpending,
- j.modpending, j.id, j.album
- FROM track t, albumjoin j
- WHERE j.track = t.id
- AND t.gid = ?
- AND j.album = ?",
- $mbid,
- $albumid,
- );
- } else {
- croak "No ID / MBID specified";
- }
+ my $query = "
+ SELECT id, name, gid, length, artist, modpending
+ FROM track WHERE";
+
+ if ($id) {
+ $row = $sql->SelectSingleRowHash("$query id = ?", $id);
}
- else
- {
- # FIXME this will fail when tracks appear on more than one album
- if ($id)
- {
- $row = $sql->SelectSingleRowArray(
- "SELECT t.id, t.name, t.gid, j.sequence, t.length, t.artist, t.modpending,
- j.modpending, j.id, j.album
- FROM track t, albumjoin j
- WHERE j.track = t.id
- AND j.track = ?",
- $id,
- );
+ elsif ($mbid) {
+ $row = $sql->SelectSingleRowHash("$query gid = ?", $mbid);
+ if (!defined($row)) {
+ my $newid = $self->CheckGlobalIdRedirect($mbid, &TableBase::TABLE_TRACK);
+ if ($newid) {
+ $self->SetId($newid);
+ $self->SetMBId(undef);
+ return $self->LoadFromId;
+ }
}
- elsif ($mbid)
- {
- $row = $sql->SelectSingleRowArray(
- "SELECT t.id, t.name, t.gid, j.sequence, t.length, t.artist, t.modpending,
- j.modpending, j.id, j.album
- FROM track t, albumjoin j
- WHERE j.track = t.id
- AND t.gid = ?",
- $mbid,
- );
- } else {
- croak "No ID / MBID specified";
- }
}
- if (!$row && $mbid)
- {
- my $newid = $this->CheckGlobalIdRedirect($mbid, &TableBase::TABLE_TRACK);
- if ($newid)
- {
- $this->SetId($newid);
- $this->SetMBId(undef);
- return $this->LoadFromId;
- }
+ if (!defined($row)) {
+ return undef;
}
- $row or return undef;
-
- @$this{qw(
- id name mbid sequence length artist modpending
- albumjoinmodpending sequenceid album
- )} = @$row;
-
- 1;
+ $self->LoadFromRow($row);
+ return 1;
}
sub GetMetadataFromIdAndAlbum
@@ -579,5 +524,67 @@
return (\@tracks, $offset + $count);
}
+sub UpdateModPending
+{
+ my ($self, $adjust) = @_;
+
+ my $sql = Sql->new($self->{DBH});
+ $sql->Do(
+ "UPDATE track SET modpending = GREATEST(modpending + ?, 0) WHERE id = ?",
+ $adjust, $self->GetId);
+}
+
+# Merge tracks with the specified IDs into this one.
+sub MergeTracks
+{
+ my ($self, $trackids) = @_;
+
+ my $sql = Sql->new($self->{DBH});
+ my $new = $self->GetId;
+
+ for my $old (@$trackids)
+ {
+ my $tr = MusicBrainz::Server::Track->new($self->{DBH});
+ $tr->SetId($old);
+ $tr->LoadFromId or die;
+
+ # TRMs
+ require MusicBrainz::Server::TRM;
+ my $trm = MusicBrainz::Server::TRM->new($self->{DBH});
+ $trm->MergeTracks($old, $new);
+
+ # PUIDs
+ require MusicBrainz::Server::PUID;
+ my $puid = MusicBrainz::Server::PUID->new($self->{DBH});
+ $puid->MergeTracks($old, $new);
+
+ # ARs
+ require MusicBrainz::Server::Link;
+ my $link = MusicBrainz::Server::Link->new($self->{DBH});
+ $link->MergeTracks($old, $new);
+
+ # Tag
+ require MusicBrainz::Server::Tag;
+ my $tag = MusicBrainz::Server::Tag->new($self->{DBH});
+ $tag->MergeTracks($old, $new);
+
+ # Remove references from track words table
+ require SearchEngine;
+ my $engine = SearchEngine->new($self->{DBH}, 'track');
+ $engine->RemoveObjectRefs($old);
+
+ # Update track<->release links
+ require MusicBrainz::Server::ReleaseTrack;
+ my $rtrack = MusicBrainz::Server::ReleaseTrack->new($self->{DBH});
+ $rtrack->MergeTracks($old, $new);
+
+ # Add MBID redirect
+ $self->SetGlobalIdRedirect($old, $tr->GetMBId, $new, &TableBase::TABLE_TRACK);
+
+ # Remove the track
+ $sql->Do("DELETE FROM track WHERE id = ?", $old);
+ }
+}
+
1;
# eof Track.pm
Modified: mb_server/branches/ReleaseTrack/htdocs/comp/linktrack
===================================================================
--- mb_server/branches/ReleaseTrack/htdocs/comp/linktrack 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/htdocs/comp/linktrack 2008-03-16 18:56:13 UTC (rev 9778)
@@ -44,6 +44,7 @@
# rendering options
$icon => 1
$strong => 1
+ $modpending => 0
</%args>
<%perl>
@@ -64,6 +65,8 @@
? ' title="' . $m->interp->apply_escapes($title, 'h').'"'
: "";
+ $m->out(qq!<span class="modpending">!) if ($modpending);
+
# render link.
# use span with the background image set to render the release icon.
$m->out(sprintf qq!<span class="linktrack%s"%s>!,
@@ -88,6 +91,8 @@
}
$m->out("</span>");
+ $m->out("</span>") if ($modpending);
+
</%perl>
%return; # no final newline
%# vi: set ts=4 sw=4 ft=mason :
Added: mb_server/branches/ReleaseTrack/htdocs/comp/moderation/MOD_MERGE_TRACKS
Modified: mb_server/branches/ReleaseTrack/htdocs/edit/track/edit.html
===================================================================
--- mb_server/branches/ReleaseTrack/htdocs/edit/track/edit.html 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/htdocs/edit/track/edit.html 2008-03-16 18:56:13 UTC (rev 9778)
@@ -83,7 +83,7 @@
my $last_seq = 0;
if (my $tracks = $release->FindTracks)
{
- my $track_cnt = scalar(@tracks);
+ my $track_cnt = scalar(@$tracks);
$last_seq = (@$tracks ? $tracks->[-1]->GetSequence : 1);
$last_seq = $track_cnt if ($track_cnt > $last_seq);
}
Modified: mb_server/branches/ReleaseTrack/htdocs/show/artist/tracks.html
===================================================================
--- mb_server/branches/ReleaseTrack/htdocs/show/artist/tracks.html 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/htdocs/show/artist/tracks.html 2008-03-16 18:56:13 UTC (rev 9778)
@@ -55,9 +55,9 @@
% my $rownum = 0;
% foreach $track (@$tracks) {
<tr class="<% $rownum++ % 2 ? 'ev' : 'od' %>">
- <td><& /comp/linktrack, track => $track, strong => 0 &></td>
+ <td><& /comp/linktrack, track => $track, strong => 0, modpending => $track->GetModPending &></td>
<td><% MusicBrainz::Server::Track::FormatTrackLength($track->GetLength) %></td>
- <td><& /comp/form/checkbox, name => "track" . $track->GetId &></td>
+ <td><& /comp/form/checkbox, name => "trackids", value => $track->GetId &></td>
</tr>
% }
</table>
Modified: mb_server/branches/ReleaseTrack/htdocs/show/edit/index.html
===================================================================
--- mb_server/branches/ReleaseTrack/htdocs/show/edit/index.html 2008-03-16 16:35:12 UTC (rev 9777)
+++ mb_server/branches/ReleaseTrack/htdocs/show/edit/index.html 2008-03-16 18:56:13 UTC (rev 9778)
@@ -105,6 +105,7 @@
<pre><% $err %></pre>
</div>
<%perl>
+ return;
};
$edit = Moderation->new($mb->{DBH});
More information about the MusicBrainz-commits
mailing list