From fbe9a7a9a22004e3cc23a61b84148da8a0c300e9 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Tue, 15 Jun 2010 18:40:27 -0700 Subject: Bug 24896: Make the First/Last/Prev/Next navigation on bugs work with multiple buglists at once r=glob, a=mkanat --- Bugzilla/Util.pm | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'Bugzilla/Util.pm') diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 03826c143..840225fbe 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -37,7 +37,7 @@ use base qw(Exporter); css_class_quote html_light_quote url_decode i_am_cgi correct_urlbase remote_ip do_ssl_redirect_if_required use_attachbase - diff_arrays + diff_arrays on_main_db trim wrap_hard wrap_comment find_wrap_point format_time format_time_decimal validate_date validate_time datetime_from @@ -597,6 +597,14 @@ sub clean_text { return trim($dtext); } +sub on_main_db (&) { + my $code = shift; + my $original_dbh = Bugzilla->dbh; + Bugzilla->request_cache->{dbh} = Bugzilla->dbh_main; + $code->(); + Bugzilla->request_cache->{dbh} = $original_dbh; +} + sub get_text { my ($name, $vars) = @_; my $template = Bugzilla->template_inner; @@ -690,6 +698,11 @@ Bugzilla::Util - Generic utility functions for bugzilla validate_email_syntax($email); validate_date($date); + # DB-related functions + on_main_db { + ... code here ... + }; + =head1 DESCRIPTION This package contains various utility functions which do not belong anywhere @@ -994,3 +1007,20 @@ Make sure the date has the correct format and returns 1 if the check is successful, else returns 0. =back + +=head2 Database + +=over + +=item C + +Runs a block of code always on the main DB. Useful for when you're inside +a subroutine and need to do some writes to the database, but don't know +if Bugzilla is currently using the shadowdb or not. Used like: + + on_main_db { + my $dbh = Bugzilla->dbh; + $dbh->do("INSERT ..."); + } + +back -- cgit v1.2.3-24-g4f1b