[pLog-svn] r5158 - plog/trunk

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Mar 22 10:03:00 EDT 2007


Author: oscar
Date: 2007-03-22 10:02:59 -0400 (Thu, 22 Mar 2007)
New Revision: 5158

Modified:
   plog/trunk/wizard.php
Log:
I forgot to commit the changes to wizard.php in the previous commit (r5157)


Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2007-03-22 14:00:03 UTC (rev 5157)
+++ plog/trunk/wizard.php	2007-03-22 14:02:59 UTC (rev 5158)
@@ -9,7 +9,7 @@
     //
     // enable this for debugging purposes
     //
-    define( "DB_WIZARD_DEBUG", false );
+    define( "DB_WIZARD_DEBUG", true );
 
     //
     // in case you're having problems with time outs while upgrading (probably too
@@ -99,7 +99,7 @@
         $config = new ConfigFileStorage();
         // open a connection to the database
         //$db = NewADOConnection('mysql');
-        $db = PDb::getDriver('mysql');
+        $db = PDb::getDriver($config->getValue( "db_driver" ));
         
         if ( $selectDatabase ) {
             $res = $db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $config->getValue( "db_database" ), $config->getValue( "db_character_set" ));
@@ -320,23 +320,24 @@
         }
     }
        
-    class WizardMySQLFunctionsAvailableValidator extends WizardValidator
+    class WizardSQLFunctionsAvailableValidator extends WizardValidator
     {
-        function WizardMySQLFunctionsAvailableValidator()
+        function WizardSQLFunctionsAvailableValidator()
         {
-            $this->WizardValidator( "Checking if <b>MySQL</b> functions are available", 
+            $this->WizardValidator( "Checking if <b>MySQL</b> or <b>PostgreSQL</b> functions are available", 
                                     "LifeType requires support for MySQL to be part of your PHP installation",
                                     true );
         }
     
         function validate()
         {
-            $this->_valid = function_exists( "mysql_select_db" ) &&
+            $this->_valid = (function_exists( "mysql_select_db" ) &&
                             function_exists( "mysql_query" ) &&
                             function_exists( "mysql_connect" ) &&
                             function_exists( "mysql_fetch_assoc" ) &&
                             function_exists( "mysql_num_rows" ) &&
-                            function_exists( "mysql_free_result" );
+                            function_exists( "mysql_free_result" )) ||
+							(function_exists( "pg_query" ));
             return( parent::validate());                            
         }        
     }
@@ -482,7 +483,7 @@
             
             $checkGroups['PHP functions availability checking'] = Array(
                "sessions" => new WizardSessionFunctionsAvailableValidator(),
-               "mysql" => new WizardMySQLFunctionsAvailableValidator(),
+               "mysql" => new WizardSQLFunctionsAvailableValidator(),
                "xml" => new WizardXmlFunctionsAvailableValidator(),
                "iconv" => new WizardIconvFunctionsAvailableValidator(),
                "mbstring" => new WizardMbstringFunctionsAvailableValidator(),
@@ -602,6 +603,7 @@
             $this->registerFieldValidator( "dbUser", new StringValidator());
             $this->registerFieldValidator( "dbPassword",  new StringValidator(), true );
             $this->registerFieldValidator( "dbName", new StringValidator());
+            $this->registerFieldValidator( "dbDriver", new StringValidator());
             $this->registerFieldValidator( "dbPrefix", new StringValidator(), true );
             $errorView = new WizardView( "intro" );
             $errorView->setErrorMessage( "Some data was incorrect or missing." );
@@ -617,6 +619,7 @@
             $this->_dbName     = $this->_request->getValue( "dbName" );
             $this->_skipThis   = $this->_request->getValue( "skipDbInfo" );
             $this->_dbPrefix   = $this->_request->getValue( "dbPrefix", DEFAULT_DB_PREFIX );
+            $this->_dbDriver   = $this->_request->getValue( "dbDriver", DEFAULT_DB_PREFIX );
 
             // we should now save the data to the configuration file, just before
             // we read it
@@ -656,7 +659,8 @@
                 !$configFile->saveValue( "db_password", $this->_dbPassword ) ||
                 !$configFile->saveValue( "db_host", $this->_dbServer ) ||
                 !$configFile->saveValue( "db_database", $this->_dbName ) ||
-                !$configFile->saveValue( "db_prefix", $this->_dbPrefix )) {
+                !$configFile->saveValue( "db_prefix", $this->_dbPrefix ) ||
+				!$configFile->saveValue( "db_driver", $this->_dbDriver )) {
                 $errors = true;
             }
 
@@ -671,10 +675,15 @@
             else {
                 $connectionEsablished = false;
 
-                $this->_connection = @mysql_connect( $this->_dbServer, $this->_dbUser, $this->_dbPassword );
+				// load the database driver
+				$driver = PDb::getDriver( $this->_dbDriver );
+				
+				// and attempt to connect
+                $this->_connection = $driver->Connect( $this->_dbServer, $this->_dbUser, $this->_dbPassword );
                 if( $this->_connection ) {
                     $connectionEsablished = true;
-                } else {
+                } 
+				else {
                     $connectionEsablished = false;
                     $message = "There was an error connecting to the database. Please check your settings.";
                 }
@@ -686,12 +695,11 @@
                     return false;
                 } else {
                 	$this->_view = new WizardView( "step1" );
-	                $availableCharacterSets = $this->getAvailableCharacterSets();
-	                $defaultCharacterSet = $this->getDatabaseCharacterSet();
+	                $availableCharacterSets = $driver->getAvailableCharacterSets();
+	                $defaultCharacterSet = $driver->getDatabaseCharacterSet( $this->_dbName );
 	                $createDatabase = false;
-	                if( empty( $defaultCharacterSet ) )
-	                {
-	                	$defaultCharacterSet = $this->getServerCharacterSet();
+	                if( empty( $defaultCharacterSet ) ) {
+	                	$defaultCharacterSet = $driver->getServerCharacterSet();
 	                	$createDatabase = true;
 	                }
 	                $this->_view->setValue( "availableCharacterSets", $availableCharacterSets );
@@ -704,69 +712,6 @@
 	            }
             }
         }
-
-	    function getAvailableCharacterSets()
-	    {
-	        // check mysql version first. Version lower than 4.1 doesn't support utf8
-	        $serverVersion = mysql_get_server_info( $this->_connection );
-	        $version = explode( '.', $serverVersion );
-	        if ( $version[0] < 4 ) return false;
-	        if ( ( $version[0] == 4 ) && ( $version[1] == 0 ) ) return false;
-	        
-	        // check if utf8 support was compiled in
-	        $result = mysql_query( "SHOW CHARACTER SET", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows($result) > 0 ) {
-		            // iterate through resultset
-		            $availableCharacterSets = array();
-		            while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) )
-		            {
-						array_push( $availableCharacterSets, $row['Charset'] );
-		            }
-		            return $availableCharacterSets;
-		        }
-		    }
-	        return false;
-	    }
-	    
-	    function getDatabaseCharacterSet()
-	    {
-			if( !@mysql_select_db( $this->_dbName, $this->_connection ) ) {
-				return false;
-			}
-	        
-	        // We use a SHOW CREATE DATABASE command to show the original
-	        // SQL character set when DB was created.
-	        $result = mysql_query( "SHOW CREATE DATABASE `".$this->_dbName."`", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows( $result ) < 0 ) {
-		            // The specified db name is wrong!
-		            return false;
-		        }
-		        $dbInfo = mysql_fetch_row( $result );
-		        $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /';
-		        if( ( preg_match( $pattern, $dbInfo[1], $match ) > 0 ) ) {
-		            return $match[1];
-		        }
-		    }
-	        return false;
-	    }
-	
-	    function getServerCharacterSet(){
-	        // We use a SHOW CREATE DATABASE command to show the original
-	        // SQL character set when DB was created.
-	        $result = mysql_query( "SHOW VARIABLES LIKE 'character_set_server'", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows( $result ) > 0 ) {
-		            $row = mysql_fetch_array( $result, MYSQL_ASSOC );
-		            return $row['Value'];
-		        }
-			}
-	        return false;
-	    }
     }
 
     /**
@@ -792,6 +737,7 @@
             $view->setValue( "dbName", $configFile->getValue( "db_database" ));
             $view->setValue( "dbPrefix", $configFile->getValue( "db_prefix" ));
             $view->setValue( "dbCharacterSet", $configFile->getValue( "db_character_set" ));
+            $view->setValue( "dbDriver", $configFile->getValue( "db_driver" ));
             return true;
         }
 
@@ -914,7 +860,13 @@
                 // each table may need more than one sql query because of indexes, triggers, etc...
                 $ok = true;
                 foreach( $sqlarray as $sql ) {
-                    $ok = ( $ok && $this->_db->Execute( $sql ));
+					$ret = true;
+					if( !$this->_db->Execute( $sql )) {
+						$ret = false;
+						print("SQL query failed: ".$sql);
+						die();
+					}
+                    $ok = ( $ok && $ret);
                 }
                 
                 if( $ok )



More information about the pLog-svn mailing list