[Rt-commit] r11098 - in rt/branches/3.8-TESTING: lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Tue Mar 18 10:54:05 EDT 2008
Author: ruz
Date: Tue Mar 18 10:53:48 2008
New Revision: 11098
Modified:
rt/branches/3.8-TESTING/lib/RT/Handle.pm
rt/branches/3.8-TESTING/sbin/rt-setup-database.in
Log:
* move errors handling into script
* API generalization
Modified: rt/branches/3.8-TESTING/lib/RT/Handle.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Handle.pm (original)
+++ rt/branches/3.8-TESTING/lib/RT/Handle.pm Tue Mar 18 10:53:48 2008
@@ -208,25 +208,28 @@
my $dbh = shift || die "No DBI handle provided";
my $db_type = RT->Config->Get('DatabaseType');
my $db_name = RT->Config->Get('DatabaseName');
- print "Creating $db_type database $db_name.\n";
+
+ my $status;
if ( $db_type eq 'SQLite' ) {
- return;
+ return (1, 'Skipped as SQLite doesn\'t need any action');
+ }
+ elsif ( $db_type eq 'Oracle' ) {
+ return (1, 'Skipped as we\'re working with Oracle');
}
elsif ( $db_type eq 'Pg' ) {
# XXX: as we get external DBH we don't know if RaiseError or PrintError
# are enabled, so we have to setup it here and restore them back
- $dbh->do("CREATE DATABASE $db_name WITH ENCODING='UNICODE'");
- if ( $DBI::errstr ) {
- $dbh->do("CREATE DATABASE $db_name") || die $DBI::errstr;
- }
+ $status = $dbh->do("CREATE DATABASE $db_name WITH ENCODING='UNICODE'")
+ || $dbh->do("CREATE DATABASE $db_name");
}
elsif ( $db_type eq 'Informix' ) {
local $ENV{'DB_LOCALE'} = 'en_us.utf8';
- $dbh->do("CREATE DATABASE $db_name WITH BUFFERED LOG");
+ $status = $dbh->do("CREATE DATABASE $db_name WITH BUFFERED LOG");
}
else {
- $dbh->do("CREATE DATABASE $db_name") or die $DBI::errstr;
+ $status = $dbh->do("CREATE DATABASE $db_name");
}
+ return ($status, $DBI::errstr);
}
=head3 DropDatabase $DBH [Force => 0]
Modified: rt/branches/3.8-TESTING/sbin/rt-setup-database.in
==============================================================================
--- rt/branches/3.8-TESTING/sbin/rt-setup-database.in (original)
+++ rt/branches/3.8-TESTING/sbin/rt-setup-database.in Tue Mar 18 10:53:48 2008
@@ -141,12 +141,10 @@
foreach my $action ( @actions ) {
if ( $action eq 'create' ) {
my $dbh = get_system_dbh();
- print "Now creating a database for RT.\n";
- if ( $db_type ne 'Oracle' || $dba_user ne $db_user ) {
- RT::Handle->CreateDatabase( $dbh );
- } else {
- print "...skipped as $dba_user is not $db_user or we're working with Oracle.\n";
- }
+ print "Now creating a $db_type database $db_name for RT.\n";
+ my ($status, $msg) = RT::Handle->CreateDatabase( $dbh );
+ die "Couldn't create a DB: $msg" unless $status;
+ print "Done.\n";
}
elsif ( $action eq 'drop' ) {
my $dbh = get_system_dbh();
@@ -162,7 +160,7 @@
$RT::Handle->dbh( $dbh );
print "Now populating database schema.\n";
- $RT::Handle->InsertSchema( $dbh, $args{'datadir'} );
+ $RT::Handle->InsertSchema( $dbh, $args{'datafile'} || $args{'datadir'} );
}
elsif ( $action eq 'acl' ) {
my $dbh = get_admin_dbh();
@@ -172,7 +170,7 @@
$RT::Handle->dbh( $dbh );
print "Now inserting database ACLs\n";
- $RT::Handle->InsertACL( $dbh, $args{'datadir'} ) # unless $db_type eq 'Oracle'
+ $RT::Handle->InsertACL( $dbh, $args{'datafile'} || $args{'datadir'} );
}
elsif ( $action eq 'coredata' ) {
$RT::Handle = new RT::Handle;
More information about the Rt-commit
mailing list