my $_dbh;
my $_dbh_main;
my $_dbh_shadow;
-
sub dbh {
my $class = shift;
return $_dbh;
}
+sub dbwritesallowed {
+ my $class = shift;
+
+ # We can write if we are connected to the main database.
+ # Note that if we don't have a shadowdb, then we claim that its ok
+ # to write even if we're nominally connected to the shadowdb.
+ # This is OK because this method is only used to test if misc
+ # updates can be done, rather than anything complicated.
+ return $class->dbh == $_dbh_main;
+}
+
sub switch_to_shadow_db {
my $class = shift;
The current database handle. See L<DBI>.
+=item C<dbwritesallowed>
+
+Determines if writes to the database are permitted. This is usually used to
+determine if some general cleanup needs to occur (such as clearing the token
+table)
+
=item C<switch_to_shadow_db>
Switch from using the main database to using the shadow database.
# This seems like as good as time as any to get rid of old
# crufty junk in the logincookies table. Get rid of any entry
# that hasn't been used in a month.
- if ($::dbwritesallowed) {
+ if (Bugzilla->dbwritesallowed) {
SendSQL("DELETE FROM logincookies " .
"WHERE TO_DAYS(NOW()) - TO_DAYS(lastused) > 30");
}
}
# Update the timestamp on our logincookie, so it'll keep on working.
- if ($::dbwritesallowed) {
+ if (Bugzilla->dbwritesallowed) {
SendSQL("UPDATE logincookies SET lastused = null " .
"WHERE cookie = $::COOKIE{'Bugzilla_logincookie'}");
}
}
if (time() - $mtime > 3600) {
use Token;
- Token::CleanTokenTable() if $::dbwritesallowed;
+ Token::CleanTokenTable() if Bugzilla->dbwritesallowed;
GenerateVersionTable();
}
require 'data/versioncache';