X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FUID.pm;h=3863256f80039d6925014272673422f0780d0dac;hp=9c52f08834e995f8eef285f9dcdbf0b91ebd4e64;hb=8d0e8149e7b19ad8543ac6c8c663be63dbc34762;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125 diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm index 9c52f0883..3863256f8 100644 --- a/FS/FS/UID.pm +++ b/FS/FS/UID.pm @@ -1,23 +1,21 @@ package FS::UID; +use base qw( Exporter ); use strict; use vars qw( - @ISA @EXPORT_OK $DEBUG $me $cgi $freeside_uid $conf_dir $cache_dir + @EXPORT_OK $DEBUG $me $cgi $freeside_uid $conf_dir $cache_dir $secrets $datasrc $db_user $db_pass $schema $dbh $driver_name - $AutoCommit %callback @callback $callback_hack $use_confcompat + $AutoCommit $ForceObeyAutoCommit %callback @callback $callback_hack ); use subs qw( getsecrets ); -use Exporter; use Carp qw( carp croak cluck confess ); -use DBI; +use FS::DBI; use IO::File; use FS::CurrentUser; -@ISA = qw(Exporter); @EXPORT_OK = qw( checkeuid checkruid cgi setcgi adminsuidsetup forksuidsetup - preuser_setup + preuser_setup load_schema getotaker dbh datasrc getsecrets driver_name myconnect - use_confcompat ); $DEBUG = 0; @@ -28,8 +26,17 @@ $freeside_uid = scalar(getpwnam('freeside')); $conf_dir = "%%%FREESIDE_CONF%%%"; $cache_dir = "%%%FREESIDE_CACHE%%%"; +# Code wanting to issue a COMMIT statement to the database is expected to +# obey the convention of checking this flag first. Setting $AutoCommit = 0 +# should (usually) suppress COMMIT statements. $AutoCommit = 1; #ours, not DBI -$use_confcompat = 1; + +# Not all methods obey $AutoCommit, by design choice. Setting +# $ForceObeyAutoCommit = 1 will override that design choice for: +# &FS::cust_main::Billing::collect +# &FS::cust_main::Billing::do_cust_event +$ForceObeyAutoCommit = 0; + $callback_hack = 0; =head1 NAME @@ -74,7 +81,6 @@ sub adminsuidsetup { sub forksuidsetup { my $user = shift; - my $olduser = $user; warn "$me forksuidsetup starting for $user\n" if $DEBUG; if ( $FS::CurrentUser::upgrade_hack ) { @@ -88,7 +94,7 @@ sub forksuidsetup { env_setup(); - db_setup($olduser); + db_setup(); callback_setup(); @@ -117,40 +123,33 @@ sub env_setup { } -sub db_setup { - my $olduser = shift; +sub load_schema { + warn "$me loading schema\n" if $DEBUG; + getsecrets() unless $datasrc; + use FS::Schema qw(reload_dbdef dbdef); + reload_dbdef("$conf_dir/dbdef.$datasrc") + unless $FS::Schema::setup_hack; +} +sub db_setup { croak "Not running uid freeside (\$>=$>, \$<=$<)\n" unless checkeuid(); warn "$me forksuidsetup connecting to database\n" if $DEBUG; - if ( $FS::CurrentUser::upgrade_hack && $olduser ) { - $dbh = &myconnect($olduser); - } else { - $dbh = &myconnect(); - } + $dbh = &myconnect(); + warn "$me forksuidsetup connected to database with handle $dbh\n" if $DEBUG; - warn "$me forksuidsetup loading schema\n" if $DEBUG; - use FS::Schema qw(reload_dbdef dbdef); - reload_dbdef("$conf_dir/dbdef.$datasrc") - unless $FS::Schema::setup_hack; + load_schema(); warn "$me forksuidsetup deciding upon config system to use\n" if $DEBUG; - if ( ! $FS::Schema::setup_hack && dbdef->table('conf') ) { + unless ( $FS::Schema::setup_hack ) { + #how necessary is this now that we're no longer possibly a pre-1.9 db? my $sth = $dbh->prepare("SELECT COUNT(*) FROM conf") or die $dbh->errstr; $sth->execute or die $sth->errstr; - my $confcount = $sth->fetchrow_arrayref->[0]; - - if ($confcount) { - $use_confcompat = 0; - }else{ - die "NO CONFIGURATION RECORDS FOUND"; - } + $sth->fetchrow_arrayref->[0] or die "NO CONFIGURATION RECORDS FOUND"; - } else { - die "NO CONFIGURATION TABLE FOUND" unless $FS::Schema::setup_hack; } @@ -173,14 +172,18 @@ sub callback_setup { } sub myconnect { - my $handle = DBI->connect( getsecrets(), { 'AutoCommit' => 0, - 'ChopBlanks' => 1, - 'ShowErrorStatement' => 1, - 'pg_enable_utf8' => 1, - #'mysql_enable_utf8' => 1, - } - ) - or die "DBI->connect error: $DBI::errstr\n"; + my $handle = FS::DBI->connect( + getsecrets(), + { + 'AutoCommit' => 0, + 'ChopBlanks' => 1, + 'ShowErrorStatement' => 1, + 'pg_enable_utf8' => 1, + # 'mysql_enable_utf8' => 1, + } + ) or die "FS::DBI->connect error: $FS::DBI::errstr\n"; + + $FS::Conf::conf_cache = undef; if ( $schema ) { use DBIx::DBSchema::_util qw(_load_driver ); #quelle hack @@ -219,7 +222,7 @@ sub install_callback { =item cgi -Returns the CGI (see L) object. +(Deprecated) Returns the CGI (see L) object. =cut @@ -229,9 +232,9 @@ sub cgi { $cgi; } -=item cgi CGI_OBJECT +=item setcgi CGI_OBJECT -Sets the CGI (see L) object. +(Deprecated) Sets the CGI (see L) object. =cut @@ -323,16 +326,6 @@ sub getsecrets { ($datasrc, $db_user, $db_pass); } -=item use_confcompat - -Returns true whenever we should use 1.7 configuration compatibility. - -=cut - -sub use_confcompat { - $use_confcompat; -} - =back =head1 CALLBACKS