load database config from the config file in preference to Constants.pm
authorTony Cook <tony@develop-help.com>
Mon, 1 Mar 2010 05:29:57 +0000 (05:29 +0000)
committertony <tony@45cb6cf1-00bc-42d2-bb5a-07f51df49f94>
Mon, 1 Mar 2010 05:29:57 +0000 (05:29 +0000)
add BSE::API::bse_init() to initialize the database (and anything else
that needs it in the future)

adjust Squirrel::{Table,Row} to not fetch the db handle until runtime

adjust command-line scripts to use bse_init.

adjust BSE::Request to initialize the db

make datadump.pl require a logged in user

make the regen code pass the config to the shop gen

20 files changed:
localinst.perl
site/cgi-bin/admin/datadump.pl
site/cgi-bin/admin/makeIndex.pl
site/cgi-bin/bse.cfg
site/cgi-bin/modules/BSE/API.pm
site/cgi-bin/modules/BSE/DB.pm
site/cgi-bin/modules/BSE/DB/Mysql.pm
site/cgi-bin/modules/BSE/Request/Base.pm
site/cgi-bin/modules/Squirrel/Row.pm
site/cgi-bin/modules/Squirrel/Table.pm
site/cgi-bin/modules/Util.pm
site/util/bse_back.pl
site/util/bse_storage.pl
site/util/bsexlsprod.pl
site/util/gen.pl
site/util/initial.pl
site/util/loaddata.pl
site/util/update_title_summary.pl
site/util/upgrade_mysql.pl
t/t081cfg.t

index 39c0a49abaffde4d6b61ebea7efd233d3c65e004..00c058fa30a0ad20c2b733267411853645d11fdf 100644 (file)
@@ -67,10 +67,10 @@ close CON;
 my $dbuser = BSE::Test::test_dbuser();
 my $dbpass = BSE::Test::test_dbpass();
 
-$con =~ s/(^\$DSN = ')[^']*/$1 . BSE::Test::test_dsn()/me;
-$con =~ s/(^\$DBCLASS = ')[^']*/$1 . BSE::Test::test_dbclass()/me;
-$con =~ s/(^\$UN = ')[^']*/$1$dbuser/m;
-$con =~ s/(^\$PW = ')[^']*/$1$dbpass/m;
+#$con =~ s/(^\$DSN = ')[^']*/$1 . BSE::Test::test_dsn()/me;
+#$con =~ s/(^\$DBCLASS = ')[^']*/$1 . BSE::Test::test_dbclass()/me;
+#$con =~ s/(^\$UN = ')[^']*/$1$dbuser/m;
+#$con =~ s/(^\$PW = ')[^']*/$1$dbpass/m;
 $con =~ s/(^\$BASEDIR = ')[^']+/$1 . BSE::Test::base_dir/me;
 #$con =~ s/(^\$URLBASE = ["'])[^'"]+/$1 . BSE::Test::base_url/me;
 #$con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1 . BSE::Test::test_securl/me;
@@ -80,6 +80,7 @@ open CON, "> $instbase/cgi-bin/modules/Constants.pm"
 print CON $con;
 close CON;
 
+
 # rebuild the config file
 # first load values from the test.cfg file
 my $conffile = BSE::Test::test_conffile();
@@ -99,53 +100,26 @@ while (<TESTCONF>) {
 }
 
 $uploads = $conf{paths}{downloads};
-# fix bse.cfg
-open CFG, "< $instbase/cgi-bin/bse.cfg"
-  or die "Cannot open $instbase/cgi-bin/bse.cfg: $!";
-my $section = "";
-my @cfg;
-while (<CFG>) {
-  chomp;
-  if (/^\[(.*)\]\s*$/) {
-    my $newsect = lc $1;
-    if ($conf{$section} && keys %{$conf{$section}}) {
-      for my $key (sort keys %{$conf{$section}}) {
-       push @cfg, "$key=$conf{$section}{$key}";
-      }
-      delete $conf{$section};
-    }
-    $section = $newsect;
-  }
-  elsif (/^\s*(\w+)\s*=\s*.*$/ && exists $conf{$section}{lc $1}) {
-    my $key = lc $1;
-    print "found $section.$key\n";
-    $_ = "$key=$conf{$section}{$key}";
-    delete $conf{$section}{$key};
-  }
-  push @cfg, $_;
-}
-if ($conf{$section} && keys %{$conf{$section}}) {
-  for my $key (sort keys %{$conf{$section}}) {
-    push @cfg, "$key=$conf{$section}{$key}";
+# create installation config
+
+$conf{db}{class} = BSE::Test::test_dbclass();
+$conf{db}{dsn} = BSE::Test::test_dsn();
+$conf{db}{user} = $dbuser;
+$conf{db}{password} = $dbpass;
+
+open CFG, "> $instbase/cgi-bin/bse-install.cfg"
+  or die "Cannot create $instbase/cgi-bin/bse-install.cfg: $!";
+
+print CFG "; DO NOT EDIT - created during installation\n";
+for my $section_name (keys %conf) {
+  print CFG "[$section_name]\n";
+  my $section = $conf{$section_name};
+  for my $key (keys %$section) {
+    print CFG "$key=$section->{$key}\n";
   }
-  delete $conf{$section};
+  print CFG "\n";
 }
-for my $sect (keys %conf) {
-  if ($conf{$sect} && keys %{$conf{$sect}}) {
-    push @cfg, "[$sect]";
-    for my $key (sort keys %{$conf{$sect}}) {
-      push @cfg, "$key=$conf{$sect}{$key}";
-    }
-    push @cfg, "";
-  }
-}
-close CFG;
 
-open CFG, "> $instbase/cgi-bin/bse.cfg"
-  or die "Cannot create $instbase/cgi-bin/bse.cfg: $!";
-for my $line (@cfg) {
-  print CFG $line, "\n";
-}
 close CFG;
 
 -d $uploads 
index f391212bac85d3341befb561d848f0bd80a349fd..cfaaa90c33ea10c2f453b16169b45c5ad4890721 100755 (executable)
@@ -4,78 +4,99 @@ BEGIN { $ENV{DISPLAY} = '192.168.32.15:0.0' }
 use strict;
 use FindBin;
 use lib "$FindBin::Bin/../modules";
-use Constants qw($UN $PW $DSN $SHOP_FROM $DATA_EMAIL);
+use BSE::Request;
+use Constants qw($SHOP_FROM $DATA_EMAIL);
 use BSE::Mail;
-use BSE::Cfg;
 use DevHelp::HTML;
-my $cfg = BSE::Cfg->new;
-
-my $email = $cfg->entryIfVar('datadump', 'to') || $DATA_EMAIL;
-my $from = $cfg->entryIfVar('datadump', 'from') || $SHOP_FROM;
-my $urlbase = $cfg->entryVar('site', 'url');
-my $opts = '-t';
-my $dumper = $cfg->entryIfVar('datadump', 'mysqldump') || 'mysqldump';
-$|=1;
-print "Content-Type: text/html\n\n";
-
-unless ($email) {
-  print "Configuration Error: You need to set the <b>to</b> key in the [datadump] section of the config file, or \$DATA_EMAIL in Constants.pm";
-  exit;
-}
-unless ($from) {
-  print "Configuration Error: You need to set the <b>from</b> key in the [datadump] section of the config file, or \$SHOP_FROM in Constants.pm";
-  exit;
-}
 
-my $user = $UN;
-my $pass = $PW;
-my $data;
-my $host;
-my $port;
-if ($DSN =~ /^dbi:mysql:(\w+)$/i) {
-  $data = $1;
+my $req = BSE::Request->new;
+
+{
+  if (!$req->check_admin_logon) {
+    my $url = $req->url("logon", { m => "You must logon to dump the database" });
+    $req->output_result($req->get_refresh($url));
+  }
+  elsif (!$req->user_can("bse_datadump")) {
+    my $url = $req->url("menu", { m => "You don't have access to dump the database" });
+    $req->output_result($req->get_refresh($url));
+  }
+  else {
+    do_dump($req);
+  }
 }
-elsif ($DSN =~ /^dbi:mysql:(.*)$/i) {
-  my @entries = split /;/, $1;
-  for my $entry (@entries) {
-    if ($entry =~ /^hostname=(.+)$/i) {
-      $host = $1;
-    }
-    elsif ($entry =~ /^database=(.+)$/i) {
-      $data = $1;
+
+sub do_dump {
+  my ($req) = @_;
+
+  my $cfg = $req->cfg;
+  
+  my $email = $cfg->entryIfVar('datadump', 'to') || $DATA_EMAIL;
+  my $from = $cfg->entryIfVar('datadump', 'from') || $SHOP_FROM;
+  my $urlbase = $cfg->entryVar('site', 'url');
+  my $opts = '-t';
+  my $dumper = $cfg->entryIfVar('datadump', 'mysqldump') || 'mysqldump';
+  $|=1;
+  print "Content-Type: text/html\n\n";
+  
+  unless ($email) {
+    print "Configuration Error: You need to set the <b>to</b> key in the [datadump] section of the config file, or \$DATA_EMAIL in Constants.pm";
+    return;
+  }
+  unless ($from) {
+    print "Configuration Error: You need to set the <b>from</b> key in the [datadump] section of the config file, or \$SHOP_FROM in Constants.pm";
+    return;
+  }
+  
+  my $user = BSE::DB->dbuser($cfg);
+  my $pass = BSE::DB->dbpassword($cfg);
+  my $data;
+  my $host;
+  my $port;
+  my $dsn = BSE::DB->dsn($cfg);
+  if ($dsn =~ /^dbi:mysql:(\w+)$/i) {
+    $data = $1;
+  }
+  elsif ($dsn =~ /^dbi:mysql:(.*)$/i) {
+    my @entries = split /;/, $1;
+    for my $entry (@entries) {
+      if ($entry =~ /^hostname=(.+)$/i) {
+       $host = $1;
+      }
+      elsif ($entry =~ /^database=(.+)$/i) {
+       $data = $1;
+      }
+      elsif ($entry =~ /^port=(.+)$/i) {
+       $port = $1;
+      }
     }
-    elsif ($entry =~ /^port=(.+)$/i) {
-      $port = $1;
+    unless ($data) {
+      print "Sorry, could not find database in ",escape_html($dsn),"<br>\n";
+      return;
     }
   }
-  unless ($data) {
-    print "Sorry, could not find database in ",escape_html($DSN),"<br>\n";
+  else {
+    print "Sorry, this doesn't appear to be a mysql database<br>\n";
     exit;
   }
-}
-else {
-  print "Sorry, this doesn't appear to be a mysql database<br>\n";
-  exit;
-}
-
-for ($user, $pass, $data) {
-  s/(["\\`\$])/\\$1/;
-}
-my $cmd = qq!$dumper !;
-$cmd .= qq!-P$port ! if $port;
-$cmd .= qq!-h$host ! if $host;
-$cmd .= qq!"-u$user" "-p$pass" "$data"!;
-open DUMP, "$cmd 2>&1 |"
-  or do { print "Cannot open mysqldump: $!\n"; exit };
-
-my $boundary = "============_".time."_==========";
-my $headers = <<EOS;
+  
+  for ($user, $pass, $data) {
+    s/(["\\`\$])/\\$1/;
+  }
+  my $cmd = qq!$dumper !;
+  $cmd .= qq!-P$port ! if $port;
+  $cmd .= qq!-h$host ! if $host;
+  $cmd .= qq!"-u$user" "-p$pass" "$data"!;
+  open DUMP, "$cmd 2>&1 |"
+    or do { print "Cannot open mysqldump: $!\n"; exit };
+  
+  my $boundary = "============_".time."_==========";
+  my $headers = <<EOS;
 Content-Type: multipart/mixed;
     boundary="$boundary"
 MIME-Version: 1.0
 EOS
-
-my $body = <<EOS;
+  
+  my $body = <<EOS;
 
 This is a multipart message in MIME format
 
@@ -92,26 +113,27 @@ Content-Type: text/plain
 Content-Disposition: attachment; filename=bsedump.txt
 
 EOS
-while (<DUMP>) {
-  $body .= $_;
-}
+  while (<DUMP>) {
+    $body .= $_;
+  }
 
-$body .= <<EOS;
+  $body .= <<EOS;
 --$boundary--
 
 EOS
 
-my $mailer = BSE::Mail->new(cfg=>$cfg);
-$mailer->send(to=>$email,
-             from=>$from,
-             headers=>$headers,
-             body=>$body,
-             subject=>$cfg->entry('datadump') || "Data dump")
-  or print "Error sending email: ",escape_html($mailer->errstr),"<br>\n";
-unless (close DUMP) {
-  print "There may have been a problem retrieving the dump, please check the error log<br>";
+  my $mailer = BSE::Mail->new(cfg=>$cfg);
+  $mailer->send(to=>$email,
+               from=>$from,
+               headers=>$headers,
+               body=>$body,
+               subject=>$cfg->entry('datadump') || "Data dump")
+    or print "Error sending email: ",escape_html($mailer->errstr),"<br>\n";
+  unless (close DUMP) {
+    print "There may have been a problem retrieving the dump, please check the error log<br>";
+  }
+  print "Database dump for $urlbase sent to $email\n";
 }
-print "Database dump for $urlbase sent to $email\n";
 
 __END__
 
index ece9d050761b728bdc4de323a1ea3063f2ee75d9..c82c0335612d88ebdb14590cc62b188500d2c388 100755 (executable)
@@ -14,6 +14,7 @@ if ($in_cgi) {
 }
 
 my $cfg = BSE::Cfg->new;
+BSE::DB->init($cfg);
 my $urlbase = $cfg->entryVar('site', 'url');
 
 my $articles = 'Articles';
index 6be231de02c1b6c0bec78aa5ebe76df56a08a9cf..d8a0ed5b13c0fc37ecd9c056342e77f367ff0c4d 100644 (file)
@@ -424,6 +424,7 @@ shop=BSE::UI::AdminShop
 [includes]
 00bsecfg_d=bsecfg_d/
 50local=bse-local.cfg
+install=bse-install.cfg
 
 [mail resources]
 stylesheet=email/email.css,text/css,1
index eac740fb84e3ceddc20e3a12803cf3c5febe28d6..282b7ddb37563bca1314390fd3d023d68e39c2f3 100644 (file)
@@ -2,12 +2,14 @@ package BSE::API;
 use strict;
 use vars qw(@ISA @EXPORT_OK);
 use BSE::Util::SQL qw(sql_datetime now_sqldatetime);
+use BSE::DB;
 use BSE::Cfg;
 require Exporter;
 @ISA = qw(Exporter);
-@EXPORT_OK = qw(bse_cfg bse_make_product bse_make_catalog bse_encoding bse_add_image bse_add_step_child bse_add_owned_file bse_delete_owned_file bse_replace_owned_file bse_make_article bse_add_step_parent);
+@EXPORT_OK = qw(bse_init bse_cfg bse_make_product bse_make_catalog bse_encoding bse_add_image bse_add_step_child bse_add_owned_file bse_delete_owned_file bse_replace_owned_file bse_make_article bse_add_step_parent);
 use Carp qw(confess croak);
 use Fcntl qw(:seek);
+use Cwd;
 
 my %acticle_defaults =
   (
@@ -111,14 +113,30 @@ sub _finalize_article {
   }
 }
 
+my $cfg;
+
 sub bse_cfg {
-  my $cfg = BSE::Cfg->new;
+  my $path = shift || ".";
+  $cfg ||= BSE::Cfg->new(path => $path);
   $cfg->entry('site', 'url')
     or confess "Could not load configuration";
 
   return $cfg;
 }
 
+sub bse_init {
+  my ($bse_cgi) = @_;
+
+  defined $bse_cgi
+    or confess "Missing bse_cgi parameter";
+
+  unless ($cfg) {
+    bse_cfg($bse_cgi);
+  }
+
+  BSE::DB->init($cfg);
+}
+
 sub bse_make_product {
   my (%opts) = @_;
 
index 9427d1027d7a98ce6d334d05bd05257211023b8b..ca58075f78e77efcb8aa1a00e913c4d0726e17cb 100644 (file)
@@ -7,18 +7,78 @@ use Carp qw/confess/;
 use vars qw($VERSION);
 $VERSION = '1.00';
 
-use Constants qw/$DBCLASS/;
+my $single;
 
-my $file = $DBCLASS;
-$file =~ s!::!/!g;
-require "$file.pm";
+my $constants_loaded = eval {
+  require Constants;
+  1;
+};
+
+sub dsn {
+  my ($class, $cfg) = @_;
+
+  $cfg or confess "Missing cfg option";
+
+  return $cfg->entry("db", "dsn", $Constants::DSN);
+}
+
+sub dbuser {
+  my ($class, $cfg) = @_;
+
+  $cfg or confess "Missing cfg option";
+
+  return $cfg->entry("db", "user", $Constants::UN);
+}
+
+sub dbpassword {
+  my ($class, $cfg) = @_;
+
+  $cfg or confess "Missing cfg option";
+
+  return $cfg->entry("db", "password", $Constants::PW);
+}
+
+sub dbopts {
+  my ($class, $cfg) = @_;
+
+  $cfg or confess "Missing cfg option";
+
+  my $def_opts = $Constants::DBOPTS || {};
+
+  my $opts = $cfg->entry("db", "dbopts", $def_opts);
+  unless (ref $opts) {
+    my $work_opts = eval $opts;
+    $@
+      and confess "Error evaluation db options: $@";
+
+    $opts = $work_opts;
+  }
+
+  return $opts;
+}
+
+sub init {
+  my ($class, $cfg) = @_;
+
+  $single and return;
+
+  my $dbclass = $cfg->entry("db", "class", "BSE::DB::Mysql");
+  
+  my $file = $dbclass;
+  $file =~ s!::!/!g;
+  require "$file.pm";
+
+  $single = $dbclass->_single($cfg);
+}
 
 sub single {
-  $DBCLASS->_single();
+  $single
+    or confess "BSE::DB->init(\$cfg) needs to be called first";
+  $single;
 }
 
 sub startup {
-  $DBCLASS->_startup();
+  $single->_startup();
 }
 
 sub query {
index 8ebb7462dad3424bea0764c5c3a807ff2714863b..1cc1fac68fa89fdd13f0af965a20a23d06c414c3 100644 (file)
@@ -592,9 +592,16 @@ sub _startup {
 }
 
 sub _connect {
-  my $dbh = DBI->connect( $DSN, $UN, $PW, $DBOPTS)
+  my ($self) = @_;
+
+  my $cfg = $self->{cfg};
+  my $dsn = $self->dsn($cfg);
+  my $un = $self->dbuser($cfg);
+  my $pass = $self->dbpassword($cfg);
+  my $dbopts = $self->dbopts($cfg);
+  my $dbh = DBI->connect( $dsn, $un, $pass, $dbopts)
       or die "Cannot connect to database: $DBI::errstr";
-    
+
   # this might fail, but I don't care
   $dbh->do("set session sql_mode='ansi_quotes'");
 
@@ -603,14 +610,19 @@ sub _connect {
 
 sub _single
 {
-  my $class = shift;
+  my ($class, $cfg) = @_;
 
-  warn "Incorrect number of parameters passed to DatabaseHandle::single\n" unless @_ == 0;
+  warn "Incorrect number of parameters passed to BSE::DB::Mysql::single\n" unless @_ == 2;
   
   unless ( defined $self ) {
-    my $dbh = $class->_connect;
-
-    $self = bless { dbh => $dbh, birth => time() }, $class;
+    $self = bless 
+      { 
+       dbh => undef,
+       birth => time(),
+       cfg => $cfg,
+      }, $class;
+
+    $self->{dbh} = $self->_connect;
   }
   $self;
 }
index 802492cb04c2db4ab2d0dee0226b31bcf450c499..364366ae9b4a2b560d60432711dc2ca19db3a2b9 100644 (file)
@@ -8,9 +8,11 @@ use Carp qw(cluck confess);
 sub new {
   my ($class, %opts) = @_;
 
+  $opts{cfg} ||= BSE::Cfg->new;
+
+  BSE::DB->init($opts{cfg});
   BSE::DB->startup();
 
-  $opts{cfg} ||= BSE::Cfg->new;
   $opts{cgi} ||= $class->_make_cgi;
   $opts{fastcgi} ||= 0;
 
@@ -150,6 +152,13 @@ sub access_control {
   $_[0]->{cfg}->entry('basic', 'access_control', 0);
 }
 
+sub get_refresh {
+  my ($req, $url) = @_;
+
+  require BSE::Template;
+  BSE::Template->get_refresh($url, $req->cfg);
+}
+
 sub output_result {
   my ($req, $result) = @_;
 
index ce521d7eb77ea089f0cd3f0a45b3573c58e80871..21532111e19dfcf6f6bbe422e4b11ffe83a9000f 100644 (file)
@@ -7,7 +7,7 @@ use BSE::DB;
 
 my %methods_created;
 
-my $dh = BSE::DB->single;
+my $dh;
 
 sub new {
   my ($class, @values) = @_;
@@ -26,6 +26,7 @@ sub new {
 
   @$self{@columns} = @values;
   
+  $dh ||= BSE::DB->single;
   unless (defined $self->{$primary[0]}) {
     my $bases = $class->bases;
     if (keys %$bases) {
@@ -109,6 +110,7 @@ sub save {
   my $self = shift;
   my %saved;
   my $bases = $self->bases;
+  $dh ||= BSE::DB->single;
   if (keys %$bases) {
     my @bases = $self->_get_bases;
     my $base_base = $bases[0];
@@ -166,6 +168,7 @@ sub save {
 sub remove {
   my $self = shift;
 
+  $dh ||= BSE::DB->single;
   my $bases = $self->bases;
   my @primary = @$self{$self->primary};
   if (keys %$bases) {
index 3368b64365bc8c6a196850eb344f6024d1238e10..c7e93558ca566d2b95d4a7934005e1dfe2ba0957 100644 (file)
@@ -8,11 +8,11 @@ $VERSION = "0.11";
 
 use BSE::DB;
 
-my $dh = BSE::DB->single;
-
 my %query_cache;
 my $cache_queries;
 
+my $dh;
+
 # no caching is performed if this is zero
 my $cache_timeout = 2; # seconds
 
@@ -33,6 +33,7 @@ sub new {
       && defined $cache{$class}{time}
       && $cache{$class}{time}+$cache_timeout >= time;
 
+  $dh ||= BSE::DB->single;
   my $sth = $dh->stmt($class)
     or confess "No $class member in DatabaseHandle";
   $sth->execute
@@ -85,6 +86,7 @@ sub getByPkey {
     }
   }
 
+  $dh ||= BSE::DB->single;
   my $result;
   if (ref($self)) {
     $result = $self->{coll}{join "", @values};
@@ -182,6 +184,7 @@ sub getBy {
     $vals{$col} = $val;
   }
 
+  $dh ||= BSE::DB->single;
   my @results;
   if (ref($self) && UNIVERSAL::isa($self, __PACKAGE__)) {
     # this is an object with the rows already loaded
@@ -241,6 +244,7 @@ sub _getBy_sth {
     " from " . $self->rowClass->table .
       " where " . join(" and ", @conds);
 
+  $dh ||= BSE::DB->single;
   my $sth = $dh->{dbh}->prepare($sql)
     or confess "Cannot prepare generated $sql: ", $dh->{dbh}->errstr;
 
@@ -270,6 +274,7 @@ sub getColumnsBy {
     " from " . $self->rowClass->table .
       " where " . join(" and ", @conds);
 
+  $dh ||= BSE::DB->single;
   my $sth = $dh->{dbh}->prepare($sql)
     or confess "Cannot prepare generated $sql: ", $dh->{dbh}->errstr;
 
@@ -302,6 +307,7 @@ sub getSpecial {
 
   my $rowClass = $self->rowClass;
   my $sqlname = $class . "." . $name;
+  $dh ||= BSE::DB->single;
   my $sth = $dh->stmt($sqlname)
     or confess "No $sqlname in database object";
   $sth->execute(@args)
@@ -324,6 +330,7 @@ sub doSpecial {
 
   my $class = ref $self ? ref $self : $self;
   my $sqlname = $class . "." . $name;
+  $dh ||= BSE::DB->single;
   my $sth = $dh->stmt($sqlname)
     or confess "No $sqlname in database object";
   $sth->execute(@args)
@@ -346,6 +353,7 @@ sub all {
 sub query {
   my ($self, $columns, $query, $opts) = @_;
 
+  $dh ||= BSE::DB->single;
   $dh->generate_query($self->rowClass, $columns, $query, $opts);
 }
 
index d5a8e6c66cc156708458ab7d02a1056051e9f5b5..7918ae3bf9fff01bd99f960a9bf107a72789435a 100644 (file)
@@ -117,14 +117,13 @@ sub generate_search {
 }
 
 sub generate_shop {
-  my ($articles) = @_;
+  my ($articles, $cfg) = @_;
   my @pages =
     (
      'cart', 'checkoutnew', 'checkoutfinal', 'checkoutcard', 'checkoutconfirm',
      'checkoutpay',
     );
   require 'Generate/Article.pm';
-  my $cfg = BSE::Cfg->new;
   my $shop_base = $articles->getByPkey($SHOPID);
   my $shop = { map { $_ => $shop_base->{$_} } $shop_base->columns };
   $shop->{link} =~ /^\w+:/
@@ -269,7 +268,7 @@ sub generate_all {
   generate_search($articles, $cfg);
 
   $callback->("Generating shop base pages") if $callback;
-  generate_shop($articles);
+  generate_shop($articles, $cfg);
 
   $callback->("Generating extra pages") if $callback;
   generate_extras($articles, $cfg, $callback);
@@ -308,7 +307,7 @@ sub regen_and_refresh {
          generate_search($articles, $cfg);
          
          $progress->("Generating shop base pages") if $progress  ;
-         generate_shop($articles);
+         generate_shop($articles, $cfg);
          
          $progress->("Generating extra pages") if $progress;
          generate_extras($articles, $cfg, $progress);
index e9bcbaaa71cc31355d39d288666682f3947b44ee..d7f32a5d79f981eeb3034179b204c172311a969c 100644 (file)
@@ -3,15 +3,14 @@ use strict;
 use warnings;
 use FindBin;
 use lib "$FindBin::Bin/../cgi-bin/modules";
+use BSE::API qw(bse_init bse_cfg);
 use BSE::Cfg;
 use BSE::TB::BackgroundTasks;
 use Getopt::Long;
 
 {
-  chdir "$FindBin::Bin/../cgi-bin"
-    or warn "Could not change to cgi-bin directory: $!\n";
-  
-  my $cfg = BSE::Cfg->new;
+  bse_init("../cgi-bin");
+  my $cfg = bse_cfg();
 
   my $cmd = shift
     or usage();
index d6d7712a8ee2e961d5bafc0207e961e31956327b..b8fef3126ffe85c40c8b89134c6d7c221ecf338e 100644 (file)
@@ -2,11 +2,11 @@
 use strict;
 use FindBin;
 use lib "$FindBin::Bin/../cgi-bin/modules";
-use BSE::Cfg;
 use BSE::StorageMgr::Images;
 use BSE::StorageMgr::Files;
 use BSE::StorageMgr::Thumbs;
 use Getopt::Long;
+use BSE::API qw(bse_init bse_cfg);
 
 my $verbose;
 my $noaction;
@@ -14,10 +14,9 @@ my $noaction;
 GetOptions("v", \$verbose,
           'n', \$noaction);
 
-chdir "$FindBin::Bin/../cgi-bin"
-  or warn "Could not change to cgi-bin directory: $!\n";
+bse_init("../cgi-bin");
 
-my $cfg = BSE::Cfg->new;
+my $cfg = bse_cfg();
 
 my $images = BSE::StorageMgr::Images->new(cfg => $cfg);
 my $files = BSE::StorageMgr::Files->new(cfg => $cfg);
index fb5e8f6aebb9528a39fd6c63054f5a5f60813b60..f9cc73deacc58070e60ae450d7dc66d7a6fc1de6 100644 (file)
@@ -4,12 +4,11 @@ use Getopt::Long;
 use FindBin;
 use lib "$FindBin::Bin/../cgi-bin/modules";
 use BSE::Cfg;
-use BSE::API qw(bse_cfg bse_make_product bse_encoding);
+use BSE::API qw(bse_init bse_cfg bse_make_product bse_encoding);
 use BSE::Importer;
 use Carp qw(confess);
 
-chdir "$FindBin::Bin/../cgi-bin"
-  or warn "Could not change to cgi-bin directory: $!\n";
+bse_init("../cgi-bin");
 
 my $verbose;
 my $delete;
index 179f0860e3831411466090112b36f33cb4d45b7b..f1033121a53e1bb20ca81078c64748eb445d67d5 100644 (file)
@@ -4,18 +4,18 @@ use Getopt::Long;
 use FindBin;
 use lib "$FindBin::Bin/../cgi-bin/modules";
 use Util qw/generate_all generate_article/;
-use BSE::Cfg;
+use BSE::API qw(bse_init bse_cfg);
 use Articles;
 
-chdir "$FindBin::Bin/../cgi-bin"
-  or warn "Could not change to cgi-bin directory: $!\n";
+bse_init("../cgi-bin");
+
 Getopt::Long::Configure('bundling');
 my $verbose;
 my $article;
 GetOptions("v", \$verbose);
 $verbose = defined $verbose;
 
-my $cfg = BSE::Cfg->new;
+my $cfg = bse_cfg();
 
 my $articles = 'Articles';
 
index 36747d51837fae2e083f8c88776647923f016bd3..f816a4397a3049159ae2f172277432cec554d8d1 100644 (file)
@@ -7,12 +7,11 @@ use lib '../cgi-bin/modules';
 use DBI;
 use Article;
 use Constants qw($DSN $UN $PW $CGI_URI $SHOP_URI $ROOT_URI);
-use BSE::Cfg;
+use BSE::API qw(bse_init bse_cfg);
 use BSE::Util::SQL qw(now_sqldate now_sqldatetime);
 
-chdir "../cgi-bin"
-  or warn "Could not change to cgi-bin directory - may not be able to get config file";
-my $cfg = BSE::Cfg->new;
+bse_init("../cgi-bin");
+my $cfg = bse_cfg();
 my $securlbase = $cfg->entryVar('site', 'secureurl');
 my $nowDate = now_sqldate();
 my $nowDatetime = now_sqldatetime();
@@ -565,7 +564,7 @@ EOS
    },
   );
 
-my $dbh = DBI->connect($DSN, $UN, $PW)
+my $dbh = BSE::DB->single->dbh
   or die "Cannot connect to database: ",DBI->errstr;
 my @columns = Article->columns;
 $dbh->do('delete from article')
index 967b3cf6867d846e3727f02cc8d4102cec3c9884..8918ea77da570a11265998acc23dff70eb15ea85 100644 (file)
@@ -4,18 +4,23 @@ use lib '../cgi-bin/modules';
 use DevHelp::LoaderData;
 use DBI;
 use Constants;
+use BSE::API qw(bse_cfg bse_init);
+use BSE::DB;
+use Cwd;
+
+bse_init("../cgi-bin");
+
+my $cfg = bse_cfg;
 
 my $datadir = shift
   or die "Usage: $0 directoryname\n";
 
-my $dsn = $Constants::DSN;
-my $dbuser = $Constants::UN;
-my $dbpass = $Constants::PW;
-
 # this is pretty rough, but good enough for now
-my $dbh = DBI->connect($dsn, $dbuser, $dbpass)
+my $dbh = BSE::DB::single->dbh
   or die "Cannot connect to database: ",DBI->errstr;
 
+my $dbuser = BSE::DB->dbuser($cfg);
+
 my %tables;
 opendir DATADIR, $datadir or die "Cannot open '$datadir' directory: $!";
 while (my $inname = readdir DATADIR) {
index 25d64050f2078a2f16e1841432b8601570152cb7..1f878d80c358cb12ebfa0d01b621b65ffa446f93 100644 (file)
@@ -3,12 +3,11 @@ use strict;
 use Getopt::Long;
 use FindBin;
 use lib "$FindBin::Bin/../cgi-bin/modules";
-use BSE::Cfg;
+use BSE::API qw(bse_init bse_cfg);
 use BSE::TB::Orders;
 use Products;
 
-chdir "$FindBin::Bin/../cgi-bin"
-  or warn "Could not change to cgi-bin directory: $!\n";
+bse_init("../cgi-bin");
 
 my @orders = BSE::TB::Orders->all;
 my %products;
index b929aec7622d21c4a03e3950ac7a5ab103f34f18..5bb7c652d4020c9b3c225173b429ee61e350ad05 100644 (file)
@@ -4,6 +4,10 @@ use lib '../cgi-bin/modules';
 use DBI;
 use BSE::DB;
 use Getopt::Long;
+use BSE::API qw(bse_init);
+use Cwd;
+
+bse_init("../cgi-bin");
 
 my $verbose;
 my $pretend;
@@ -41,7 +45,7 @@ EOS
   my $entered = <STDIN>;
   chomp $entered;
   if ($entered ne $conf) {
-    print "Either you didn't backup your data of you didn't read the message.\n";
+    print "Either you didn't backup your data or you didn't read the message.\n";
     exit;
   }
 }
@@ -49,7 +53,7 @@ EOS
 my $db = BSE::DB->single;
 
 UNIVERSAL::isa($db, 'BSE::DB::Mysql')
-  or die "Sorry, this only works for Mysql databases\n";
+  or die "Sorry, this only works for Mysql databases ($db)\n";
 
 open STRUCT, "< $input"
   or die "Cannot open structure file $input: $!\n";
index dfc19b2d04b5b6f485844572bb871b00adb5374f..b08a3c55c9cf77a4a8c51e089e161fc9cf8992dd 100644 (file)
@@ -8,10 +8,10 @@ BEGIN {
     or plan skip_all => "Cannot load BSE::Cfg";
 }
 
-plan tests => 10;
+plan tests => 9;
 
-ok(chdir "t/cfg", "chdir to cfg dir");
-my $cfg = eval { BSE::Cfg->new };
+#ok(chdir "t/cfg", "chdir to cfg dir");
+my $cfg = eval { BSE::Cfg->new(path => "t/cfg") };
 ok($cfg, "made a config");
 is($cfg->entry("alpha", "beta"), "one", "check simple lookup");
 is($cfg->entryVar("var", "varb"), "ab", "simple variable lookup");