From: lpsolit%gmail.com <> Date: Mon, 14 Nov 2005 01:57:26 +0000 (+0000) Subject: Bug 313695: buglist.cgi and some other scripts do not use the shadow DB correctly... X-Git-Tag: bugzilla-2.20.1~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5548ff96fed5b86738e39f7c5f13e985602603c1;p=thirdparty%2Fbugzilla.git Bug 313695: buglist.cgi and some other scripts do not use the shadow DB correctly - Patch by Frédéric Buclin r/a=justdave --- diff --git a/Bugzilla.pm b/Bugzilla.pm index 0deb6e16e5..c46b8f8063 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -144,12 +144,20 @@ sub switch_to_shadow_db { } $_dbh = $_dbh_shadow; + # we have to return $class->dbh instead of $_dbh as + # $_dbh_shadow may be undefined if no shadow DB is used + # and no connection to the main DB has been established yet. + return $class->dbh; } sub switch_to_main_db { my $class = shift; $_dbh = $_dbh_main; + # We have to return $class->dbh instead of $_dbh as + # $_dbh_main may be undefined if no connection to the main DB + # has been established yet. + return $class->dbh; } # Private methods diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 252275991e..87b82171bd 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -149,11 +149,11 @@ sub _create { if ($result) { my $is_main_db; unless ($is_main_db = Bugzilla->dbwritesallowed()) { - Bugzilla->switch_to_main_db(); + $dbh = Bugzilla->switch_to_main_db(); } $self->derive_groups($tables_locked_for_derive_groups); unless ($is_main_db) { - Bugzilla->switch_to_shadow_db(); + $dbh = Bugzilla->switch_to_shadow_db(); } } diff --git a/buglist.cgi b/buglist.cgi index cc087fe67e..461f7f8bfb 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -836,7 +836,7 @@ if ($serverpush) { # Connect to the shadow database if this installation is using one to improve # query performance. -Bugzilla->switch_to_shadow_db(); +$dbh = Bugzilla->switch_to_shadow_db(); # Normally, we ignore SIGTERM and SIGPIPE (see globals.pl) but we need to # respond to them here to prevent someone DOSing us by reloading a query diff --git a/collectstats.pl b/collectstats.pl index a12c85586c..e087c28d04 100755 --- a/collectstats.pl +++ b/collectstats.pl @@ -458,10 +458,8 @@ sub CollectSeriesData { # We save a copy of the main $dbh and then switch to the shadow and get # that one too. Remember, these may be the same. - Bugzilla->switch_to_main_db(); - my $dbh = Bugzilla->dbh; - Bugzilla->switch_to_shadow_db(); - my $shadow_dbh = Bugzilla->dbh; + my $dbh = Bugzilla->switch_to_main_db(); + my $shadow_dbh = Bugzilla->switch_to_shadow_db(); my $serieses = $dbh->selectall_hashref("SELECT series_id, query, creator " . "FROM series " . diff --git a/whine.pl b/whine.pl index d8fc8ddd08..4068a052f6 100755 --- a/whine.pl +++ b/whine.pl @@ -327,7 +327,7 @@ while (my $event = get_next_event) { # We loop for each target user because some of the queries will be using # subjective pronouns - Bugzilla->switch_to_shadow_db(); + $dbh = Bugzilla->switch_to_shadow_db(); for my $target (@{$event->{'mailto'}}) { my $args = { 'subject' => $event->{'subject'}, @@ -352,7 +352,7 @@ while (my $event = get_next_event) { mail($args); } - Bugzilla->switch_to_main_db(); + $dbh = Bugzilla->switch_to_main_db(); } ################################################################################