logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

[mb-commits] r8929 - in mb_server/trunk: admin/sql admin/sql/updates cgi-bi: msg#00057

Subject: [mb-commits] r8929 - in mb_server/trunk: admin/sql admin/sql/updates cgi-bin/MusicBrainz/Server cgi-bin/MusicBrainz/Server/Moderation htdocs/comp htdocs/comp/moderation htdocs/edit/label
Author: luks
Date: 2007-03-21 21:47:57 +0000 (Wed, 21 Mar 2007)
New Revision: 8929

Modified:
   mb_server/trunk/admin/sql/CreateTables.sql
   mb_server/trunk/admin/sql/updates/20061104-1.sql
   mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_ADD_LABEL.pm
   mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_LABEL.pm
   mb_server/trunk/cgi-bin/MusicBrainz/Server/Validation.pm
   mb_server/trunk/htdocs/comp/labeltitle
   mb_server/trunk/htdocs/comp/moderation/MOD_ADD_LABEL
   mb_server/trunk/htdocs/comp/moderation/MOD_EDIT_LABEL
   mb_server/trunk/htdocs/edit/label/add.html
   mb_server/trunk/htdocs/edit/label/edit.html
Log:
Make label code an INTEGER, restrict the format. (closes #2563)

Modified: mb_server/trunk/admin/sql/CreateTables.sql
===================================================================
--- mb_server/trunk/admin/sql/CreateTables.sql  2007-03-21 08:14:55 UTC (rev 
8928)
+++ mb_server/trunk/admin/sql/CreateTables.sql  2007-03-21 21:47:57 UTC (rev 
8929)
@@ -209,7 +209,7 @@
     name                VARCHAR(255) NOT NULL,
     gid                 CHAR(36) NOT NULL,
     modpending          INTEGER DEFAULT 0,
-    labelcode           VARCHAR(255),
+    labelcode           INTEGER,
     sortname            VARCHAR(255) NOT NULL,
     country             INTEGER, -- references country
     page                INTEGER NOT NULL,

Modified: mb_server/trunk/admin/sql/updates/20061104-1.sql
===================================================================
--- mb_server/trunk/admin/sql/updates/20061104-1.sql    2007-03-21 08:14:55 UTC 
(rev 8928)
+++ mb_server/trunk/admin/sql/updates/20061104-1.sql    2007-03-21 21:47:57 UTC 
(rev 8929)
@@ -11,7 +11,7 @@
     name                VARCHAR(255) NOT NULL,
     gid                 CHAR(36) NOT NULL,
     modpending          INTEGER DEFAULT 0,
-    labelcode           VARCHAR(255),
+    labelcode           INTEGER,
     sortname            VARCHAR(255) NOT NULL,
     country             INTEGER, -- references country
     page                INTEGER NOT NULL,

Modified: mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_ADD_LABEL.pm
===================================================================
--- mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_ADD_LABEL.pm      
2007-03-21 08:14:55 UTC (rev 8928)
+++ mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_ADD_LABEL.pm      
2007-03-21 21:47:57 UTC (rev 8929)
@@ -73,7 +73,10 @@
                die 'Invalid end date' unless 
MusicBrainz::Server::Validation::IsValidDate(@$enddate);
                $enddate_str = 
MusicBrainz::Server::Validation::MakeDBDateStr(@$enddate);
        }
-       
+
+       die 'Invalid label code'
+               if ($labelcode && not 
MusicBrainz::Server::Validation::IsValidLabelCode($labelcode));
+
        my $label = Label->new($self->{DBH});
        $label->SetName($name);
        $label->SetSortName($sortname);

Modified: 
mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_LABEL.pm
===================================================================
--- mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_LABEL.pm     
2007-03-21 08:14:55 UTC (rev 8928)
+++ mb_server/trunk/cgi-bin/MusicBrainz/Server/Moderation/MOD_EDIT_LABEL.pm     
2007-03-21 21:47:57 UTC (rev 8929)
@@ -77,8 +77,10 @@
        if ( defined $labelcode )
        {
                MusicBrainz::Server::Validation::TrimInPlace($labelcode);
-               $labelcode =~ s/^LC\s+//;
 
+               die 'Invalid label code'
+                       if ($labelcode && not 
MusicBrainz::Server::Validation::IsValidLabelCode($labelcode));
+
                $new{'LabelCode'} = $labelcode if $labelcode ne 
$ar->GetLabelCode();
        }
 

Modified: mb_server/trunk/cgi-bin/MusicBrainz/Server/Validation.pm
===================================================================
--- mb_server/trunk/cgi-bin/MusicBrainz/Server/Validation.pm    2007-03-21 
08:14:55 UTC (rev 8928)
+++ mb_server/trunk/cgi-bin/MusicBrainz/Server/Validation.pm    2007-03-21 
21:47:57 UTC (rev 8929)
@@ -203,6 +203,18 @@
     return 1;
 }
 
+sub IsValidLabelCode
+{
+       my $t = shift;
+       defined($t) and not ref($t) and $t =~ /\A(\d{1,5})\z/;
+}
+
+sub MakeDisplayLabelCode
+{
+       my $labelcode = shift;
+       return sprintf("LC-%05d", $labelcode)
+}
+
 # This wrapper will prevent us from having the stupid patched version of the 
Text::Unaccent library
 # which in turn will make the mb_server install process simpler.
 sub unaccent($) 

Modified: mb_server/trunk/htdocs/comp/labeltitle
===================================================================
--- mb_server/trunk/htdocs/comp/labeltitle      2007-03-21 08:14:55 UTC (rev 
8928)
+++ mb_server/trunk/htdocs/comp/labeltitle      2007-03-21 21:47:57 UTC (rev 
8929)
@@ -94,7 +94,7 @@
        {
                if ($labelcode)
                {
-                       $m->out("LC ".$m->interp->apply_escapes($labelcode, 
'h'));
+                       
$m->out(MusicBrainz::Server::Validation::MakeDisplayLabelCode($labelcode));
                        $m->out(", ") if ($date_str or $country or $type);
                }
                if ($date_str)

Modified: mb_server/trunk/htdocs/comp/moderation/MOD_ADD_LABEL
===================================================================
--- mb_server/trunk/htdocs/comp/moderation/MOD_ADD_LABEL        2007-03-21 
08:14:55 UTC (rev 8928)
+++ mb_server/trunk/htdocs/comp/moderation/MOD_ADD_LABEL        2007-03-21 
21:47:57 UTC (rev 8929)
@@ -68,7 +68,7 @@
                <tr>
                        <td class="lbl">Label code:</td>
                        <td>
-                               LC <% $labelcode %></td>
+                               <% 
MusicBrainz::Server::Validation::MakeDisplayLabelCode($labelcode) %></td>
                </tr>
 %      }
 

Modified: mb_server/trunk/htdocs/comp/moderation/MOD_EDIT_LABEL
===================================================================
--- mb_server/trunk/htdocs/comp/moderation/MOD_EDIT_LABEL       2007-03-21 
08:14:55 UTC (rev 8928)
+++ mb_server/trunk/htdocs/comp/moderation/MOD_EDIT_LABEL       2007-03-21 
21:47:57 UTC (rev 8929)
@@ -60,7 +60,7 @@
                <tr>
                        <td class="lbl">Label code:</td>
                        <td class="diff" id="ov::labelcode<% $id %>">
-                               LC <% $prev->{"LabelCode"} %>
+                               <% 
MusicBrainz::Server::Validation::MakeDisplayLabelCode($prev->{"LabelCode"}) %>
                        </td>
                </tr>
 %      }
@@ -180,12 +180,12 @@
                <tr class="top">
                        <td class="lbl" rowspan="2">Label Code:</td>
                        <td class="diff" id="ov::labelcode<% $id %>">
-                               <% $prev->{'LabelCode'} %>
+                               <% 
MusicBrainz::Server::Validation::MakeDisplayLabelCode($prev->{"LabelCode"}) %>
                        </td>
                </tr>
                <tr>
                        <td class="diff" id="nv::labelcode<% $id %>">
-                               <% $new->{"LabelCode"} %>
+                               <% 
MusicBrainz::Server::Validation::MakeDisplayLabelCode($new->{"LabelCode"}) %>
                        </td>
                </tr>
 

Modified: mb_server/trunk/htdocs/edit/label/add.html
===================================================================
--- mb_server/trunk/htdocs/edit/label/add.html  2007-03-21 08:14:55 UTC (rev 
8928)
+++ mb_server/trunk/htdocs/edit/label/add.html  2007-03-21 21:47:57 UTC (rev 
8929)
@@ -123,6 +123,8 @@
                        push @messages, "Please enter the Name." if ($name eq 
"");
                        push @messages, "Please enter the Sort Name." if 
($sortname eq "");
 
+                       push @messages, "Label Code has a to be a number with 
max. 5 digits"
+                               if ($labelcode && not 
MusicBrainz::Server::Validation::IsValidLabelCode($labelcode));
                        push @messages, "Begin Date has to be either valid or 
empty"
                                if (not 
MusicBrainz::Server::Validation::IsValidDateOrEmpty($begindate_y, $begindate_m, 
$begindate_d));
                        push @messages, "End Date has to be either valid or 
empty"

Modified: mb_server/trunk/htdocs/edit/label/edit.html
===================================================================
--- mb_server/trunk/htdocs/edit/label/edit.html 2007-03-21 08:14:55 UTC (rev 
8928)
+++ mb_server/trunk/htdocs/edit/label/edit.html 2007-03-21 21:47:57 UTC (rev 
8929)
@@ -138,6 +138,8 @@
                        push @messages, "Please Select a valid type." if (not 
Label::IsValidType($type));
                        push @messages, "Please Enter the Name." if ($name eq 
"");
                        push @messages, "Please Enter the Sort Name." if 
($sortname eq "");
+                       push @messages, "Label Code has a to be a number with 
max. 5 digits"
+                               if ($labelcode && not 
MusicBrainz::Server::Validation::IsValidLabelCode($labelcode));
                        push @messages, "Begin Date has to be either valid or 
empty"
                                if (not 
MusicBrainz::Server::Validation::IsValidDateOrEmpty($begindate_y, $begindate_m, 
$begindate_d));
                        push @messages, "Begin Date has to be either valid or 
empty"


<Prev in Thread] Current Thread [Next in Thread>