]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 347290: Move default product and classification creation into Bugzilla::Install
authormkanat%bugzilla.org <>
Fri, 4 Aug 2006 11:04:25 +0000 (11:04 +0000)
committermkanat%bugzilla.org <>
Fri, 4 Aug 2006 11:04:25 +0000 (11:04 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=justdave

Bugzilla/DB/Schema.pm
Bugzilla/Install.pm
Bugzilla/Install/DB.pm
checksetup.pl

index 9f46708455b6a8bf3777f81c00e026436eb30150..088a70a7856be1517d05ca63eac7e93d227bf46f 100644 (file)
@@ -874,12 +874,16 @@ use constant ABSTRACT_SCHEMA => {
             classification_id => {TYPE => 'INT2', NOTNULL => 1,
                                   DEFAULT => '1'},
             description       => {TYPE => 'MEDIUMTEXT'},
-            milestoneurl      => {TYPE => 'TINYTEXT', NOTNULL => 1},
-            disallownew       => {TYPE => 'BOOLEAN', NOTNULL => 1},
-            votesperuser      => {TYPE => 'INT2', NOTNULL => 1},
+            milestoneurl      => {TYPE => 'TINYTEXT', NOTNULL => 1,
+                                  DEFAULT => "''"},
+            disallownew       => {TYPE => 'BOOLEAN', NOTNULL => 1,
+                                  DEFAULT => 0},
+            votesperuser      => {TYPE => 'INT2', NOTNULL => 1,
+                                  DEFAULT => 0},
             maxvotesperbug    => {TYPE => 'INT2', NOTNULL => 1,
                                   DEFAULT => '10000'},
-            votestoconfirm    => {TYPE => 'INT2', NOTNULL => 1},
+            votestoconfirm    => {TYPE => 'INT2', NOTNULL => 1,
+                                  DEFAULT => 0},
             defaultmilestone  => {TYPE => 'varchar(20)',
                                   NOTNULL => 1, DEFAULT => "'---'"},
         ],
index 4e94fa4a4856084e2dfb27153b3846db259a47da..f35292ed9fa817b6f94910f25c6f6835fc44b248 100644 (file)
@@ -26,7 +26,10 @@ package Bugzilla::Install;
 
 use strict;
 
+use Bugzilla::Group;
+use Bugzilla::Product;
 use Bugzilla::User::Setting;
+use Bugzilla::Version;
 
 use constant SETTINGS => {
     # 2005-03-03 travis@sedsystems.ca -- Bug 41972
@@ -50,6 +53,25 @@ use constant SETTINGS => {
 
 };
 
+use constant DEFAULT_CLASSIFICATION => {
+    name        => 'Unclassified',
+    description => 'Unassigned to any classification'
+};
+
+use constant DEFAULT_PRODUCT => {
+    name => 'TestProduct',
+    description => 'This is a test product.'
+        . ' This ought to be blown away and replaced with real stuff in a'
+        . ' finished installation of bugzilla.'
+};
+
+use constant DEFAULT_COMPONENT => {
+    name => 'TestComponent',
+    description => 'This is a test component in the test product database.'
+        . ' This ought to be blown away and replaced with real stuff in'
+        . ' a finished installation of Bugzilla.'
+};
+
 sub update_settings {
     my %settings = %{SETTINGS()};
     foreach my $setting (keys %settings) {
@@ -58,6 +80,58 @@ sub update_settings {
     }
 }
 
+# This function should be called only after creating the admin user.
+sub create_default_product {
+    my $dbh = Bugzilla->dbh;
+
+    # Make the default Classification if it doesn't already exist.
+    if (!$dbh->selectrow_array('SELECT 1 FROM classifications')) {
+        my $class = DEFAULT_CLASSIFICATION;
+        print "Creating default classification '$class->{name}'...\n";
+        $dbh->do('INSERT INTO classifications (name, description)
+                       VALUES (?, ?)',
+                 undef, $class->{name}, $class->{description});
+    }
+
+    # And same for the default product/component.
+    if (!$dbh->selectrow_array('SELECT 1 FROM products')) {
+        my $default_prod = DEFAULT_PRODUCT;
+        print "Creating initial dummy product '$default_prod->{name}'...\n";
+
+        $dbh->do(q{INSERT INTO products (name, description)
+                        VALUES (?,?)}, 
+                 undef, $default_prod->{name}, $default_prod->{description});
+
+        my $product = new Bugzilla::Product({name => $default_prod->{name}});
+
+        # The default version.
+        Bugzilla::Version::create(Bugzilla::Version::DEFAULT_VERSION, $product);
+
+        # And we automatically insert the default milestone.
+        $dbh->do(q{INSERT INTO milestones (product_id, value, sortkey)
+                        SELECT id, defaultmilestone, 0
+                          FROM products});
+
+        # Get the user who will be the owner of the Product.
+        # We pick the admin with the lowest id, or we insert
+        # an invalid "0" into the database, just so that we can
+        # create the component.
+        my $admin_group = new Bugzilla::Group({name => 'admin'});
+        my ($admin_id)  = $dbh->selectrow_array(
+            'SELECT user_id FROM user_group_map WHERE group_id = ?
+           ORDER BY user_id ' . $dbh->sql_limit(1),
+            undef, $admin_group->id) || 0;
+        my $default_comp = DEFAULT_COMPONENT;
+
+        $dbh->do("INSERT INTO components (name, product_id, description,
+                                          initialowner)
+                       VALUES (?, ?, ?, ?)", undef, $default_comp->{name},
+                 $product->id, $default_comp->{description}, $admin_id);
+    }
+
+}
+
 1;
 
 __END__
@@ -100,4 +174,13 @@ Params:      none
 
 Returns:     nothing.
 
+=item C<create_default_product()>
+
+Description: Creates the default product and classification if
+             they don't exist.
+
+Params:      none
+
+Returns:     nothing
+
 =back
index 46e9b5c5a7462c30de621e78aec4847bd3a79bc5..9b29bbc76079fa45e3e82c884f5f827c0e8edd64 100644 (file)
@@ -449,6 +449,16 @@ sub update_table_definitions {
 
     _add_classifications_sortkey();
     _move_data_nomail_into_db();
+
+    # The products table lacked sensible defaults.
+    $dbh->bz_alter_column('products', 'milestoneurl',
+                          {TYPE => 'TINYTEXT', NOTNULL => 1, DEFAULT => "''"});
+    $dbh->bz_alter_column('products', 'disallownew',
+                          {TYPE => 'BOOLEAN', NOTNULL => 1,  DEFAULT => 0});
+    $dbh->bz_alter_column('products', 'votesperuser', 
+                          {TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
+    $dbh->bz_alter_column('products', 'votestoconfirm',
+                          {TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
     
     ################################################################
     # New --TABLE-- changes should go *** A B O V E *** this point #
@@ -1194,9 +1204,10 @@ sub _use_ids_for_products_and_components {
             $dbh->do("UPDATE attachstatusdefs SET product_id = $product_id " .
                      "WHERE product = " . $dbh->quote($product))
                 if $dbh->bz_table_info("attachstatusdefs");
-            }
+        }
+
+        print "Updating the database to use component IDs.\n";
 
-            print "Updating the database to use component IDs.\n";
         $dbh->bz_add_column("components", "id",
             {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
         $dbh->bz_add_column("bugs", "component_id",
index ed670a271d6ac208723b8fe59d9dc62914fa1a90..4dad00ecd0cb66acf2140fe6c7b4058077691a7f 100755 (executable)
@@ -466,53 +466,6 @@ Bugzilla::Install::DB::update_fielddefs_definition();
 
 Bugzilla::Field::populate_field_definitions();
 
-###########################################################################
-# Create initial test product if there are no products present.
-###########################################################################
-my $sth = $dbh->prepare("SELECT description FROM products");
-$sth->execute;
-unless ($sth->rows) {
-    print "Creating initial dummy product 'TestProduct' ...\n";
-    my $test_product_name = 'TestProduct';
-    my $test_product_desc = 
-        'This is a test product. This ought to be blown away and'
-        . ' replaced with real stuff in a finished installation of bugzilla.';
-    my $test_product_version = 'other';
-
-    $dbh->do(q{INSERT INTO products(name, description, milestoneurl, 
-                           disallownew, votesperuser, votestoconfirm)
-               VALUES (?, ?, '', ?, ?, ?)},
-               undef, $test_product_name, $test_product_desc, 0, 0, 0);
-
-    # We could probably just assume that this is "1", but better
-    # safe than sorry...
-    my $product_id = $dbh->bz_last_key('products', 'id');
-    
-    $dbh->do(q{INSERT INTO versions (value, product_id) 
-                VALUES (?, ?)}, 
-             undef, $test_product_version, $product_id);
-    # note: since admin user is not yet known, components gets a 0 for 
-    # initialowner and this is fixed during final checks.
-    $dbh->do("INSERT INTO components (name, product_id, description, " .
-                                     "initialowner) " .
-             "VALUES (" .
-             "'TestComponent', $product_id, " .
-             "'This is a test component in the test product database.  " .
-             "This ought to be blown away and replaced with real stuff in " .
-             "a finished installation of Bugzilla.', 0)");
-    $dbh->do(q{INSERT INTO milestones (product_id, value, sortkey) 
-               VALUES (?,?,?)},
-             undef, $product_id, '---', 0);
-}
-
-# Create a default classification if one does not exist
-my $class_count =
-    $dbh->selectrow_array("SELECT COUNT(*) FROM classifications");
-if (!$class_count) {
-    $dbh->do("INSERT INTO classifications (name,description) " .
-             "VALUES('Unclassified','Unassigned to any classifications')");
-}
-
 ###########################################################################
 # Update the tables to the current definition --TABLE--
 ###########################################################################
@@ -576,7 +529,7 @@ use constant GRANT_DERIVED => 1;
 # Get rid of leftover DERIVED group permissions
 $dbh->do("DELETE FROM user_group_map WHERE grant_type = " . GRANT_DERIVED);
 # Evaluate regexp-based group memberships
-$sth = $dbh->prepare("SELECT profiles.userid, profiles.login_name,
+my $sth = $dbh->prepare("SELECT profiles.userid, profiles.login_name,
                          groups.id, groups.userregexp,
                          user_group_map.group_id
                          FROM (profiles
@@ -845,9 +798,15 @@ if ($sth->rows == 0) {
     print "\n$login is now set up as an administrator account.\n";
 }
 
+###########################################################################
+# Create default Product and Classification
+###########################################################################
 
-#
-# Final checks...
+Bugzilla::Install::create_default_product();
+
+###########################################################################
+# Final checks
+###########################################################################
 
 $sth = $dbh->prepare("SELECT user_id " .
                        "FROM groups INNER JOIN user_group_map " .
@@ -856,10 +815,6 @@ $sth = $dbh->prepare("SELECT user_id " .
 $sth->execute;
 my ($adminuid) = $sth->fetchrow_array;
 if (!$adminuid) { die "No administrator!" } # should never get here
-# when test product was created, admin was unknown
-$dbh->do("UPDATE components " .
-            "SET initialowner = $adminuid " .
-          "WHERE initialowner = 0");
 
 # Check if the default parameter for urlbase is still set, and if so, give
 # notification that they should go and visit editparams.cgi