--- lib/TWiki/Plugins/BugzillaQueryPlugin.pm Tue Feb 7 11:16:04 2006 +++ ../BugzillaQueryPlugin-0_02/lib/TWiki/Plugins/BugzillaQueryPlugin.pm Tue Feb 7 12:28:00 2006 @@ -51,6 +51,7 @@ package TWiki::Plugins::BugzillaQueryPlugin; # change the package name and $pluginName!!! use DBI; +use Text::Wrap; # ========================= use vars qw( $web $topic $user $installWeb $VERSION $pluginName @@ -348,21 +349,33 @@ while ( my $row = $tmp->fetchrow_hashref ) { my $s = $format; foreach my $field ( keys( %{$row} ) ) { + # PARSE 'format' FIELD + $s =~ s/\$n/\n/g; + $s =~ s/\$q/\"/g; + $s =~ s/\$percent/\%/g; my $value = $$row{$field}; ( $value, $field ) = getField( "name", "products", "id", $$row{$field}, "product" ) if ( $field eq "product_id" ); ( $value, $field ) = getField( "name", "components", "id", $$row{$field}, "component" ) if ( $field eq "component_id" ); - ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "qa_contact" ) if ( $field eq "qa_contact" ); - ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "reporter" ) if ( $field eq "reporter" ); - ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "assigned_to" ) if ( $field eq "assigned_to" ); - $s =~ s/\$bug_id/$value<\/a>/g if ( $field eq "bug_id" ); +# ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "qa_contact" ) if ( $field eq "qa_contact" ); +# ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "reporter" ) if ( $field eq "reporter" ); +# ( $value, $field ) = getField( "login_name", "profiles", "userid", $$row{$field}, "assigned_to" ) if ( $field eq "assigned_to" ); + ( $value, $field ) = getField( "realname", "profiles", "userid", $$row{$field}, "qa_contact" ) if ( $field eq "qa_contact" ); + ( $value, $field ) = getField( "realname", "profiles", "userid", $$row{$field}, "reporter" ) if ( $field eq "reporter" ); + ( $value, $field ) = getField( "realname", "profiles", "userid", $$row{$field}, "assigned_to" ) if ( $field eq "assigned_to" ); + $value =~ s/^([0-9]{4}.[0-9]{2}.[0-9]{2}).+/$1/g if $field eq "deadline"; + $s =~ s/\$bug_id/$value<\/a>/g if $field eq "bug_id"; + $s =~ s/\$bug_href/$url\/$showBugScript?id=$value/g if $field eq "bug_id"; + ( $value, $field ) = getLongDesc( $$row{$field}, "longdesc") if $field eq "bug_id"; $s =~ s/\$$field/$value/g; } $result .= "$s\n"; } $db->disconnect; return $result; + # EARLY EXIT } else { + # NOT DATAVIEW if ( defined( $params{'bug_id'} ) ) { @tmp = makeArray( $params{'bug_id'} ); if ( $#tmp < 1 ) { @@ -400,6 +413,53 @@ return ( $row[0], $key ); } +sub wrap_comment ($) { + my ($comment) = @_; + my $wrappedcomment = ""; + + # Use 'local', as recommended by Text::Wrap's perldoc. + local $Text::Wrap::columns = 80; + # Make words that are longer than COMMENT_COLS not wrap. + local $Text::Wrap::huge = 'overflow'; + # Don't mess with tabs. + local $Text::Wrap::unexpand = 0; + + # If the line starts with ">", don't wrap it. Otherwise, wrap. + foreach my $line (split(/\r\n|\r|\n/, $comment)) { + if ($line =~ qr/^>/) { + $wrappedcomment .= ($line . "\n"); + } + else { + $wrappedcomment .= (wrap('', '', $line) . "\n"); + } + } + + return $wrappedcomment; +} + +sub getLongDesc { + my ( $value, $key ) = @_; + my $fulltext = ""; + $db = openDB(); + my $statement = "SELECT * FROM longdescs WHERE bug_id = '$value' ORDER BY `bug_when` ASC"; + my $tmp = $db->prepare( $statement ); + $tmp->execute(); + + while (my $row = $tmp->fetchrow_hashref ) { + my ($commentee, undef) = getField( "realname", "profiles", "userid", $$row{"who"}, undef); + $fulltext .= qq(*$$row{bug_when}* _Comment from ${commentee}_\n); + $fulltext .= qq(\n); + $fulltext .= ($$row{"already_wrapped"}) ? $$row{"thetext"} : wrap_comment($$row{thetext}) ; + $fulltext .= qq(\n); +# &TWiki::Func::writeDebug( "COMMENTTEXT:\n$$row{thetext}\n" ); + } + + $tmp->finish; + $db->disconnect(); +# &TWiki::Func::writeDebug( "FULLTEXT:\n$fulltext\n" ); + return("$fulltext", $key); +} + sub openDB { my $host = "";