head	1.17;
access;
symbols
	TIGRIS_NOV_12_2000:1.16
	OLDHELM:1.16.0.2
	TIGRIS_NOV_11_2000:1.16
	TIGRIS_SEP_13_2000:1.3.0.2
	TIGRIS_BASELINE:1.14;
locks; strict;
comment	@# @;


1.17
date	2000.11.14.02.25.03;	author kmaples;	state dead;
branches;
next	1.16;

1.16
date	2000.10.05.18.50.02;	author kmaples;	state Exp;
branches;
next	1.15;

1.15
date	2000.09.27.19.00.58;	author kmaples;	state Exp;
branches;
next	1.14;

1.14
date	2000.09.27.00.27.19;	author kmaples;	state Exp;
branches;
next	1.13;

1.13
date	2000.09.26.05.51.17;	author kmaples;	state Exp;
branches;
next	1.12;

1.12
date	2000.09.25.23.33.49;	author kmaples;	state Exp;
branches;
next	1.11;

1.11
date	2000.09.21.19.29.10;	author kmaples;	state Exp;
branches;
next	1.10;

1.10
date	2000.09.21.18.44.20;	author kmaples;	state Exp;
branches;
next	1.9;

1.9
date	2000.09.21.17.15.23;	author kmaples;	state Exp;
branches;
next	1.8;

1.8
date	2000.09.20.22.59.21;	author kmaples;	state Exp;
branches;
next	1.7;

1.7
date	2000.09.18.23.49.09;	author kmaples;	state Exp;
branches;
next	1.6;

1.6
date	2000.09.18.21.47.54;	author kmaples;	state Exp;
branches;
next	1.5;

1.5
date	2000.09.15.03.51.10;	author kmaples;	state Exp;
branches;
next	1.4;

1.4
date	2000.09.13.22.33.46;	author kmaples;	state Exp;
branches;
next	1.3;

1.3
date	2000.09.12.16.28.06;	author kmaples;	state Exp;
branches;
next	1.2;

1.2
date	2000.05.17.00.02.17;	author manoj;	state dead;
branches;
next	1.1;

1.1
date	2000.04.29.00.04.10;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.17
log
@Changed the way that child scripts are called in order to return the number
or the (child) script which failed (if any).  Currently returns 0 or the
number of the first script in the sequence to fail.  Removed leftovers from
merge.
@
text
@#!/usr/bin/perl

# ================================================================
# Copyright (c) 2000 Collab.Net.  All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement: "This product includes
# software developed by Collab.Net (http://www.Collab.Net/)."
# Alternately, this acknowlegement may appear in the software itself, if
# and wherever such third-party acknowlegements normally appear.
# 
# 4. The hosted project names must not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact info@@collab.net.
# 
# 5. Products derived from this software may not use the "Tigris" name
# nor may "Tigris" appear in their names without prior written
# permission of Collab.Net.
# 
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
# 
# This software consists of voluntary contributions made by many
# individuals on behalf of Collab.Net.
#


# 
# $Id: bugzilla-module-add,v 1.16 2000/10/05 18:50:02 kmaples Exp $
# --------------------
# 

# Flush buffer, just in case:
$| = 1;

use strict;
use DBI;
# For the sake of -T:
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin";
# Detaint the args by brute force:
@@ARGV = detaint_array(@@ARGV);

# Process arguments
my $sandbox            = $ARGV[0] || '';
my $project_name       = $ARGV[1] || '';
my $domain_name        = $ARGV[2] || '';
my $module_name        = $ARGV[3] || '';
my $module_description = $ARGV[4] || 'none';

# Some email address for bugzilla:
my $init_owner = "$project_name-bugs\@@$domain_name";
my $init_qa    = $init_owner;

# NOTE - this script requires the info necessary to connect
# to the correct DB, e.g., username/password, DB name, etc.

my $dbname         = $ENV{DATABASE_NAME}     || '';
my $dbuser         = $ENV{DATABASE_USER}     || '';
my $dbpass         = $ENV{DATABASE_PASSWORD} || '';


# Grab just the filename portion of this script to use as a 
# log identifier:
my $script_name = $0;
$script_name =~ s/^.*\/([^\/]+)$/  $1/;

# String for current sql statement
my $command;

# Placeholder vars for db work:
my ($select, $ret);

#---------------------------------------------------------------
# MAIN
#---------------------------------------------------------------

# Fail if we don't have what we need to talk to the database:
unless($dbname && $dbuser && $dbpass){
    print "$script_name: envrionmentals for DB access not set\n";
    exit(1);
}

my $dbc = "DBI:mysql:$dbname";
my $CONN = DBI->connect($dbc, $dbuser, $dbpass);

# Check for a good connection:
unless( $CONN =~ m/HASH/){
    print "$script_name: no connection to database: $!\n";
    exit(1);
}

# Do the sql quoting for the values we're gonna play with:
foreach($project_name, $module_name, $module_description, $init_owner, $init_qa){
    $_ = $CONN->quote( $_ );
}

# Check to see if there's already a record, and if so, return
# successful:

print "$script_name: checking for previous record\n";

$command = qq[
    SELECT * FROM components WHERE 
    value   = $module_name AND
    program = $project_name
    LIMIT 1
];

$select = $CONN->prepare($command);
$ret    = $select->execute;

if($ret && $ret ne '0E0'){
    print "$script_name: record found\n";
    $select->finish();
    $CONN->disconnect;
    exit(0);
}

# Now prepare the actual insert:
print "$script_name: doing mysql insert\n";
$command = qq[
    INSERT INTO components SET
        value        =  $module_name, 
	program      =  $project_name,
	initialowner =  $init_owner, 
	initialqacontact = $init_qa,
    	description  =  $module_description
];

$select = $CONN->prepare($command);
$ret    = $select->execute;

$CONN->disconnect;

unless($ret){
    print "$script_name: unable to perform insert: $!\n";
    exit(1);
}
#---------------------------------------------------------------
# END MAIN
#---------------------------------------------------------------


# A crude attempt to overcome data tainting in perl:
#-------------------
sub detaint_array {
#-------------------
    my @@unclean = @@_;
    my @@clean = ();

    foreach(@@unclean){
        # We don't really have rules for this, so at the moment
        # this acts as a passthrough:
        $_ =~ m/^(.*)$/;
        push(@@clean,$1);
    }

    return(@@clean);
}

@


1.16
log
@Because last week I was an idiot who didn't understand sql ... not much has
changed, but this week I realized things didn't need to be as hard as I was
making them.  All better now.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.15 2000/09/27 19:00:58 kmaples Exp $
@


1.15
log
@Because sometimes your hack isn't as clever as you thought it was ... changed
the way in which the number of columns in each table is determined before
inserts are performed so that it does it the hard way - selects the table
description, then iterates over the rows in the description.  Reliable, but
ugly; this addresses problems that would occur if the schema had been changed
and there was no previously existing data in the table.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.14 2000/09/27 00:27:19 kmaples Exp $
a93 1
my $components_index = 0;
a118 11
# Get a column count:  We know that the bugzilla schema may
# change out from under us, so we want to start out by finding 
# how many columns the table has:

# Components:
$command = qq[show columns from components];
$select = $CONN->prepare($command);
$ret    = $select->execute;
while(my (@@foo) = $select->fetchrow_array){ $components_index++; }


d144 6
a149 3
    INSERT INTO components VALUES ($module_name, $project_name,
    $init_owner, $init_qa,
    $module_description
a150 9

# Oohh, this is a hack.  We currently know of 5 columns, but
# this is for bugzilla 2.6 - and we know that there are more 
# cols. in later versions, so:
for(1 .. ($components_index - 5)){
    $command .= q[,''];
}
$command .= ')';

@


1.14
log
@Added tests for number of columns before performing inserts, and padding out
the insert to match that number.  This is to avoid a potential problem in
upgrading to newer versions of bugzilla where the schema has been changed,
which meant that inserts of fixed-length would have choked.  Fixed a bug in
bugzilla-module-delete which was preventing some deletes from occuring.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.13 2000/09/26 05:51:17 kmaples Exp $
d94 1
a94 1
my $components_index;
d120 11
a144 2
# Check the row count:
$components_index = $#{ [$select->fetchrow_array] };
d164 1
a164 1
for(0 .. ($components_index - 5)){
@


1.13
log
@Rewrote bugzilla-project-add to use DBI; misc. bugfixes around conversion
to DBI in related scripts.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.12 2000/09/25 23:33:49 kmaples Exp $
d94 1
d129 1
d134 2
d149 1
a149 1
    $module_description)
d151 9
@


1.12
log
@Reworked using DBI; now checks for previous record before performing insert,
corrected fields being inserted.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.11 2000/09/21 19:29:10 kmaples Exp $
d133 1
a133 1
if($ret){
d144 2
a145 2
    $project_name-bugs\@@$domain_name, $project_name-bugs\@@$domain_name,
    $module_description);
@


1.11
log
@Added print statements for log files
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.10 2000/09/21 18:44:20 kmaples Exp $
d59 1
a59 1

d72 4
d89 6
d105 12
a116 8
# Ultimately, this command is going to be wrapped in double-quotes 
# as it's passed on the command line, so we need to escape both
# types of quotes - the first to appease mysql, the second to 
# prevent premature termination of the command:

foreach($project_name, $domain_name, $module_name, $module_description){
    $_ =~ s/'/\\'/g;
    $_ =~ s/"/\\"/g;
d119 9
a127 5
# Don't use double-quotes when building the command string:
my $command = qq[
	INSERT INTO components VALUES ('$module_name', '$module_name',
	'$project_name-bugs\@@$domain_name','$project_name-bugs\@@$domain_name',
	'$module_description');
d130 2
a131 2
# compress whitespace:
$command =~ s/\s+/ /g;
d133 6
a138 6
# This approach is abandoned in favor of the safer use of 'system':
#
# my $string = qq[mysql -u$dbuser -p$dbpass $dbname -e "$command"];
#
# system($string) == 0 
#	or die "$script_name: Unable to execute mysql command: $!\n";
d140 7
a146 1
my $mysql_bin = `which mysql`; chomp $mysql_bin;
d148 2
a149 1
print "$script_name: doing mysql insert\n";
d151 1
a151 2
system($mysql_bin,"-u$dbuser","-p$dbpass","$dbname",'-e',$command) == 0
    or die "$script_name: Unable to execute mysql command: $!\n";
d153 4
@


1.10
log
@Changed the way that quoting was approached in building mysql insert; changed
the actual call to use the safer form of 'system()'
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.9 2000/09/21 17:15:23 kmaples Exp $
d123 2
@


1.9
log
@Escaped '@@' in string to prevent interpretation as array ref.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.8 2000/09/20 22:59:21 kmaples Exp $
d95 10
d115 6
a120 4
# escape double-quotes:
$command =~ s/"/\\"/g;

my $string = qq[mysql -u$dbuser -p$dbpass $dbname -e "$command"];
d122 1
a122 2
system($string) == 0 
	or die "$script_name: Unable to execute mysql command: $!\n";
d124 2
@


1.8
log
@Modifications to get info for database access via environmentals; amended
the @@ARGV list to include a 'bugs_password' to be passed in.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.7 2000/09/18 23:49:09 kmaples Exp $
d98 1
a98 1
	'$project_name-bugs@@$domain_name','$project_name-bugs@@$domain_name',
@


1.7
log
@Converted pseudocode to mysql command.  Both of these are currently 'short-
circuited' while under development - they both exit before any real code would
be executed.  They're also blunt instruments - at the moment, they just
put together a sql statment to pass to mysql on the command line (it isn't
yet clear if it's worth going to the trouble of loading DBI and establishing
a real connection to the database, considering that neither script executes
more than three statements - all inserts).
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.6 2000/09/18 21:47:54 kmaples Exp $
d72 1
a72 1
# NOTE - this script still requires the info necessary to connect to
d75 3
a77 3
my $dbname         = '';
my $dbuser         = '';
my $dbpass         = '';
d89 5
a93 3
# short-circuit while under development:
exit;

@


1.6
log
@Preparatory work for bugzilla components
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.5 2000/09/15 03:51:10 kmaples Exp $
d75 5
d89 21
a109 5
# Rough mysql instructions:
# 
# INSERT INTO components VALUES ("$modulename", "$modulename",
# "$projectname-bugs@@$domain","$projectname-bugs@@$domain",
# "$moduledescription");
@


1.5
log
@Fixed regex to display script name in logfiles.
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.4 2000/09/13 22:33:46 kmaples Exp $
d66 8
d84 5
@


1.4
log
@Added crude subroutine to all child scripts to detaint @@ARGV.  At the moment,
this isn't doing any real detainting - just spitting the args back out to get
around warnings setuid generates.  Complications with the scripts' knowledge
of it's own working dir when it's called prevent the effective use of 'require'
in the child scripts, thus the redundancy of code in the children (for the time
being)
@
text
@d51 1
a51 1
# $Id: bugzilla-module-add,v 1.3 2000/09/12 16:28:06 kmaples Exp $
d70 1
a70 1
$script_name =~ s/^.*\/([\w]+)$/$1/;
@


1.3
log
@Stubs for bugzilla-related functions
@
text
@d51 1
a51 1
# $Id: $
d60 5
d83 16
@


1.2
log
@These functions will be performed by the servlets.
@
text
@d1 1
a1 1
#!/usr/bin/perl -w
d50 2
a51 2
# bugzilla-module-add
# $Id: bugzilla-module-add,v 1.1 2000/04/29 00:04:10 jrobbins Exp $
d53 4
a56 1
# Provide functions related to configuring the bugzilla bug tracking tool
d60 10
a70 8
# Process arguments
my $sandbox      = $ARGV[0];
my $project_name       = $ARGV[1];
my $domain_name        = $ARGV[2];
my $brand_name         = $ARGV[3];
my $module_name        = $ARGV[4];
my $module_description = $ARGV[5];
my $is_web             = $ARGV[6];
d73 3
a75 2
print "bugzilla: Add component named: " . $module_name . "\n";
print "          to product: " . $project_name . "\n";
@


1.1
log
@initial checkin
@
text
@d51 1
a51 1
# $Id: bugzilla.pm,v 1.1 2000/03/24 20:33:58 jrobbins Exp $
@

