From f71149e1af4ac0b03678fc80da73a7cdc352c3aa Mon Sep 17 00:00:00 2001 From: "gerv%gerv.net" <> Date: Thu, 25 Jul 2002 06:22:55 +0000 Subject: Bug 67950 - Move the quip list into the database. Patch by davef@tetsubo.com; r=gerv, preed. --- buglist.cgi | 14 ++++----- checksetup.pl | 34 +++++++++++++++++++++ quips.cgi | 23 +++++++-------- reports.cgi | 52 ++------------------------------- template/en/default/list/list.html.tmpl | 3 +- 5 files changed, 54 insertions(+), 72 deletions(-) diff --git a/buglist.cgi b/buglist.cgi index aa9cfb7eb..7863dda3e 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -270,18 +270,14 @@ sub LookupNamedQuery { } sub GetQuip { - return if !Param('usequip'); my $quip; - # This is stupid. We really really need to move the quip list into the DB! - if (open(COMMENTS, "; - close COMMENTS; - $quip = $cdata[int(rand($#cdata + 1))]; + SendSQL("SELECT quip FROM quips ORDER BY RAND() LIMIT 1"); + + if (MoreSQLData()) { + ($quip) = FetchSQLData(); } - $quip ||= "Bugzilla would like to put a random quip here, but nobody has entered any."; return $quip; } @@ -1542,7 +1538,7 @@ if ($::FORM{'debug'}) { # the list more compact. $vars->{'splitheader'} = $::COOKIE{'SPLITHEADER'} ? 1 : 0; -$vars->{'quip'} = GetQuip() if Param('usequip'); +$vars->{'quip'} = GetQuip(); $vars->{'currenttime'} = time2str("%a %b %e %T %Z %Y", time()); # The following variables are used when the user is making changes to multiple bugs. diff --git a/checksetup.pl b/checksetup.pl index 6013bd1d5..5b504dea9 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -1589,6 +1589,12 @@ $table{tokens} = index(userid)'; +# 2002-07-19, davef@tetsubo.com, bug 67950: +# Store quips in the db. +$table{quips} = + 'quipid mediumint not null auto_increment primary key, + userid mediumint not null default 0, + quip text not null'; ########################################################################### @@ -3015,6 +3021,34 @@ if (!GetFieldDef("bugs", "alias")) { $dbh->do("ALTER TABLE bugs ADD UNIQUE (alias)"); } +# 2002-07-15 davef@tetsubo.com - bug 67950 +# Move quips to the db. +my $renamed_comments_file = 0; +if (GetFieldDef("quips", "quipid")) { + if (-s 'data/comments' && open (COMMENTS, ") { + chomp; + $dbh->do("INSERT INTO quips (quip) VALUES (" + . $dbh->quote($_) . ")"); + } + print "The data/comments file (used to store quips) has been +copied into the database, and the data/comments file +moved to data/comments.bak - you can delete this file +once you're satisfied the migration worked correctly.\n"; + close COMMENTS; + rename("data/comments", "data/comments.bak") or next; + $renamed_comments_file = 1; + } +} + +# Warn if data/comments.bak exists, as it should be deleted. +if (-s 'data/comments.bak' && !$renamed_comments_file) { + print "Please note the data/comments.bak file can be removed as it's +no longer used.\n"; +} + + # If you had to change the --TABLE-- definition in any way, then add your # differential change code *** A B O V E *** this comment. # diff --git a/quips.cgi b/quips.cgi index 7441f51fc..be773e1e1 100755 --- a/quips.cgi +++ b/quips.cgi @@ -20,6 +20,7 @@ # # Contributor(s): Owen Taylor # Gervase Markham +# David Fallon use diagnostics; use strict; @@ -34,8 +35,6 @@ use lib qw(.); require "CGI.pl"; -# Even though quips aren't (yet) in the database, we need to check -# logins for the footer ConnectToDatabase(); quietly_check_login(); @@ -43,14 +42,16 @@ my $action = $::FORM{'action'} || ""; if ($action eq "show") { # Read in the entire quip list - if (open (COMMENTS, "); - close COMMENTS; - - $vars->{'quips'} = \@quips; - $vars->{'show_quips'} = 1; + SendSQL("SELECT quip FROM quips"); + + my @quips; + while (MoreSQLData()) { + my ($quip) = FetchSQLData(); + push(@quips, $quip); } + + $vars->{'quips'} = \@quips; + $vars->{'show_quips'} = 1; } if ($action eq "add") { @@ -67,9 +68,7 @@ if ($action eq "add") { exit(); } - open(COMMENTS, ">>data/comments"); - print COMMENTS $comment . "\n"; - close(COMMENTS); + SendSQL("INSERT INTO quips (userid, quip) VALUES (". $::userid . ", " . SqlQuote($comment) . ")"); $vars->{'added_quip'} = $comment; } diff --git a/reports.cgi b/reports.cgi index 2d91ebc61..e04a9fd6d 100755 --- a/reports.cgi +++ b/reports.cgi @@ -152,7 +152,6 @@ if (! defined $FORM{'product'}) { } - ################################## # user came in with no form data # ################################## @@ -236,14 +235,6 @@ print <  Links to Bugs
 Banner
-FIN - - if (Param('usequip')) { - print " Quip
"; - } else { - print ""; - } - print < @@ -299,7 +290,6 @@ FIN my $c = 0; - my $quip = "Summary"; my $bugs_count = 0; my $bugs_new_this_week = 0; my $bugs_reopened = 0; @@ -328,19 +318,6 @@ FIN $bugs_totals{$who}{$st} ++; } - if ($FORM{'quip'}) { - if (open (COMMENTS, ") { - push @cdata, $_; - } - close COMMENTS; - if(@cdata) { - $quip = "" . $cdata[int(rand(scalar(@cdata)))] . ""; - } - } - } - ######################### # start painting report # ######################### @@ -349,7 +326,7 @@ FIN $bugs_status{'ASSIGNED'} ||= '0'; $bugs_status{'REOPENED'} ||= '0'; print <$quip +

Summary

@@ -664,7 +641,6 @@ sub bybugs { sub most_doomed_for_milestone { my $when = localtime (time); my $ms = "M" . Param("curmilestone"); - my $quip = "Summary"; print "
\n

"; if( $FORM{'product'} ne "-All-" ) { @@ -681,17 +657,6 @@ sub most_doomed_for_milestone { # start painting report # ######################### - if ($FORM{'quip'}) { - if (open (COMMENTS, ") { - push @cdata, $_; - } - close COMMENTS; - $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; - } - } - # Build up $query string my $query; $query = "select distinct assigned_to from bugs where target_milestone=\"$ms\""; @@ -786,8 +751,7 @@ FIN sub most_recently_doomed { my $when = localtime (time); my $ms = "M" . Param("curmilestone"); - my $quip = "Summary"; - + print "
\n

"; if( $FORM{'product'} ne "-All-" ) { SendSQL("SELECT defaultmilestone FROM products WHERE product = " . @@ -803,18 +767,6 @@ sub most_recently_doomed { # start painting report # ######################### - if ($FORM{'quip'}) { - if (open (COMMENTS, ") { - push @cdata, $_; - } - close COMMENTS; - $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; - } - } - - # Build up $query string my $query = "select distinct assigned_to from bugs where bugs.bug_status='NEW' and target_milestone='' and bug_severity!='enhancement' and status_whiteboard='' and (product='Browser' or product='MailNews')"; if ($FORM{'product'} ne "-All-" ) { diff --git a/template/en/default/list/list.html.tmpl b/template/en/default/list/list.html.tmpl index 8ffba004f..d89193290 100644 --- a/template/en/default/list/list.html.tmpl +++ b/template/en/default/list/list.html.tmpl @@ -44,7 +44,8 @@

[% query FILTER html %]

[% END %] - [% IF quip %] + [% IF Param('usequip') %] + [% DEFAULT quip = "Bugzilla would like to put a random quip here, but no one has entered any." %] [% quip FILTER html %] [% END %] -- cgit v1.2.3-24-g4f1b

New Bugs This Week