[mb-commits] branch, mbs-5687, created. MBS-5687, Detect and notify the user when a race condition occurs with two ed...

MusicBrainz Git Server <[email protected]> Sat, 29 Dec 2012 16:41:33 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1TozTZ-0001E7-6m@wiley>
The branch, mbs-5687 has been created
        at  6eefff05324eeedd7cff69c36c1ae0fe43f375f4 (commit)

- Log -----------------------------------------------------------------
commit 6eefff05324eeedd7cff69c36c1ae0fe43f375f4
Author: warp <[email protected]>
Date:   Sat Dec 29 17:40:29 2012 +0100

    MBS-5687, Detect and notify the user when a race condition occurs with two editors editing the same tracklist.

diff --git a/lib/MusicBrainz/Server/Wizard/ReleaseEditor.pm b/lib/MusicBrainz/Server/Wizard/ReleaseEditor.pm
index 9b4d04b..ea38b6b 100644
--- a/lib/MusicBrainz/Server/Wizard/ReleaseEditor.pm
+++ b/lib/MusicBrainz/Server/Wizard/ReleaseEditor.pm
@@ -679,9 +679,13 @@ sub prepare_recordings
         $medium->{edits} = $self->edited_tracklist ($json->decode ($medium->{edits}))
             if $medium->{edits};
 
-        if ($medium->{edits} && defined $medium->{tracklist_id})
+        my $tracklist = defined $medium->{tracklist_id} ?
+            $tracklists_by_id->{$medium->{tracklist_id}} : undef;
+
+        if ($medium->{edits} && $tracklist)
         {
             my $tracklist = $tracklists_by_id->{$medium->{tracklist_id}};
+
             $self->c->model ('Recording')->load ($tracklist->all_tracks);
             $self->c->model ('ArtistCredit')->load (map { $_->recording } $tracklist->all_tracks);
 
@@ -712,6 +716,17 @@ sub prepare_recordings
         }
         elsif ($medium->{edits})
         {
+            if (defined $medium->{tracklist_id})
+            {
+                # We have a tracklist id, but failed to load it.  That
+                # probably means the release is being edited by
+                # multiple people at the same time -- one of them
+                # changed the tracklist (which assigns a new id) so we
+                # cannot find it anymore.
+
+                $self->c->stash( tracklist_vanished => 1 );
+            }
+
             # A new tracklist has been entered, create new recordings
             # for all these tracks by default (no recording
             # assocations are suggested).
diff --git a/root/release/edit/recordings.tt b/root/release/edit/recordings.tt
index 2571279..b88806f 100644
--- a/root/release/edit/recordings.tt
+++ b/root/release/edit/recordings.tt
@@ -179,6 +179,10 @@
       [%- notice(l('Some tracks were changed, please select a recording for each of these tracks.')) -%]
     [%- END -%]
 
+    [%- IF tracklist_vanished -%]
+      [%- warning(l('A tracklist on this release has been recently changed by someone else, cannot load recordings.')) -%]
+    [%- END -%]
+
     [%- USE w = Wizard() -%]
     [%- information = w.page('information') -%]
     [%- multidisc = tracklist_edits.size > 1 -%]

-----------------------------------------------------------------------


hooks/post-receive
-- 
mb_server