Commit d7958942 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 280502: Replace "INTERVAL" with Bugzilla::DB function call

Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat, a=justdave
parent e547dd6d
...@@ -906,7 +906,7 @@ sub init { ...@@ -906,7 +906,7 @@ sub init {
$unitinterval = 'YEAR'; $unitinterval = 'YEAR';
} }
my $cutoff = "DATE_SUB(NOW(), " . my $cutoff = "DATE_SUB(NOW(), " .
"INTERVAL $quantity $unitinterval)"; $dbh->sql_interval("$quantity $unitinterval");
my $assigned_fieldid = &::GetFieldID('assigned_to'); my $assigned_fieldid = &::GetFieldID('assigned_to');
push(@supptables, "LEFT JOIN longdescs comment_$table " . push(@supptables, "LEFT JOIN longdescs comment_$table " .
"ON comment_$table.who = bugs.assigned_to " . "ON comment_$table.who = bugs.assigned_to " .
......
...@@ -119,7 +119,8 @@ sub IssuePasswordToken { ...@@ -119,7 +119,8 @@ sub IssuePasswordToken {
LEFT JOIN tokens LEFT JOIN tokens
ON tokens.userid = profiles.userid ON tokens.userid = profiles.userid
AND tokens.tokentype = 'password' AND tokens.tokentype = 'password'
AND tokens.issuedate > DATE_SUB(NOW(), INTERVAL 10 MINUTE) AND tokens.issuedate > DATE_SUB(NOW(), " .
$dbh->sql_interval('10 MINUTE') . ")
WHERE login_name = $quotedloginname"); WHERE login_name = $quotedloginname");
my ($userid, $toosoon) = &::FetchSQLData(); my ($userid, $toosoon) = &::FetchSQLData();
......
...@@ -29,8 +29,10 @@ require "CGI.pl"; ...@@ -29,8 +29,10 @@ require "CGI.pl";
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::BugMail; use Bugzilla::BugMail;
my $dbh = Bugzilla->dbh;
SendSQL("SELECT bug_id FROM bugs WHERE lastdiffed < delta_ts AND SendSQL("SELECT bug_id FROM bugs WHERE lastdiffed < delta_ts AND
delta_ts < date_sub(now(), INTERVAL 30 minute) ORDER BY bug_id"); delta_ts < date_sub(now(), " . $dbh->sql_interval('30 minute') .
" ORDER BY bug_id");
my @list; my @list;
while (MoreSQLData()) { while (MoreSQLData()) {
push (@list, FetchOneColumn()); push (@list, FetchOneColumn());
......
...@@ -144,7 +144,8 @@ if (defined $cgi->param('cleangroupsnow')) { ...@@ -144,7 +144,8 @@ if (defined $cgi->param('cleangroupsnow')) {
# to get the groups up to date. # to get the groups up to date.
# If any page starts taking longer than one hour to load, this interval # If any page starts taking longer than one hour to load, this interval
# should be revised. # should be revised.
SendSQL("SELECT MAX(last_changed) FROM groups WHERE last_changed < NOW() - INTERVAL 1 HOUR"); SendSQL("SELECT MAX(last_changed) FROM groups WHERE last_changed < NOW() - " .
$dbh->sql_interval('1 HOUR'));
(my $cutoff) = FetchSQLData(); (my $cutoff) = FetchSQLData();
Status("Cutoff is $cutoff"); Status("Cutoff is $cutoff");
SendSQL("SELECT COUNT(*) FROM user_group_map"); SendSQL("SELECT COUNT(*) FROM user_group_map");
...@@ -175,7 +176,8 @@ if (defined $cgi->param('rescanallBugMail')) { ...@@ -175,7 +176,8 @@ if (defined $cgi->param('rescanallBugMail')) {
Status("OK, now attempting to send unsent mail"); Status("OK, now attempting to send unsent mail");
SendSQL("SELECT bug_id FROM bugs WHERE lastdiffed < delta_ts AND SendSQL("SELECT bug_id FROM bugs WHERE lastdiffed < delta_ts AND
delta_ts < date_sub(now(), INTERVAL 30 minute) ORDER BY bug_id"); delta_ts < date_sub(now(), " . $dbh->sql_interval('30 minute') .
" ORDER BY bug_id");
my @list; my @list;
while (MoreSQLData()) { while (MoreSQLData()) {
push (@list, FetchOneColumn()); push (@list, FetchOneColumn());
...@@ -738,8 +740,8 @@ Status("Checking for unsent mail"); ...@@ -738,8 +740,8 @@ Status("Checking for unsent mail");
SendSQL("SELECT bug_id " . SendSQL("SELECT bug_id " .
"FROM bugs WHERE lastdiffed < delta_ts AND ". "FROM bugs WHERE lastdiffed < delta_ts AND ".
"delta_ts < date_sub(now(), INTERVAL 30 minute) ". "delta_ts < date_sub(now(), " . $dbh->sql_interval('30 minute') .
"ORDER BY bug_id"); " ORDER BY bug_id");
while (@row = FetchSQLData()) { while (@row = FetchSQLData()) {
my ($id) = (@row); my ($id) = (@row);
......
...@@ -54,7 +54,8 @@ sub DoAccount { ...@@ -54,7 +54,8 @@ sub DoAccount {
$vars->{'realname'} = FetchSQLData(); $vars->{'realname'} = FetchSQLData();
if(Param('allowemailchange')) { if(Param('allowemailchange')) {
SendSQL("SELECT tokentype, issuedate + INTERVAL 3 DAY, eventdata SendSQL("SELECT tokentype, issuedate + " . $dbh->sql_interval('3 DAY') .
", eventdata
FROM tokens FROM tokens
WHERE userid = $userid WHERE userid = $userid
AND tokentype LIKE 'email%' AND tokentype LIKE 'email%'
......
...@@ -168,7 +168,8 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) { ...@@ -168,7 +168,8 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
elsif ($time >= $now_hour) { elsif ($time >= $now_hour) {
# set it to today + number of hours # set it to today + number of hours
$sth = $dbh->prepare( "UPDATE whine_schedules " . $sth = $dbh->prepare( "UPDATE whine_schedules " .
"SET run_next=DATE_ADD(CURRENT_DATE(), INTERVAL ? HOUR) " . "SET run_next=DATE_ADD(CURRENT_DATE(), " .
$dbh->sql_interval('? HOUR') . ") " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($time, $schedule_id); $sth->execute($time, $schedule_id);
} }
...@@ -177,7 +178,7 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) { ...@@ -177,7 +178,7 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
my $nextdate = &get_next_date($day); my $nextdate = &get_next_date($day);
$sth = $dbh->prepare( "UPDATE whine_schedules " . $sth = $dbh->prepare( "UPDATE whine_schedules " .
"SET run_next=" . "SET run_next=" .
"DATE_ADD(?, INTERVAL ? HOUR) " . "DATE_ADD(?, " . $dbh->sql_interval('? HOUR') . ") " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($nextdate, $time, $schedule_id); $sth->execute($nextdate, $time, $schedule_id);
} }
...@@ -192,7 +193,8 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) { ...@@ -192,7 +193,8 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
my $target_time = ($time =~ /^\d+$/) ? $time : 0; my $target_time = ($time =~ /^\d+$/) ? $time : 0;
$sth = $dbh->prepare( "UPDATE whine_schedules " . $sth = $dbh->prepare( "UPDATE whine_schedules " .
"SET run_next=DATE_ADD(?, INTERVAL ? HOUR) " . "SET run_next=DATE_ADD(?, " .
$dbh->sql_interval('? HOUR') . ") " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($target_date, $target_time, $schedule_id); $sth->execute($target_date, $target_time, $schedule_id);
} }
...@@ -590,7 +592,8 @@ sub reset_timer { ...@@ -590,7 +592,8 @@ sub reset_timer {
my $nextdate = &get_next_date($run_day); my $nextdate = &get_next_date($run_day);
$sth = $dbh->prepare( "UPDATE whine_schedules " . $sth = $dbh->prepare( "UPDATE whine_schedules " .
"SET run_next=DATE_ADD(?, INTERVAL ? HOUR) " . "SET run_next=DATE_ADD(?, " .
$dbh->sql_interval('? HOUR') . ") " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($nextdate, $target_time, $schedule_id); $sth->execute($nextdate, $target_time, $schedule_id);
return; return;
...@@ -601,8 +604,9 @@ sub reset_timer { ...@@ -601,8 +604,9 @@ sub reset_timer {
if ($minute_offset > 0) { if ($minute_offset > 0) {
$sth = $dbh->prepare("UPDATE whine_schedules " . $sth = $dbh->prepare("UPDATE whine_schedules " .
"SET run_next = " . "SET run_next = " .
"DATE_SUB(DATE_ADD(NOW(), INTERVAL ? MINUTE), " . "DATE_SUB(DATE_ADD(NOW(), " .
"INTERVAL SECOND(NOW()) SECOND) " . $dbh->sql_interval('? MINUTE') . "), " .
$dbh->sql_interval('SECOND(NOW()) SECOND') . ") " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($minute_offset, $schedule_id); $sth->execute($minute_offset, $schedule_id);
} else { } else {
...@@ -683,7 +687,8 @@ sub get_next_date { ...@@ -683,7 +687,8 @@ sub get_next_date {
} }
# Get a date in whatever format the database will accept # Get a date in whatever format the database will accept
$sth = $dbh->prepare("SELECT DATE_ADD(CURRENT_DATE(), INTERVAL ? DAY)"); $sth = $dbh->prepare("SELECT DATE_ADD(CURRENT_DATE(), " .
$dbh->sql_interval('? DAY') . ")");
$sth->execute($add_days); $sth->execute($add_days);
return $sth->fetch->[0]; return $sth->fetch->[0];
} }
......
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