Commit ab199bf5 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 286294: cleanup editclassifications.cgi and migrate the existent code to use…

Bug 286294: cleanup editclassifications.cgi and migrate the existent code to use Classification.pm - Patch by Tiago R. Mello <timello@gmail.com> r=LpSolit a=myk
parent 966c2621
...@@ -21,6 +21,7 @@ package Bugzilla::Classification; ...@@ -21,6 +21,7 @@ package Bugzilla::Classification;
use Bugzilla; use Bugzilla;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error;
############################### ###############################
#### Initialization #### #### Initialization ####
...@@ -87,7 +88,7 @@ sub product_count { ...@@ -87,7 +88,7 @@ sub product_count {
if (!defined $self->{'product_count'}) { if (!defined $self->{'product_count'}) {
$self->{'product_count'} = $dbh->selectrow_array(q{ $self->{'product_count'} = $dbh->selectrow_array(q{
SELECT COUNT(*) FROM products SELECT COUNT(*) FROM products
WHERE classification_id = ?}, undef, $self->id); WHERE classification_id = ?}, undef, $self->id) || 0;
} }
return $self->{'product_count'}; return $self->{'product_count'};
} }
...@@ -108,13 +109,31 @@ sub get_all_classifications () { ...@@ -108,13 +109,31 @@ sub get_all_classifications () {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $ids = $dbh->selectcol_arrayref(q{ my $ids = $dbh->selectcol_arrayref(q{
SELECT id FROM classifications}); SELECT id FROM classifications ORDER BY name});
my $classifications; my @classifications;
foreach my $id (@$ids) { foreach my $id (@$ids) {
$classifications->{$id} = new Bugzilla::Classification($id); push @classifications, new Bugzilla::Classification($id);
} }
return $classifications; return @classifications;
}
sub check_classification ($) {
my ($class_name) = @_;
unless ($class_name) {
ThrowUserError("classification_not_specified");
}
my $classification =
new Bugzilla::Classification({name => $class_name});
unless ($classification) {
ThrowUserError("classification_doesnt_exist",
{ name => $class_name });
}
return $classification;
} }
1; 1;
...@@ -140,11 +159,14 @@ Bugzilla::Classification - Bugzilla classification class. ...@@ -140,11 +159,14 @@ Bugzilla::Classification - Bugzilla classification class.
my $hash_ref = Bugzilla::Classification::get_all_classifications(); my $hash_ref = Bugzilla::Classification::get_all_classifications();
my $classification = $hash_ref->{1}; my $classification = $hash_ref->{1};
my $classification =
Bugzilla::Classification::check_classification('AcmeClass');
=head1 DESCRIPTION =head1 DESCRIPTION
Classification.pm represents a Classification object. Classification.pm represents a Classification object.
A Classification is a higher-level grouping of Bugzilla Products. A Classification is a higher-level grouping of Products.
=head1 METHODS =head1 METHODS
...@@ -181,12 +203,20 @@ A Classification is a higher-level grouping of Bugzilla Products. ...@@ -181,12 +203,20 @@ A Classification is a higher-level grouping of Bugzilla Products.
=item C<get_all_classifications()> =item C<get_all_classifications()>
Description: Returns all Bugzilla classifications. Description: Returns all classifications.
Params: none. Params: none.
Returns: A hash with classification id as key and Returns: Bugzilla::Classification object list.
Bugzilla::Classification object as value.
=item C<check_classification($classification_name)>
Description: Checks if the classification name passed in is a
valid classification.
Params: $classification_name - String with a classification name.
Returns: Bugzilla::Classification object.
=back =back
......
...@@ -196,13 +196,13 @@ sub get_products_by_classification ($) { ...@@ -196,13 +196,13 @@ sub get_products_by_classification ($) {
my $ids = $dbh->selectcol_arrayref(q{ my $ids = $dbh->selectcol_arrayref(q{
SELECT id FROM products SELECT id FROM products
WHERE classification_id = ?}, undef, $class_id); WHERE classification_id = ? ORDER by name}, undef, $class_id);
my $products; my @products;
foreach my $id (@$ids) { foreach my $id (@$ids) {
$products->{$id} = new Bugzilla::Product($id); push @products, new Bugzilla::Product($id);
} }
return $products; return @products;
} }
sub get_all_products () { sub get_all_products () {
...@@ -265,8 +265,7 @@ Bugzilla::Product - Bugzilla product class. ...@@ -265,8 +265,7 @@ Bugzilla::Product - Bugzilla product class.
my $defaultmilestone = $product->default_milestone; my $defaultmilestone = $product->default_milestone;
my $classificationid = $product->classification_id; my $classificationid = $product->classification_id;
my $hash_ref = Bugzilla::Product::get_products_by_classification(1); my @products = Bugzilla::Product::get_products_by_classification(1);
my $product = $hash_ref->{1};
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -355,8 +354,7 @@ Product.pm represents a product object. ...@@ -355,8 +354,7 @@ Product.pm represents a product object.
Params: $class_id - Integer with classification id. Params: $class_id - Integer with classification id.
Returns: A hash with product id as key and a Bugzilla::Product Returns: Bugzilla::Product object list.
object as value.
=item C<get_all_products()> =item C<get_all_products()>
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
</table> </table>
<input type=hidden name="classificationold" value="[% classification FILTER html %]"> <input type=hidden name="classificationold" value="[% classification FILTER html %]">
<input type=hidden name="descriptionold" value="[% description FILTER html %]">
<input type=hidden name="action" value="update"> <input type=hidden name="action" value="update">
<input type=submit value="Update"> <input type=submit value="Update">
</form> </form>
......
...@@ -51,9 +51,9 @@ ...@@ -51,9 +51,9 @@
<td></td> <td></td>
<td valign="top"> <td valign="top">
<select name="prodlist" id="prodlist" multiple="multiple" size="20"> <select name="prodlist" id="prodlist" multiple="multiple" size="20">
[% FOREACH cl = class_products %] [% FOREACH product = unselected_products %]
<option value="[% cl.value FILTER html %]"> <option value="[% product.name FILTER html %]">
[% cl.name FILTER html %] [[% product.classification.name FILTER html %]]&nbsp;[% product.name FILTER html %]
</option> </option>
[% END %] [% END %]
</select></td> </select></td>
...@@ -66,8 +66,8 @@ ...@@ -66,8 +66,8 @@
<td valign="middle" rowspan=2> <td valign="middle" rowspan=2>
<select name="myprodlist" id="myprodlist" multiple="multiple" size="20"> <select name="myprodlist" id="myprodlist" multiple="multiple" size="20">
[% FOREACH product = selected_products %] [% FOREACH product = selected_products %]
<option value="[% product FILTER html %]"> <option value="[% product.name FILTER html %]">
[% product FILTER html %] [% product.name FILTER html %]
</option> </option>
[% END %] [% END %]
</select></td> </select></td>
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
title = "Select classification" title = "Select classification"
%] %]
[% filt_classification = classification FILTER html %]
<table border=1 cellpadding=4 cellspacing=0> <table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor="#6666ff"> <tr bgcolor="#6666ff">
<th align="left">Edit Classification ...</th> <th align="left">Edit Classification ...</th>
...@@ -35,7 +33,7 @@ ...@@ -35,7 +33,7 @@
[% FOREACH cl = classifications %] [% FOREACH cl = classifications %]
<tr> <tr>
<td valign="top"><a href="editclassifications.cgi?action=edit&amp;classification=[% cl.classification FILTER url_quote %]"><b>[% cl.classification FILTER html %]</b></a></td> <td valign="top"><a href="editclassifications.cgi?action=edit&amp;classification=[% cl.name FILTER url_quote %]"><b>[% cl.name FILTER html %]</b></a></td>
<td valign="top"> <td valign="top">
[% IF cl.description %] [% IF cl.description %]
[% cl.description %] [% cl.description %]
...@@ -44,16 +42,16 @@ ...@@ -44,16 +42,16 @@
[% END %] [% END %]
</td> </td>
[% IF (cl.id == 1) %] [% IF (cl.id == 1) %]
<td valign="top">[% cl.total FILTER html %]</td> <td valign="top">[% cl.product_count FILTER html %]</td>
[% ELSE %] [% ELSE %]
<td valign="top"><a href="editclassifications.cgi?action=reclassify&amp;classification=[% cl.classification FILTER url_quote %]">reclassify ([% cl.total FILTER html %])</a></td> <td valign="top"><a href="editclassifications.cgi?action=reclassify&amp;classification=[% cl.name FILTER url_quote %]">reclassify ([% cl.product_count FILTER html %])</a></td>
[% END %] [% END %]
[%# don't allow user to delete the default id. %] [%# don't allow user to delete the default id. %]
[% IF (cl.id == 1) %] [% IF (cl.id == 1) %]
<td valign="top">&nbsp;</td> <td valign="top">&nbsp;</td>
[% ELSE %] [% ELSE %]
<td valign="top"><a href="editclassifications.cgi?action=del&amp;classification=[% cl.classification FILTER url_quote %]">delete</a></td> <td valign="top"><a href="editclassifications.cgi?action=del&amp;classification=[% cl.name FILTER url_quote %]">delete</a></td>
[% END %] [% END %]
</tr> </tr>
[% END %] [% END %]
......
...@@ -248,10 +248,6 @@ ...@@ -248,10 +248,6 @@
must reassign those products to another classification before you must reassign those products to another classification before you
can delete this one. can delete this one.
[% ELSIF error == "cant_delete_default_classification" %]
Sorry, but you can not delete the default classification,
'[% name FILTER html %]'.
[% ELSIF error == "component_already_exists" %] [% ELSIF error == "component_already_exists" %]
[% title = "Component Already Exists" %] [% title = "Component Already Exists" %]
A component with the name '[% name FILTER html %]' already exists. A component with the name '[% name FILTER html %]' already exists.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment