\r
my %options;\r
\r
-#if(need_upgrade() eq 1) {\r
-# dbupgrade();\r
-#}\r
-\r
sub export_options {\r
my ($writer) = (@_);\r
my ($sth);\r
return;\r
}\r
\r
-# Check if we need an upgrade\r
-sub need_upgrade {\r
- if(!defined($options{version})) { return 1; }\r
-\r
- if($options{version} ne $version) {\r
- return 1;\r
- } else {\r
- return 0;\r
- }\r
-}\r
-\r
-# Functions\r
-\r
sub get_option {\r
+ my ($name) = (@_);\r
+\r
if(keys (%options) == 0) {\r
- my $sql = "select name, value from $tbl_options";\r
- my $sth = $dbh->prepare($sql);\r
- $sth->execute() or die $DBI::errstr;\r
+ reload_options();\r
+ }\r
\r
- while(my $hr = $sth->fetchrow_hashref) {\r
- $options{$hr->{'name'}} = $hr->{'value'};\r
- }\r
+ # Determine if we need to upgrade the database\r
+ if($version ne $options{'version'}) {\r
+ print STDERR "Upgrading schema from $options{'version'} to $version.\n";\r
+ dbupgrade();\r
+ reload_options();\r
}\r
\r
- my ($name) = (@_);\r
return $options{$name};\r
}\r
\r
+sub reload_options {\r
+ my $sql = "select name, value from $tbl_options";\r
+ my $sth = $dbh->prepare($sql);\r
+ $sth->execute() or die $DBI::errstr;\r
+\r
+ while(my $hr = $sth->fetchrow_hashref) {\r
+ $options{$hr->{'name'}} = $hr->{'value'};\r
+ }\r
+}\r
+\r
# This configures the URLs in the application to support mod_rewrite or\r
# a webserver sans mod_rewrite.\r
if(get_option('use_rewrite') eq 'yes') {\r