[Rt-commit] r5915 - in rt/branches/3.7-EXPERIMENTAL: .
ruz at bestpractical.com
ruz at bestpractical.com
Tue Sep 12 10:10:01 EDT 2006
Author: ruz
Date: Tue Sep 12 10:09:59 2006
New Revision: 5915
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in
Log:
r3720 at cubic-pc: cubic | 2006-09-12 18:19:37 +0400
* we was connecting too early with credentials from RT config
* add new function get_rt_handle_as_dba
* update docs
Modified: rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in Tue Sep 12 10:09:59 2006
@@ -96,8 +96,6 @@
}
require RT::Handle;
-my $Handle = RT::Handle->new($db_type);
-$Handle->BuildDSN;
my $dbh;
if ( $args{'action'} eq 'init' ) {
@@ -604,7 +602,7 @@
}
sub check_db_compatibility {
- if ( $db_type eq "mysql" ) {
+ if ( lc $db_type eq "mysql" ) {
# Check which version we're running
my ($version) = $dbh->selectrow_hashref("show variables like 'version'")->{Value} =~ /^(\d\.\d+)/;
if ( $version < 4 ) {
@@ -673,7 +671,7 @@
=head2 get_system_dsn
-Returns a dsn suitable for database creates and drops
+Returns a DSN suitable for database creates and drops
and user creates and drops.
=cut
@@ -697,11 +695,44 @@
return $dsn;
}
+=head2 get_system_dbh
+
+Returns L<DBI> database handle connected to B<system> with DBA credentials.
+
+See also L</get_system_dsn>.
+
+=cut
+
+sub get_system_dbh {
+ return _get_dbh( get_system_dsn(), $args{'dba'}, $args{'dba-password'} );
+}
+
+=head2 get_rt_dsn
+
+Returns DSN according to RT config.
+
+=cut
+
sub get_rt_dsn {
- require RT::Handle;
- $RT::Handle ||= RT::Handle->new;
- $RT::Handle->BuildDSN;
- return $RT::Handle->DSN;
+ my $rt_handle = RT::Handle->new;
+ $rt_handle->BuildDSN;
+ return $rt_handle->DSN;
+}
+
+=head2 get_rt_dbh [USER, PASSWORD]
+
+Returns L<DBI> database handle connected to RT database,
+you may specify credentials(USER and PASSWORD) to connect
+with. By default connects with credentials from RT config.
+
+=cut
+
+sub get_rt_dbh {
+ my ($user, $pass) = @_;
+ unless ( @_ ) {
+ ($user, $pass) = ($db_user, $db_pass);
+ }
+ return _get_dbh( get_rt_dsn, $user, $pass );
}
sub _get_dbh {
@@ -721,21 +752,10 @@
return $dbh;
}
-sub get_system_dbh {
- return _get_dbh( get_system_dsn(), $args{'dba'}, $args{'dba-password'} );
-}
-
-sub get_rt_dbh {
- my ($user, $pass) = @_;
- unless ( @_ ) {
- ($user, $pass) = ($db_user, $db_pass);
- }
- return _get_dbh( get_rt_dsn, $user, $pass );
-}
-
=head2 connect_rt_handle
-Returns connected C<$RT::Handle>, connect with credentials from RT config.
+Returns connected C<RT::Handle> object. Connects with credentials
+from RT config.Alos, inits C<$RT::Handle> global variable.
=cut
@@ -743,12 +763,34 @@
require RT::Handle;
- $RT::Handle ||= RT::Handle->new;
+ $RT::Handle = RT::Handle->new;
+ $RT::Handle->BuildDSN;
$RT::Handle->Connect;
return $RT::Handle;
}
+=head2 get_rt_handle_as_dba
+
+Returns connected C<$RT::Handle> object. Uses DBA's credentials.
+
+=cut
+
+sub get_rt_handle_as_dba {
+ require RT::Handle;
+ RT->Config->Set( DatabaseUser => $args{'dba'} );
+ RT->Config->Set( DatabasePassword => $args{'dba-password'} );
+
+ my $rt_handle = RT::Handle->new;
+ $rt_handle->BuildDSN;
+ $rt_handle->Connect;
+
+ RT->Config->Set( DatabaseUser => $db_user );
+ RT->Config->Set( DatabasePassword => $db_pass );
+
+ return $rt_handle;
+}
+
=head1 get_version_file
Takes base name of the file as argument, scans for <base name>-<version> named
@@ -764,7 +806,7 @@
return '' unless @files;
my %version = map { $_ =~ /\.\w+-([-\w\.]+)$/; ($1||0) => $_ } @files;
- my $db_version = connect_rt_handle()->DatabaseVersion;
+ my $db_version = get_rt_handle_as_dba()->DatabaseVersion;
print "Server version $db_version\n";
my $version;
foreach ( reverse sort cmp_version keys %version ) {
More information about the Rt-commit
mailing list