Skip to content

Commit

Permalink
Check for contrib modules and error when creating or upgrading db
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/ledger-smb/code/branches/1.3@4215 4979c152-3d1c-0410-bac9-87ea11338e46
  • Loading branch information
einhverfr committed Dec 15, 2011
1 parent f1560bf commit d92cf7e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog for 1.3.10
* Fixes for POS cashier permissions. (Chris T)
* More Localization Fixes (Herman V)
* Customer/Vendor Search now shows records without credit accounts (Herman V)
* Better error handling contrib modules not found (Chris T)

Changelog for 1.3.9
* More logging enhancements (Herman V)
Expand Down
20 changes: 20 additions & 0 deletions LedgerSMB/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,26 @@ sub get_info {
return $retval;
}

=item $db->server_version();
Connects to the server and returns the version number in x.y.z format.
=cut

sub server_version {
my $self = shift @_;
my $creds = LedgerSMB::Auth->get_credentials();
my $dbh = DBI->connect(
"dbi:Pg:dbname=template1",
"$creds->{login}", "$creds->{password}", { AutoCommit => 0 }
);
my ($version) = $dbh->selectrow_array('SELECT version()');
$version =~ /(\d+\.\d+\.\d+)/;
my $retval = $1;
$dbh->disconnect;
return $retval;
}

=item $db->create();
Creates a database and loads the contrib files. This is done from template0,
Expand Down
19 changes: 19 additions & 0 deletions scripts/setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ sub login {
company_name => $request->{database},
password => $creds->{password}}
);
my $server_info = $database->server_version;
my @sv_info = split '.', $server_info;
if (($sv_info[0] > 9)or ($sv_info[0] == 9 and $sv_info[1] >= 1)){
if (! -f "$ENV{PG_CONTRIB_DIR}/tablefunc.control"){
$request->error($request->{_locale}->text(
'Cannot find Contrib scripts in [_1].',
$ENV{PG_CONTRIB_DIR}
));
}
} else {
if (! -f "$ENV{PG_CONTRIB_DIR}/tablefunc.sql"){
$request->error($request->{_locale}->text(
'Cannot find Contrib scripts in [_1].',
$ENV{PG_CONTRIB_DIR}
));

}
}

my $version_info = $database->get_info();
if(!$request->{dbh}){$request->{dbh}=$database->{dbh};}#allow upper stack to disconnect dbh when leaving
$request->{login_name} = $version_info->{username};
Expand Down

0 comments on commit d92cf7e

Please sign in to comment.