Closed Bug 303709 Opened 19 years ago Closed 19 years ago

Eliminate deprecated Bugzilla::DB routines from sendbugmail.pl, sendunsentbugmail.pl and syncLDAP.pl scripts in contrib

Categories

(Bugzilla :: Bugzilla-General, enhancement)

2.21
enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Bugzilla 3.0

People

(Reporter: wicked, Assigned: bugzilla-mozilla)

References

Details

Attachments

(1 file, 4 obsolete files)

These lines need to rewritten to use DBI:

contrib/sendbugmail.pl:44:SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugnum");
contrib/sendbugmail.pl:46:if (!FetchOneColumn()) {

contrib/sendunsentbugmail.pl:33:SendSQL("SELECT bug_id FROM bugs
contrib/sendunsentbugmail.pl:39:while (MoreSQLData()) {
contrib/sendunsentbugmail.pl:40:    push (@list, FetchOneColumn());

contrib/syncLDAP.pl:84:SendSQL("SELECT login_name, realname, disabledtext " .
contrib/syncLDAP.pl:86:while (MoreSQLData()) {
contrib/syncLDAP.pl:88:        = FetchSQLData();
contrib/syncLDAP.pl:241:        SendSQL("UPDATE profiles SET disabledtext =
'auto-disabled by ldap " .
contrib/syncLDAP.pl:255:          SendSQL("UPDATE profiles SET login_name = '" .
contrib/syncLDAP.pl:259:          SendSQL("UPDATE profiles SET realname = '" .
@$value{'realname'} .
contrib/syncLDAP.pl:272:        SendSQL("INSERT INTO profiles VALUES ('',
Assignee: general → bugzilla-mozilla
Attached patch Patch v1 (obsolete) β€” β€” Splinter Review
I could NOT test contrib/syncLDAP.pl due to lack of LDAP install. That script was broken anyway. The part that created a new user in Bugzilla used 'INSERT INTO profiles VALUES'. This relied on a old order of the columns (also had that old emailsettings in there). I replaced it with insert_new_user as that is much cleaner.

contrib/sendbugmail.pl:
 * Adds 'use Bugzilla' (much better than assuming globals.pl uses it)

contrib/syncLDAP.pl:
 * Script could use a rewrite
 * Indentation is off
 * Seems to made for Oracle ('sysdate()', 'sql_istrcmp' for login_name)
 * Perhaps move this into a seperate bug?
 * See part about it being broken
Attachment #201559 - Flags: review?(wicked)
Target Milestone: --- → Bugzilla 2.24
Severity: normal → enhancement
Comment on attachment 201559 [details] [diff] [review]
Patch v1

>Index: contrib/sendunsentbugmail.pl
>===================================================================

This is sligthly bitrotten but otherwise seems good.

>Index: contrib/syncLDAP.pl
>===================================================================
>+my $bugzilla_users = $dbh->selectall_hashref(
>+    'SELECT login_name AS new_login_name, realname, disabledtext ' .
>+    'FROM profiles', 'login_name');

This doesn't work:

syncLDAP.pl: DBD::mysql::db selectall_hashref failed: Field 'login_name' does not exist (not one of realname disabledtext new_login_name) [for Statement "SELECT login_name AS new_login_name, realname, disabledtext FROM profiles"] at ./contrib/syncLDAP.pl line 85

>+foreach my $login_name (keys %$bugzilla_users) {
>     # remove whitespaces
>+    $bugzilla_users->{'realname'} =~ s/^\s+|\s+$//g;
> }

This doesn't look like it's going to work.. Shouldn't it use $login_name somehow?
Attachment #201559 - Flags: review?(wicked) → review-
bkor, are you still working on this bug? Else I'm sure gbel would be interested in working on it. ;)
Attached patch Patch v2 (obsolete) β€” β€” Splinter Review
(In reply to comment #2)
> (From update of attachment 201559 [details] [diff] [review] [edit])
> >Index: contrib/sendunsentbugmail.pl
> >===================================================================
> 
> This is sligthly bitrotten but otherwise seems good.

Fixed the bitrot (one SQL)

> >Index: contrib/syncLDAP.pl
> >===================================================================
> >+my $bugzilla_users = $dbh->selectall_hashref(
> >+    'SELECT login_name AS new_login_name, realname, disabledtext ' .
> >+    'FROM profiles', 'login_name');
> 
> This doesn't work:
> 
> syncLDAP.pl: DBD::mysql::db selectall_hashref failed: Field 'login_name' does
> not exist (not one of realname disabledtext new_login_name) [for Statement
> "SELECT login_name AS new_login_name, realname, disabledtext FROM profiles"] at
> ./contrib/syncLDAP.pl line 85

Fixed.

> >+foreach my $login_name (keys %$bugzilla_users) {
> >     # remove whitespaces
> >+    $bugzilla_users->{'realname'} =~ s/^\s+|\s+$//g;
> > }
> 
> This doesn't look like it's going to work.. Shouldn't it use $login_name
> somehow?

Indeed. Fixed and tested until that part. Hopefully no more errors in the LDAP part as I cannot test it here :-( :-(
Attachment #201559 - Attachment is obsolete: true
Attachment #219427 - Flags: review?
Attachment #219427 - Flags: review? → review?(wicked+bz)
Comment on attachment 219427 [details] [diff] [review]
Patch v2

>Index: contrib/sendunsentbugmail.pl

Nit: explicitly "use Bugzilla;" as globals.pl will die very soon now.


> my @list;
> while (MoreSQLData()) {
>     push (@list, FetchOneColumn());
> }

Unused code. Remove these lines.



>Index: contrib/syncLDAP.pl

>       while( my ($key, $value) = each(%disable_users) ) {
>+        $dbh->do('UPDATE profiles SET disabledtext = ? WHERE ' .
>+                 $dbh->sql_istrcmp('login_name', '?'), undef, 
>+                 ('auto-disabled by ldap sync', $key));
>       }

Prepare the SQL query outside the while() loop, and use ->execute() inside the loop.


>       while( my ($key, $value) = each(%update_users) ) {
>         if(defined @$value{'new_login_name'}) {
>+          $dbh->do('UPDATE profiles SET login_name = ? WHERE ' .
>+                   $dbh->sql_istrcmp('login_name', '?'), undef,
>+                   (@$value{'new_login_name'}, $key));
>         } else {
>+          $dbh->do('UPDATE profiles SET realname = ? WHERE ' .
>+                   $dbh->sql_istrcmp('login_name', '?'), undef,
>+                   (@$value{'realname'}, $key));
>         }
>       }

Same comment here. Moreover, I prefer @$value{'realname'}[0] as we really want to return a scalar, not an array.
Attachment #219427 - Flags: review?(wicked+bz) → review-
Status: NEW → ASSIGNED
Attached patch Patch v3: Bugzilla HEAD 2005-05-14 (obsolete) β€” β€” Splinter Review
> Nit: explicitly "use Bugzilla;" as globals.pl will die very soon now.

done

> Unused code. Remove these lines.

whoops! removed.

> Prepare the SQL query outside the while() loop, and use ->execute() inside the
> loop.

done

> Same comment here. Moreover, I prefer @$value{'realname'}[0] as we really want
> to return a scalar, not an array.

Done and made same change for @$value{'new_login_name'}.
Attachment #219427 - Attachment is obsolete: true
Attachment #221985 - Flags: review?(LpSolit)
Attached patch Patch v4: Use @$values (obsolete) β€” β€” Splinter Review
Attachment #221985 - Attachment is obsolete: true
Attachment #221986 - Flags: review?(LpSolit)
Attachment #221985 - Flags: review?(LpSolit)
Comment on attachment 221986 [details] [diff] [review]
Patch v4: Use @$values

>Index: contrib/syncLDAP.pl

>+          $sth_update_login->execute(@$value{'new_login_name'}[0], $key);

>+          $sth_update_realname->execute(@$value{'realname'}[0], $key);

>+        insert_new_user($key, @$value{'realname'}[0]);

Next time I should look at the code more carefully. I thought $value{'foo'} was a reference to an array, but it's a reference to an hash and so appending [0] is wrong here. To make more sense, we should write $value->{'foo'} instead as $value is really a ref to an hash. This file really needs some cleanup, so let's use the $value->{'foo'} notation in another bug. Meanwhile, I r+ this patch and the one doing the checkin should remove these [0] on checkin. Sorry for the confusion, bkor. r=LpSolit
Attachment #221986 - Flags: review?(LpSolit) → review+
Flags: approval?
Attached patch patch, v4.1 β€” β€” Splinter Review
[0] removed
Attachment #221986 - Attachment is obsolete: true
Comment on attachment 221992 [details] [diff] [review]
patch, v4.1

carrying forward r+ from previous patch based on interdiff exactly matching the previous reviewer's comments.
Attachment #221992 - Flags: review+
Flags: approval? → approval+
Checking in contrib/sendbugmail.pl;
/cvsroot/mozilla/webtools/bugzilla/contrib/sendbugmail.pl,v  <--  sendbugmail.pl
new revision: 1.4; previous revision: 1.3
done
Checking in contrib/sendunsentbugmail.pl;
/cvsroot/mozilla/webtools/bugzilla/contrib/sendunsentbugmail.pl,v  <--  sendunsentbugmail.pl
new revision: 1.8; previous revision: 1.7
done
Checking in contrib/syncLDAP.pl;
/cvsroot/mozilla/webtools/bugzilla/contrib/syncLDAP.pl,v  <--  syncLDAP.pl
new revision: 1.5; previous revision: 1.4
done
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: