From 6368cfad3ea49b6220598d2e362defbc820b9c36 Mon Sep 17 00:00:00 2001 From: "bbaetz%student.usyd.edu.au" <> Date: Wed, 15 Jan 2003 04:00:05 +0000 Subject: Bug 163290 - move DB handling code into a module r=justdave, myk, joel, preed a=justdave --- Bugzilla.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index f093edaa5..66831046d 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -25,6 +25,8 @@ package Bugzilla; use strict; use Bugzilla::CGI; +use Bugzilla::Config; +use Bugzilla::DB; use Bugzilla::Template; sub create { @@ -51,6 +53,26 @@ sub instance { sub template { return $_[0]->{_template}; } sub cgi { return $_[0]->{_cgi}; } +sub dbh { return $_[0]->{_dbh}; } + +sub switch_to_shadow_db { + my $self = shift; + + if (!$self->{_dbh_shadow}) { + if (Param('shadowdb')) { + $self->{_dbh_shadow} = Bugzilla::DB::connect_shadow(); + } else { + $self->{_dbh_shadow} = $self->{_dbh_main}; + } + } + + $self->{_dbh} = $self->{_dbh_shadow}; +} + +sub switch_to_main_db { + my $self = shift; + $self->{_dbh} = $self->{_dbh_main}; +} # PRIVATE methods below here @@ -70,6 +92,9 @@ sub _new_instance { sub _init_persistent { my $self = shift; + # We're always going to use the main db, so connect now + $self->{_dbh} = $self->{_dbh_main} = Bugzilla::DB::connect_main(); + # Set up the template $self->{_template} = Bugzilla::Template->create(); } @@ -96,6 +121,11 @@ sub DESTROY { # may need special casing # under a persistent environment (ie mod_perl) $self->_cleanup; + + # Now clean up the persistent items + $self->{_dbh_main}->disconnect if $self->{_dbh_main}; + $self->{_dbh_shadow}->disconnect if + $self->{_dbh_shadow} and Param("shadowdb") } 1; @@ -189,4 +219,16 @@ The current C object. Note that modules should B be using this in general. Not all Bugzilla actions are cgi requests. Its useful as a convenience method for those scripts/templates which are only use via CGI, though. +=item C + +The current database handle. See L. + +=item C + +Switch from using the main database to using the shadow database. + +=item C + +Change the database object to refer to the main database. + =back -- cgit v1.2.3-24-g4f1b