}
$_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
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();
}
}
# 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
# 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 " .
# 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'},
mail($args);
}
- Bugzilla->switch_to_main_db();
+ $dbh = Bugzilla->switch_to_main_db();
}
################################################################################