Commit 63dde600 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 280500: Replace "DATE_FORMAT()" with Bugzilla::DB function call

Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat, a=myk
parent 32882b6e
...@@ -67,6 +67,8 @@ sub query ...@@ -67,6 +67,8 @@ sub query
# "attachments" variable. # "attachments" variable.
my ($bugid) = @_; my ($bugid) = @_;
my $dbh = Bugzilla->dbh;
my $in_editbugs = &::UserInGroup("editbugs"); my $in_editbugs = &::UserInGroup("editbugs");
&::SendSQL("SELECT product_id &::SendSQL("SELECT product_id
FROM bugs FROM bugs
...@@ -76,9 +78,9 @@ sub query ...@@ -76,9 +78,9 @@ sub query
# Retrieve a list of attachments for this bug and write them into an array # Retrieve a list of attachments for this bug and write them into an array
# of hashes in which each hash represents a single attachment. # of hashes in which each hash represents a single attachment.
&::SendSQL(" &::SendSQL("SELECT attach_id, " .
SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'), $dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') .
mimetype, description, ispatch, isobsolete, isprivate, ", mimetype, description, ispatch, isobsolete, isprivate,
submitter_id, LENGTH(thedata) submitter_id, LENGTH(thedata)
FROM attachments WHERE bug_id = $bugid ORDER BY attach_id FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
"); ");
......
...@@ -144,18 +144,19 @@ sub initBug { ...@@ -144,18 +144,19 @@ sub initBug {
rep_platform, op_sys, bug_status, resolution, priority, rep_platform, op_sys, bug_status, resolution, priority,
bug_severity, bugs.component_id, components.name, assigned_to, bug_severity, bugs.component_id, components.name, assigned_to,
reporter, bug_file_loc, short_desc, target_milestone, reporter, bug_file_loc, short_desc, target_milestone,
qa_contact, status_whiteboard, qa_contact, status_whiteboard, " .
DATE_FORMAT(creation_ts,'%Y.%m.%d %H:%i'), $dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') . ",
delta_ts, COALESCE(SUM(votes.vote_count), 0), delta_ts, COALESCE(SUM(votes.vote_count), 0),
reporter_accessible, cclist_accessible, reporter_accessible, cclist_accessible,
estimated_time, remaining_time, DATE_FORMAT(deadline,'%Y-%m-%d') estimated_time, remaining_time, " .
from bugs left join votes using(bug_id), $dbh->sql_date_format('deadline', '%Y-%m-%d') . ",
FROM bugs LEFT JOIN votes using(bug_id),
classifications, products, components classifications, products, components
WHERE bugs.bug_id = ? WHERE bugs.bug_id = ?
AND classifications.id = products.classification_id AND classifications.id = products.classification_id
AND products.id = bugs.product_id AND products.id = bugs.product_id
AND components.id = bugs.component_id AND components.id = bugs.component_id
group by bugs.bug_id"; GROUP BY bugs.bug_id";
my $bug_sth = $dbh->prepare($query); my $bug_sth = $dbh->prepare($query);
$bug_sth->execute($bug_id); $bug_sth->execute($bug_id);
...@@ -534,11 +535,11 @@ sub GetComments { ...@@ -534,11 +535,11 @@ sub GetComments {
my @comments; my @comments;
my $sth = $dbh->prepare( my $sth = $dbh->prepare(
"SELECT profiles.realname AS name, profiles.login_name AS email, "SELECT profiles.realname AS name, profiles.login_name AS email,
date_format(longdescs.bug_when,'%Y.%m.%d %H:%i') AS time, " . $dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i') . "
longdescs.thetext AS body, longdescs.work_time, AS time, longdescs.thetext AS body, longdescs.work_time,
isprivate, already_wrapped, isprivate, already_wrapped,
date_format(longdescs.bug_when,'%Y%m%d%H%i%s') " . $dbh->sql_date_format('longdescs.bug_when', '%Y%m%d%H%i%s') . "
FROM longdescs, profiles FROM longdescs, profiles
WHERE profiles.userid = longdescs.who WHERE profiles.userid = longdescs.who
AND longdescs.bug_id = ? AND longdescs.bug_id = ?
ORDER BY longdescs.bug_when"); ORDER BY longdescs.bug_when");
......
...@@ -317,6 +317,7 @@ sub LogActivityEntry { ...@@ -317,6 +317,7 @@ sub LogActivityEntry {
sub GetBugActivity { sub GetBugActivity {
my ($id, $starttime) = (@_); my ($id, $starttime) = (@_);
my $datepart = ""; my $datepart = "";
my $dbh = Bugzilla->dbh;
die "Invalid id: $id" unless $id=~/^\s*\d+\s*$/; die "Invalid id: $id" unless $id=~/^\s*\d+\s*$/;
...@@ -333,9 +334,9 @@ sub GetBugActivity { ...@@ -333,9 +334,9 @@ sub GetBugActivity {
my $query = " my $query = "
SELECT COALESCE(fielddefs.description, bugs_activity.fieldid), SELECT COALESCE(fielddefs.description, bugs_activity.fieldid),
fielddefs.name, fielddefs.name,
bugs_activity.attach_id, bugs_activity.attach_id, " .
DATE_FORMAT(bugs_activity.bug_when,'%Y.%m.%d %H:%i:%s'), $dbh->sql_date_format('bugs_activity.bug_when', '%Y.%m.%d %H:%i:%s') .
bugs_activity.removed, bugs_activity.added, ", bugs_activity.removed, bugs_activity.added,
profiles.login_name profiles.login_name
FROM bugs_activity $suppjoins LEFT JOIN fielddefs ON FROM bugs_activity $suppjoins LEFT JOIN fielddefs ON
bugs_activity.fieldid = fielddefs.fieldid, bugs_activity.fieldid = fielddefs.fieldid,
......
...@@ -800,11 +800,14 @@ sub viewall ...@@ -800,11 +800,14 @@ sub viewall
# Retrieve the attachments from the database and write them into an array # Retrieve the attachments from the database and write them into an array
# of hashes where each hash represents one attachment. # of hashes where each hash represents one attachment.
my $privacy = ""; my $privacy = "";
my $dbh = Bugzilla->dbh;
if (Param("insidergroup") && !(UserInGroup(Param("insidergroup")))) { if (Param("insidergroup") && !(UserInGroup(Param("insidergroup")))) {
$privacy = "AND isprivate < 1 "; $privacy = "AND isprivate < 1 ";
} }
SendSQL("SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'), SendSQL("SELECT attach_id, " .
mimetype, description, ispatch, isobsolete, isprivate, $dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') . ",
mimetype, description, ispatch, isobsolete, isprivate,
LENGTH(thedata) LENGTH(thedata)
FROM attachments WHERE bug_id = $::FORM{'bugid'} $privacy FROM attachments WHERE bug_id = $::FORM{'bugid'} $privacy
ORDER BY attach_id"); ORDER BY attach_id");
......
...@@ -505,7 +505,7 @@ DefineColumn("remaining_time" , "bugs.remaining_time" , "Remaining Hou ...@@ -505,7 +505,7 @@ DefineColumn("remaining_time" , "bugs.remaining_time" , "Remaining Hou
DefineColumn("actual_time" , "(SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id)) AS actual_time", "Actual Hours"); DefineColumn("actual_time" , "(SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id)) AS actual_time", "Actual Hours");
DefineColumn("percentage_complete","(100*((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))/((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))+bugs.remaining_time))) AS percentage_complete", "% Complete"); DefineColumn("percentage_complete","(100*((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))/((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))+bugs.remaining_time))) AS percentage_complete", "% Complete");
DefineColumn("relevance" , "relevance" , "Relevance" ); DefineColumn("relevance" , "relevance" , "Relevance" );
DefineColumn("deadline" , "DATE_FORMAT(bugs.deadline, '%Y-%m-%d')", "Deadline"); DefineColumn("deadline" , $dbh->sql_date_format('bugs.deadline', '%Y-%m-%d'), "Deadline");
################################################################################ ################################################################################
# Display Column Determination # Display Column Determination
......
...@@ -971,7 +971,9 @@ sub GetLongDescriptionAsText { ...@@ -971,7 +971,9 @@ sub GetLongDescriptionAsText {
my $result = ""; my $result = "";
my $count = 0; my $count = 0;
my $anyprivate = 0; my $anyprivate = 0;
my ($query) = ("SELECT profiles.login_name, DATE_FORMAT(longdescs.bug_when,'%Y.%m.%d %H:%i'), " . my $dbh = Bugzilla->dbh;
my ($query) = ("SELECT profiles.login_name, " .
$dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i') . ", " .
" longdescs.thetext, longdescs.isprivate, " . " longdescs.thetext, longdescs.isprivate, " .
" longdescs.already_wrapped " . " longdescs.already_wrapped " .
"FROM longdescs, profiles " . "FROM longdescs, profiles " .
......
...@@ -56,6 +56,7 @@ exit; ...@@ -56,6 +56,7 @@ exit;
sub queue { sub queue {
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
validateStatus($cgi->param('status')); validateStatus($cgi->param('status'));
validateGroup($cgi->param('group')); validateGroup($cgi->param('group'));
...@@ -75,7 +76,7 @@ sub queue { ...@@ -75,7 +76,7 @@ sub queue {
flags.attach_id, attachments.description, flags.attach_id, attachments.description,
requesters.realname, requesters.login_name, requesters.realname, requesters.login_name,
requestees.realname, requestees.login_name, requestees.realname, requestees.login_name,
DATE_FORMAT(flags.creation_date,'%Y.%m.%d %H:%i'), " . $dbh->sql_date_format('flags.creation_date', '%Y.%m.%d %H:%i') . ",
" . " .
# Select columns that help us weed out secure bugs to which the user # Select columns that help us weed out secure bugs to which the user
# should not have access. # should not have access.
......
...@@ -118,12 +118,16 @@ if (open(NOMAIL, '<', "$datadir/nomail")) { ...@@ -118,12 +118,16 @@ if (open(NOMAIL, '<', "$datadir/nomail")) {
} }
# get the current date and time from the database # get the current date and time from the database
$sth = $dbh->prepare( 'SELECT DATE_FORMAT( NOW(), "%y,%m,%e,%w,%k,%i")'); $sth = $dbh->prepare('SELECT ' . $dbh->sql_date_format('NOW()', '%y,%m,%d,%a,%H,%i'));
$sth->execute; $sth->execute;
my ($now_year, $now_month, $now_day, $now_weekday, $now_hour, $now_minute) = my ($now_year, $now_month, $now_day, $now_weekdayname, $now_hour, $now_minute) =
split(',', $sth->fetchrow_array); split(',', $sth->fetchrow_array);
$sth->finish; $sth->finish;
# As DBs have different days numbering, use day name and convert it
# to the range 0-6
my $now_weekday = index("SunMonTueWedThuFriSat", $now_weekdayname) / 3;
my @daysinmonth = qw(0 31 28 31 30 31 30 31 31 30 31 30 31); my @daysinmonth = qw(0 31 28 31 30 31 30 31 31 30 31 30 31);
# Alter February in case of a leap year. This simple way to do it only # Alter February in case of a leap year. This simple way to do it only
# applies if you won't be looking at February of next year, which whining # applies if you won't be looking at February of next year, which whining
......
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