From 19ffadce2c1f5eadacb2254401a40f50d740f35a Mon Sep 17 00:00:00 2001 From: Luke Reeves Date: Sun, 12 Jul 2009 10:58:50 -0400 Subject: [PATCH] Fix for Perl 5.10 reload module bheaviour. Basically the installation for the database was moved to a standalone module that can be safely invoked from the main insipid.cgi stub. --- insipid.cgi | 7 ++-- lib/Insipid/DBInstall.pm | 82 ++++++++++++++++++++++++++++++++++++++++ lib/Insipid/Database.pm | 35 ----------------- 3 files changed, 86 insertions(+), 38 deletions(-) create mode 100755 lib/Insipid/DBInstall.pm diff --git a/insipid.cgi b/insipid.cgi index d1627f5..87160f8 100755 --- a/insipid.cgi +++ b/insipid.cgi @@ -23,7 +23,6 @@ use warnings; use strict; # This stub checks for libraries and what not and then calls the main program. -push(@INC, "lib"); if(!-e "insipid-config.cgi") { # TODO: Better error message here. @@ -33,6 +32,7 @@ if(!-e "insipid-config.cgi") { eval { + push(@INC, "lib"); require Insipid::Main; Insipid::Main::main(); }; @@ -60,8 +60,9 @@ if($@) { # tables were not found. undef($@); eval { - require Insipid::Database; - Insipid::Database::install(); + push(@INC, "lib"); + require Insipid::DBCreate; + Insipid::DBInstall::install(); }; if($@) { diff --git a/lib/Insipid/DBInstall.pm b/lib/Insipid/DBInstall.pm new file mode 100755 index 0000000..1d726dc --- /dev/null +++ b/lib/Insipid/DBInstall.pm @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# +# Copyright (C) 2008 Luke Reeves +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# + +package Insipid::DBInstall; + +use strict; +use warnings; + +use Insipid::Config; +use Insipid::Schemas; + +use DBI qw/:sql_types/;; +use vars qw($version); + +use Exporter (); +our (@ISA, @EXPORT); + +@ISA = qw(Exporter); +@EXPORT = qw(install); + +sub install { + my ($sth, $dbname, $dbuser, $dbpass, $dbtype, $dsn, $dbh, @creates); + + $dbname = getconfig('dbname'); + $dbuser = getconfig('dbuser'); + $dbpass = getconfig('dbpass'); + + if(defined(getconfig('dbtype'))) { + $dbtype = getconfig('dbtype'); + } else { + $dbtype = 'mysql'; + } + + $dsn = "DBI:$dbtype:dbname=$dbname;host=localhost"; + $dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::errstr; + + print "Content-Type: text/html\r\n\r\n"; + print "Insipid Installation"; + + print "

Creating tables..."; + + if($dbtype eq 'mysql') { + @creates = split(/\;/, $createMySQL); + } else { + @creates = split(/\;/, $createPostgres); + } + + foreach(@creates) { + my $sql = $_; + if(length($sql) > 2) { + $sth = $dbh->prepare($sql); + $sth->execute() or print "
Error executing \"$sql\" - $DBI::errstr
"; + } + } + print " done!

"; + + print "

Insipid's database has been installed. You can reload this " . + "page to start using Insipid.

"; + + print ""; + +} + +1; +__END__ diff --git a/lib/Insipid/Database.pm b/lib/Insipid/Database.pm index d7d1275..bfbd336 100755 --- a/lib/Insipid/Database.pm +++ b/lib/Insipid/Database.pm @@ -78,8 +78,6 @@ sub export_options { } sub dbupgrade { - print STDERR "Upgrading Insipid database...\n"; - my $sql = "update $tbl_options set value = ? where (name = ?)"; my $sth = $dbh->prepare($sql); $sth->execute($version, 'version'); @@ -131,45 +129,12 @@ sub get_option { while(my $hr = $sth->fetchrow_hashref) { $options{$hr->{'name'}} = $hr->{'value'}; } - $sth->close(); } my ($name) = (@_); return $options{$name}; } -sub install { - my ($sth, @creates); - - print STDERR "Performing database installation.\n"; - - print "Content-Type: text/html\r\n\r\n"; - print "Insipid Installation"; - - print "

Creating tables..."; - - if($dbtype eq 'mysql') { - @creates = split(/\;/, $createMySQL); - } else { - @creates = split(/\;/, $createPostgres); - } - - foreach(@creates) { - my $sql = $_; - if(length($sql) > 2) { - $sth = $dbh->prepare($sql); - $sth->execute() or print "
Error executing \"$sql\" - $DBI::errstr
"; - } - } - print " done!

"; - - print "

Insipid's database has been installed. You can reload this " . - "page to start using Insipid.

"; - - print ""; - -} - # This configures the URLs in the application to support mod_rewrite or # a webserver sans mod_rewrite. if(get_option('use_rewrite') eq 'yes') { -- 2.39.5