[mb-commits] branch, mbs-5732, created. MBS-5732: Show the 'cleanup' banner for labels with no releases or relationships

MusicBrainz Git Server <[email protected]> Tue, 22 Jan 2013 17:07:17 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1TxhJd-0006NM-W6@wiley>
The branch, mbs-5732 has been created
        at  0d61474a88681ac1f14d88c94c229adc840d38f8 (commit)

- Log -----------------------------------------------------------------
commit 0d61474a88681ac1f14d88c94c229adc840d38f8
Author: Oliver Charles <[email protected]>
Date:   Tue Jan 22 17:07:04 2013 +0000

    MBS-5732: Show the 'cleanup' banner for labels with no releases or relationships

diff --git a/lib/MusicBrainz/Server/Controller/Label.pm b/lib/MusicBrainz/Server/Controller/Label.pm
index 4f88ae0..ada5395 100644
--- a/lib/MusicBrainz/Server/Controller/Label.pm
+++ b/lib/MusicBrainz/Server/Controller/Label.pm
@@ -10,6 +10,7 @@ with 'MusicBrainz::Server::Controller::Role::Load' => {
 with 'MusicBrainz::Server::Controller::Role::LoadWithRowID';
 with 'MusicBrainz::Server::Controller::Role::Annotation';
 with 'MusicBrainz::Server::Controller::Role::Alias';
+with 'MusicBrainz::Server::Controller::Role::Cleanup';
 with 'MusicBrainz::Server::Controller::Role::Details';
 with 'MusicBrainz::Server::Controller::Role::EditListing';
 with 'MusicBrainz::Server::Controller::Role::IPI';
diff --git a/lib/MusicBrainz/Server/Data/Label.pm b/lib/MusicBrainz/Server/Data/Label.pm
index f72d5c4..d6837cd 100644
--- a/lib/MusicBrainz/Server/Data/Label.pm
+++ b/lib/MusicBrainz/Server/Data/Label.pm
@@ -2,6 +2,7 @@ package MusicBrainz::Server::Data::Label;
 
 use Moose;
 use namespace::autoclean;
+use MusicBrainz::Server::Constants qw( $STATUS_OPEN );
 use MusicBrainz::Server::Data::Edit;
 use MusicBrainz::Server::Data::ReleaseLabel;
 use MusicBrainz::Server::Entity::Label;
@@ -291,6 +292,62 @@ sub load_meta
     }, @_);
 }
 
+sub is_empty {
+    my ($self, $label_id) = @_;
+
+    return $self->sql->select_single_value(<<'EOSQL', $label_id, $STATUS_OPEN);
+        SELECT TRUE
+        FROM label label_row
+        WHERE id = ?
+        AND edits_pending = 0
+        AND NOT (
+          EXISTS (
+            SELECT TRUE FROM edit_label
+            WHERE status = ? AND label = label_row.id
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM release_label
+            WHERE label = label_row.id
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_recording
+            WHERE entity0 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_work
+            WHERE entity0 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_url
+            WHERE entity0 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_label
+            WHERE entity0 = label_row.id OR entity1 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_artist_label
+            WHERE entity1 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_release
+            WHERE entity0 = label_row.id
+            LIMIT 1
+          ) OR
+          EXISTS (
+            SELECT TRUE FROM l_label_release_group
+            WHERE entity0 = label_row.id
+            LIMIT 1
+          )
+        )
+EOSQL
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 1;
diff --git a/root/label/index.tt b/root/label/index.tt
index 2a90c37..54f181b 100644
--- a/root/label/index.tt
+++ b/root/label/index.tt
@@ -1,6 +1,14 @@
 [%- WRAPPER "label/layout.tt" page='index' -%]
     [%- INCLUDE 'label/annotation.tt' summary=1 -%]
 
+    [% IF eligble_for_cleanup %]
+      <p class="cleanup">
+          [% l('This label has no relationships or releases and will be removed
+                automatically in the next few days. If this is not intended,
+                please add more data to this label.') %]
+      </p>
+    [% END %]
+
     [%- show_wikipedia_extract() -%]
 
     <h2 class="releases">[% l('Releases') %]</h2>

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


hooks/post-receive
-- 
mb_server