Commit 14a992f3 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303709: Eliminate deprecated Bugzilla::DB routines from sendbugmail.pl,…

Bug 303709: Eliminate deprecated Bugzilla::DB routines from sendbugmail.pl, sendunsentbugmail.pl and syncLDAP.pl scripts in contrib - Patch by Olav Vitters <bugzilla-mozilla@bkor.dhs.org> r=LpSolit a=justdave
parent ea5339f6
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Nick Barnes, Ravenbrook Limited, 2004-04-01. # Nick Barnes, Ravenbrook Limited, 2004-04-01.
# #
# $Id: sendbugmail.pl,v 1.3 2005/02/24 23:42:48 mkanat%kerio.com Exp $ # $Id: sendbugmail.pl,v 1.4 2006/05/15 16:06:59 lpsolit%gmail.com Exp $
# #
# Bugzilla email script for Bugzilla 2.17.4 and later. Invoke this to send # Bugzilla email script for Bugzilla 2.17.4 and later. Invoke this to send
# bugmail for a bug which has been changed directly in the database. # bugmail for a bug which has been changed directly in the database.
...@@ -17,9 +17,12 @@ ...@@ -17,9 +17,12 @@
use lib qw(.); use lib qw(.);
require "globals.pl"; require "globals.pl";
use Bugzilla;
use Bugzilla::BugMail; use Bugzilla::BugMail;
use Bugzilla::User; use Bugzilla::User;
my $dbh = Bugzilla->dbh;
sub usage { sub usage {
print STDERR "Usage: $0 bug_id user_email\n"; print STDERR "Usage: $0 bug_id user_email\n";
exit; exit;
...@@ -41,9 +44,10 @@ if (!($bugnum =~ /^(\d+)$/)) { ...@@ -41,9 +44,10 @@ if (!($bugnum =~ /^(\d+)$/)) {
detaint_natural($bugnum); detaint_natural($bugnum);
SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugnum"); my ($id) = $dbh->selectrow_array("SELECT bug_id FROM bugs WHERE bug_id = ?",
undef, $bugnum);
if (!FetchOneColumn()) { if (!$id) {
print STDERR "Bug number $bugnum does not exist.\n"; print STDERR "Bug number $bugnum does not exist.\n";
usage(); usage();
} }
......
...@@ -26,24 +26,23 @@ use strict; ...@@ -26,24 +26,23 @@ use strict;
use lib qw(.); use lib qw(.);
require "globals.pl"; require "globals.pl";
use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::BugMail; use Bugzilla::BugMail;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
SendSQL("SELECT bug_id FROM bugs
my $list = $dbh->selectcol_arrayref(
'SELECT bug_id FROM bugs
WHERE lastdiffed IS NULL WHERE lastdiffed IS NULL
OR lastdiffed < delta_ts AND delta_ts < NOW() - " OR lastdiffed < delta_ts
. $dbh->sql_interval(30, 'MINUTE') . AND delta_ts < NOW() - ' . $dbh->sql_interval(30, 'MINUTE') .
" ORDER BY bug_id"); ' ORDER BY bug_id');
my @list;
while (MoreSQLData()) {
push (@list, FetchOneColumn());
}
if (scalar(@list) > 0) { if (scalar(@$list) > 0) {
print "OK, now attempting to send unsent mail\n"; print "OK, now attempting to send unsent mail\n";
print scalar(@list) . " bugs found with possibly unsent mail.\n\n"; print scalar(@$list) . " bugs found with possibly unsent mail.\n\n";
foreach my $bugid (@list) { foreach my $bugid (@$list) {
my $start_time = time; my $start_time = time;
print "Sending mail for bug $bugid...\n"; print "Sending mail for bug $bugid...\n";
my $outputref = Bugzilla::BugMail::Send($bugid); my $outputref = Bugzilla::BugMail::Send($bugid);
......
...@@ -28,6 +28,8 @@ require "globals.pl"; ...@@ -28,6 +28,8 @@ require "globals.pl";
use lib qw(.); use lib qw(.);
use Net::LDAP; use Net::LDAP;
use Bugzilla;
use Bugzilla::User;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
...@@ -75,24 +77,18 @@ foreach my $arg (@ARGV) ...@@ -75,24 +77,18 @@ foreach my $arg (@ARGV)
} }
} }
my %bugzilla_users;
my %ldap_users; my %ldap_users;
### ###
# Get current bugzilla users # Get current bugzilla users
### ###
SendSQL("SELECT login_name, realname, disabledtext " . my $bugzilla_users = $dbh->selectall_hashref(
"FROM profiles" ); 'SELECT login_name AS new_login_name, realname, disabledtext ' .
while (MoreSQLData()) { 'FROM profiles', 'new_login_name');
my ($login_name, $realname, $disabledtext)
= FetchSQLData();
foreach my $login_name (keys %$bugzilla_users) {
# remove whitespaces # remove whitespaces
$realname =~ s/^\s+|\s+$//g; $bugzilla_users->{$login_name}{'realname'} =~ s/^\s+|\s+$//g;
$bugzilla_users{$login_name} = { realname => $realname,
new_login_name => $login_name,
disabledtext => $disabledtext };
} }
### ###
...@@ -171,7 +167,7 @@ my %update_users; ...@@ -171,7 +167,7 @@ my %update_users;
my %create_users; my %create_users;
print "Bugzilla-Users: \n" unless $quiet; print "Bugzilla-Users: \n" unless $quiet;
while( my ($key, $value) = each(%bugzilla_users) ) { while( my ($key, $value) = each(%$bugzilla_users) ) {
print " " . $key . " '" . @$value{'realname'} . "' " . @$value{'disabledtext'} ."\n" unless $quiet==1; print " " . $key . " '" . @$value{'realname'} . "' " . @$value{'disabledtext'} ."\n" unless $quiet==1;
if(!exists $ldap_users{$key}){ if(!exists $ldap_users{$key}){
if(@$value{'disabledtext'} eq '') { if(@$value{'disabledtext'} eq '') {
...@@ -183,11 +179,11 @@ while( my ($key, $value) = each(%bugzilla_users) ) { ...@@ -183,11 +179,11 @@ while( my ($key, $value) = each(%bugzilla_users) ) {
print "\nLDAP-Users: \n" unless $quiet; print "\nLDAP-Users: \n" unless $quiet;
while( my ($key, $value) = each(%ldap_users) ) { while( my ($key, $value) = each(%ldap_users) ) {
print " " . $key . " '" . @$value{'realname'} . "'\n" unless $quiet==1; print " " . $key . " '" . @$value{'realname'} . "'\n" unless $quiet==1;
if(!exists $bugzilla_users{$key}){ if(!defined $bugzilla_users->{$key}){
$create_users{$key} = $value; $create_users{$key} = $value;
} }
else { else {
my $bugzilla_user_value = $bugzilla_users{$key}; my $bugzilla_user_value = $bugzilla_users->{$key};
if(@$bugzilla_user_value{'realname'} ne @$value{'realname'}) { if(@$bugzilla_user_value{'realname'} ne @$value{'realname'}) {
$update_users{$key} = $value; $update_users{$key} = $value;
} }
...@@ -236,11 +232,15 @@ if($quiet == 0) { ...@@ -236,11 +232,15 @@ if($quiet == 0) {
### ###
if($readonly == 0) { if($readonly == 0) {
print "Performing DB update:\nPhase 1: disabling not-existing users... " unless $quiet; print "Performing DB update:\nPhase 1: disabling not-existing users... " unless $quiet;
my $sth_disable = $dbh->prepare(
'UPDATE profiles
SET disabledtext = ?
WHERE ' . $dbh->sql_istrcmp('login_name', '?'));
if($nodisable == 0) { if($nodisable == 0) {
while( my ($key, $value) = each(%disable_users) ) { while( my ($key, $value) = each(%disable_users) ) {
SendSQL("UPDATE profiles SET disabledtext = 'auto-disabled by ldap " . $sth_disable->execute('auto-disabled by ldap sync', $key);
"sync' WHERE " . $dbh->sql_istrcmp('login_name',
$dbh->quote($key)));
} }
print "done!\n" unless $quiet; print "done!\n" unless $quiet;
} }
...@@ -249,15 +249,22 @@ if($readonly == 0) { ...@@ -249,15 +249,22 @@ if($readonly == 0) {
} }
print "Phase 2: updating existing users... " unless $quiet; print "Phase 2: updating existing users... " unless $quiet;
my $sth_update_login = $dbh->prepare(
'UPDATE profiles
SET login_name = ?
WHERE ' . $dbh->sql_istrcmp('login_name', '?'));
my $sth_update_realname = $dbh->prepare(
'UPDATE profiles
SET realname = ?
WHERE ' . $dbh->sql_istrcmp('login_name', '?'));
if($noupdate == 0) { if($noupdate == 0) {
while( my ($key, $value) = each(%update_users) ) { while( my ($key, $value) = each(%update_users) ) {
if(defined @$value{'new_login_name'}) { if(defined @$value{'new_login_name'}) {
SendSQL("UPDATE profiles SET login_name = '" . $sth_update_login->execute(@$value{'new_login_name'}, $key);
@$value{'new_login_name'} . "' WHERE " .
$dbh->sql_istrcmp('login_name', $dbh->quote($key)));
} else { } else {
SendSQL("UPDATE profiles SET realname = '" . @$value{'realname'} . $sth_update_realname->execute(@$value{'realname'}, $key);
"' WHERE " . $dbh->sql_istrcmp('login_name', $dbh->quote($key)));
} }
} }
print "done!\n" unless $quiet; print "done!\n" unless $quiet;
...@@ -269,14 +276,7 @@ if($readonly == 0) { ...@@ -269,14 +276,7 @@ if($readonly == 0) {
print "Phase 3: creating new users... " unless $quiet; print "Phase 3: creating new users... " unless $quiet;
if($nocreate == 0) { if($nocreate == 0) {
while( my ($key, $value) = each(%create_users) ) { while( my ($key, $value) = each(%create_users) ) {
SendSQL("INSERT INTO profiles VALUES ('', insert_new_user($key, @$value{'realname'});
'$key',
'xxKFIy4WR66mA',
'" . @$value{'realname'} . "',
'',
1,
'ExcludeSelf~on~emailOwnerRemoveme~on~emailOwnerComments~on~emailOwnerAttachments~on~emailOwnerStatus~on~emailOwnerResolved~on~emailOwnerKeywords~on~emailOwnerCC~on~emailOwnerOther~on~emailOwnerUnconfirmed~on~emailReporterRemoveme~on~emailReporterComments~on~emailReporterAttachments~on~emailReporterStatus~on~emailReporterResolved~on~emailReporterKeywords~on~emailReporterCC~on~emailReporterOther~on~emailReporterUnconfirmed~on~emailQAcontactRemoveme~on~emailQAcontactComments~on~emailQAcontactAttachments~on~emailQAcontactStatus~on~emailQAcontactResolved~on~emailQAcontactKeywords~on~emailQAcontactCC~on~emailQAcontactOther~on~emailQAcontactUnconfirmed~on~emailCClistRemoveme~on~emailCClistComments~on~emailCClistAttachments~on~emailCClistStatus~on~emailCClistResolved~on~emailCClistKeywords~on~emailCClistCC~on~emailCClistOther~on~emailCClistUnconfirmed~on~emailVoterRemoveme~on~emailVoterComments~on~emailVoterAttachments~on~emailVoterStatus~on~emailVoterResolved~on~emailVoterKeywords~on~emailVoterCC~on~emailVoterOther~on~emailVoterUnconfirmed~on',
sysdate())");
} }
print "done!\n" unless $quiet; print "done!\n" unless $quiet;
} }
......
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