- fix: 7.4 Editing SQL Form seems to break site ...?
This commit is contained in:
parent
3c7bfb6595
commit
172985e2a0
6 changed files with 33 additions and 43 deletions
|
|
@ -137,14 +137,12 @@ sub db {
|
||||||
$self->{_dbh} = $self->session->db;
|
$self->{_dbh} = $self->session->db;
|
||||||
return $self->{_dbh};
|
return $self->{_dbh};
|
||||||
} elsif ($dsn =~ /\DBI\:\w+\:\w+/i) {
|
} elsif ($dsn =~ /\DBI\:\w+\:\w+/i) {
|
||||||
eval{
|
my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier);
|
||||||
$self->{_dbh} = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier);
|
unless (defined $dbh) {
|
||||||
};
|
$self->session->errorHandler->arn("Cannot connect to DatabaseLink [".$self->getId."]");
|
||||||
if ($@) {
|
|
||||||
$self->session->errorHandler->warn("DatabaseLink [".$self->getId."] ".$@);
|
|
||||||
} else {
|
|
||||||
return $self->{_dbh};
|
|
||||||
}
|
}
|
||||||
|
$self->{_dbh} = $dbh;
|
||||||
|
return $self->{_dbh};
|
||||||
} else {
|
} else {
|
||||||
$self->session->errorHandler->warn("DatabaseLink [".$self->getId."] The DSN specified is of an improper format.");
|
$self->session->errorHandler->warn("DatabaseLink [".$self->getId."] The DSN specified is of an improper format.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -317,12 +317,10 @@ sub connect {
|
||||||
my $user = shift;
|
my $user = shift;
|
||||||
my $pass = shift;
|
my $pass = shift;
|
||||||
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 });
|
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 });
|
||||||
|
|
||||||
unless (defined $dbh) {
|
unless (defined $dbh) {
|
||||||
$session->setDbNotAvailable;
|
$session->errorHandler->error("Couldn't connect to database: $dsn");
|
||||||
$session->errorHandler->fatal("Couldn't connect to database.");
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $dsn =~ /Oracle/ || $dsn =~ /ODBC/ ) { # Set specific attributes for long Oracle and ODBC DSNs
|
if ( $dsn =~ /Oracle/ || $dsn =~ /ODBC/ ) { # Set specific attributes for long Oracle and ODBC DSNs
|
||||||
$dbh->{LongReadLen} = 512 * 1024;
|
$dbh->{LongReadLen} = 512 * 1024;
|
||||||
$dbh->{LongTruncOk} = 1;
|
$dbh->{LongTruncOk} = 1;
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ Cleans up a WebGUI session information from memory and disconnects from any reso
|
||||||
|
|
||||||
sub close {
|
sub close {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->db->disconnect unless $self->dbNotAvailable;
|
$self->db->disconnect if (exists $self->{_db});
|
||||||
|
|
||||||
# Kill circular references. The literal list is so that the order
|
# Kill circular references. The literal list is so that the order
|
||||||
# can be explicitly shuffled as necessary.
|
# can be explicitly shuffled as necessary.
|
||||||
|
|
@ -158,16 +158,32 @@ sub datetime {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 db ( )
|
=head2 db ( [ skipFatal ] )
|
||||||
|
|
||||||
Returns a WebGUI::SQL object, which is connected to the WebGUI database.
|
Returns a WebGUI::SQL object, which is connected to the WebGUI database.
|
||||||
|
|
||||||
|
=head3 skipFatal
|
||||||
|
|
||||||
|
If set to true, we won't throw a fatal error, just return undef.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub db {
|
sub db {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $skipFatal = shift;
|
||||||
unless (exists $self->{_db}) {
|
unless (exists $self->{_db}) {
|
||||||
$self->{_db} = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
|
my $db = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
|
||||||
|
if (defined $db) {
|
||||||
|
$self->{_db} = $db;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($skipFatal) {
|
||||||
|
return undef
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->errorHandler->fatal("Couldn't connect to WebGUI database, and can't continue without it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $self->{_db};
|
return $self->{_db};
|
||||||
}
|
}
|
||||||
|
|
@ -618,28 +634,4 @@ sub var {
|
||||||
return $self->{_var};
|
return $self->{_var};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 setDbNotAvailable ( )
|
|
||||||
|
|
||||||
Sets a flag for this session indicating that database accesses are known to be probably broken and should not be performed.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub setDbNotAvailable {
|
|
||||||
my $self = shift;
|
|
||||||
$self->{_dbNotAvailable} = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
=head2 dbNotAvailable ( )
|
|
||||||
|
|
||||||
Returns true iff there is an error condition such that no database accesses should be attempted for this session whatsoever.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub dbNotAvailable {
|
|
||||||
my $self = shift;
|
|
||||||
return $self->{_dbNotAvailable};
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -609,7 +609,7 @@ Returns the timezone for this user, in DateTime::TimeZone format. Checks to mak
|
||||||
|
|
||||||
sub getTimeZone {
|
sub getTimeZone {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return 'America/Chicago' if $self->session->dbNotAvailable;
|
return 'America/Chicago' unless defined $self->session->db(1);
|
||||||
return $self->session->user->{_timeZone} if $self->session->user->{_timeZone};
|
return $self->session->user->{_timeZone} if $self->session->user->{_timeZone};
|
||||||
my @zones = @{DateTime::TimeZone::all_names()};
|
my @zones = @{DateTime::TimeZone::all_names()};
|
||||||
my $zone = $self->session->user->profileField('timeZone');
|
my $zone = $self->session->user->profileField('timeZone');
|
||||||
|
|
|
||||||
|
|
@ -208,15 +208,17 @@ sub fatal {
|
||||||
$self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace());
|
$self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace());
|
||||||
$self->session->http->sendHeader if ($self->session->request);
|
$self->session->http->sendHeader if ($self->session->request);
|
||||||
|
|
||||||
if ($self->session->dbNotAvailable) {
|
if (! defined $self->session->db(1)) {
|
||||||
# We can't even _determine_ whether we can show the debug text. Punt.
|
# We can't even _determine_ whether we can show the debug text. Punt.
|
||||||
$self->session->output->print("<h1>Fatal Internal Error</h1>");
|
$self->session->output->print("<h1>Fatal Internal Error</h1>");
|
||||||
} elsif ($self->canShowDebug()) {
|
}
|
||||||
|
elsif ($self->canShowDebug()) {
|
||||||
$self->session->output->print("<h1>WebGUI Fatal Error</h1><p>Something unexpected happened that caused this system to fault.</p>\n",1);
|
$self->session->output->print("<h1>WebGUI Fatal Error</h1><p>Something unexpected happened that caused this system to fault.</p>\n",1);
|
||||||
$self->session->output->print("<p>".$message."</p>\n",1);
|
$self->session->output->print("<p>".$message."</p>\n",1);
|
||||||
$self->session->output->print($self->getStackTrace(), 1);
|
$self->session->output->print($self->getStackTrace(), 1);
|
||||||
$self->session->output->print($self->showDebug(),1);
|
$self->session->output->print($self->showDebug(),1);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
# NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop.
|
# NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop.
|
||||||
$self->session->output->print("<h1>Problem With Request</h1>
|
$self->session->output->print("<h1>Problem With Request</h1>
|
||||||
We have encountered a problem with your request. Please use your back button and try again.
|
We have encountered a problem with your request. Please use your back button and try again.
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ Generates and sends HTTP headers for a response.
|
||||||
sub sendHeader {
|
sub sendHeader {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return undef if ($self->{_http}{noHeader});
|
return undef if ($self->{_http}{noHeader});
|
||||||
return $self->_sendMinimalHeader if $self->session->dbNotAvailable;
|
return $self->_sendMinimalHeader unless defined $self->session->db(1);
|
||||||
|
|
||||||
my ($request, $datetime, $config, $var) = $self->session->quick(qw(request datetime config var));
|
my ($request, $datetime, $config, $var) = $self->session->quick(qw(request datetime config var));
|
||||||
return undef unless $request;
|
return undef unless $request;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue