[Rt-commit] r11156 - in rt/branches/3.8-TESTING: bin

ruz at bestpractical.com ruz at bestpractical.com
Fri Mar 21 23:39:15 EDT 2008


Author: ruz
Date: Fri Mar 21 23:39:09 2008
New Revision: 11156

Modified:
   rt/branches/3.8-TESTING/bin/standalone_httpd.in
   rt/branches/3.8-TESTING/lib/RT/Handle.pm

Log:
* add CheckIntegrity and CheckCompatibility methods to RT::Handle

Modified: rt/branches/3.8-TESTING/bin/standalone_httpd.in
==============================================================================
--- rt/branches/3.8-TESTING/bin/standalone_httpd.in	(original)
+++ rt/branches/3.8-TESTING/bin/standalone_httpd.in	Fri Mar 21 23:39:09 2008
@@ -60,10 +60,16 @@
 
 my $install_mode = 0;
 
-unless ( eval { RT::ConnectToDatabase(); } ) {
-    print "new install";
+require RT::Handle;
+my ($integrity, $state, $msg) = RT::Handle->CheckIntegrity;
+
+unless ( $integrity ) {
+    print STDERR "We couldn't connect to DB defined in your config.\n";
+    print STDERR "We think it's a new installtion, here is error:\n\n";
+    print STDERR "$msg\n\n";
     $install_mode = 1;
 } else {
+    RT::ConnectToDatabase();
     RT::InitSystemObjects();
     RT::InitClasses();
     RT::InitLogging();

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	Fri Mar 21 23:39:09 2008
@@ -189,9 +189,92 @@
     return $dsn;
 }
 
+=head2 Database compatibility and integrity checks
+
+
+
+=cut
+
+sub CheckIntegrity {
+    my $self = shift;
+    
+    my $dsn = $self->DSN;
+    my $user = RT->Config->Get('DatabaseUser');
+    my $pass = RT->Config->Get('DatabasePassword');
+
+    my $dbh = DBI->connect(
+        $dsn, $user, $pass,
+        { RaiseError => 0, PrintError => 0 },
+    );
+    unless ( $dbh ) {
+        return (0, 'no connection', "Failed to connect to $dsn as user '$user': ". $DBI::errstr);
+    }
+
+    RT::ConnectToDatabase();
+    RT::InitLogging();
+
+    require RT::CurrentUser;
+    my $test_user = new RT::CurrentUser;
+    $test_user->Load('RT_System');
+    unless ( $test_user->id ) {
+        return (0, 'no system user', "Couldn't find RT_System user in the DB '$dsn'");
+    }
+
+    $test_user = new RT::CurrentUser;
+    $test_user->Load('Nobody');
+    unless ( $test_user->id ) {
+        return (0, 'no nobody user', "Couldn't find Nobody user in the DB '$dsn'");
+    }
+
+    return $dbh;
+}
+
+sub CheckCompatibility {
+    my $self = shift;
+    my $dbh = shift;
+    my $state = shift || 'post';
+
+    my $db_type = RT->Config->Get('DatabaseType');
+    if ( $db_type eq "mysql" ) {
+        # Check which version we're running
+        my $version = ($dbh->selectrow_array("show variables like 'version'"))[1];
+        return (0, "couldn't get version of the mysql server")
+            unless $version;
+
+        ($version) = $version =~ /^(\d+\.\d+)/;
+        return (0, "RT is unsupported on MySQL versions before 4.0.x, it's $version")
+            if $version < 4;
+
+        # MySQL must have InnoDB support
+        my $innodb = ($dbh->selectrow_array("show variables like 'have_innodb'"))[1];
+        if ( lc $innodb eq "no" ) {
+            return (0, "RT requires that MySQL be compiled with InnoDB table support.\n".
+                "See http://dev.mysql.com/doc/mysql/en/InnoDB.html");
+        } elsif ( lc $innodb eq "disabled" ) {
+            return (0, "RT requires that MySQL InnoDB table support be enabled.\n".
+                "Remove the 'skip-innodb' line from your my.cnf file, restart MySQL, and try again.\n");
+        }
+
+        if ( $state eq 'post' ) {
+            my $create_table = $dbh->selectrow_arrayref("SHOW CREATE TABLE Tickets")->[1];
+            unless ( $create_table =~ /(?:ENGINE|TYPE)\s*=\s*InnoDB/i ) {
+                return (0, "RT requires that all its tables be of InnoDB type. Upgrade RT tables.");
+            }
+        }
+        if ( $version >= 4.1 && $state eq 'post' ) {
+            my $create_table = $dbh->selectrow_arrayref("SHOW CREATE TABLE Attachments")->[1];
+            unless ( $create_table =~ /\bContent\b[^,]*BLOB/i ) {
+                return (0, "RT since version 3.8 has new schema for MySQL versions after 4.1.0\n"
+                    ."Follow instructions in the UPGRADING.mysql file.");
+            }
+        }
+    }
+    return (1)
+}
+
 =head2 Database maintanance
 
-=head2 CreateDatabase $DBH
+=head3 CreateDatabase $DBH
 
 Creates a new database. This method can be used as class method.
 


More information about the Rt-commit mailing list