[pLog-svn] r610 - plog/trunk

ork at devel.plogworld.net ork at devel.plogworld.net
Wed Dec 29 18:34:32 GMT 2004


Author: ork
Date: 2004-12-29 18:34:31 +0000 (Wed, 29 Dec 2004)
New Revision: 610

Modified:
   plog/trunk/wizard.php
Log:
the wizard does now check whether we are unable to connect to the
dbm or we're unable to select the database. 

other changes:
- few formatting
- added $v->getVersion() to the intro template
- added the parameter $selectDatabase the dbConnect(), so we can connect
  without selecting a database.



Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2004-12-29 17:42:49 UTC (rev 609)
+++ plog/trunk/wizard.php	2004-12-29 18:34:31 UTC (rev 610)
@@ -531,15 +531,19 @@
 	/**
 	 * Open a connection to the database
 	 */
-     function connectDb( $ignoreError = false )
+     function connectDb( $ignoreError = false , $selectDatabase = true )
      {
         $config = new ConfigFileStorage();
         // open a connection to the database
         $db = NewADOConnection( 'mysql' );
-        $res = $db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $config->getValue( "db_database" ));
+        if ( $selectDatabase ) {
+            $res = $db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $config->getValue( "db_database" ));
+        } else {
+            $res = $db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ));
+        }
 		
-		if( DB_WIZARD_DEBUG )
-			$db->debug = true;
+        if( DB_WIZARD_DEBUG )
+            $db->debug = true;
 
         // return error
         if( $ignoreError )
@@ -605,7 +609,8 @@
 
             //$t = new Template( $templateFileName, "" );
             $t = new Smarty();
-            $this->_params->setValue( "version", new Version());
+            $v = new Version();
+            $this->_params->setValue( "version", $v->getVersion());
             $t->assign( $this->_params->getAsArray());
             $t->template_dir    = "./templates";
             $t->compile_dir     = TEMP_FOLDER;
@@ -686,6 +691,9 @@
             // we read it
             $configFile = new ConfigFileStorage();
 
+            // we expect everything to be fine
+            $errors = false;
+
             // before doing anything, we should check of the configuration file is
             // writable by this script, or else, throw an error and bail out gracefully
             $configFileName = $configFile->getConfigFileName();
@@ -760,19 +768,35 @@
 
             // only check for errors in case the database table should already exist!
             if( !$createDb ) {
+                $connectionEsablished = false;
+
+                // Lets check the 'everything is fine' case first.. 
                 $this->_db = connectDb();
-                if( !$this->_db ) {                
+                if( $this->_db ) {                
+                     $connectionEsablished = true;
+                } else {
+                     $connectionEsablished = false;
+                     $errorMessage = "There was an error selecting the database. Please verify the database was already created or check the 'Create database' checkbox.";
+                }
+
+                // We were unable to connect to the db and select the right db.. lets try
+                // just to connect.. maybe the database needs to be created (even though the
+                // user did not check the appropriate box).
+                if ( !$connectionEsablished ) {
+                    $this->_db = connectDb( true, false );
+                    if( !$this->_db ) {                
+                         $errorMessage = "There was an error connecting to the database. Please check your settings.";
+                    }
+                }
+
+                if ( !$connectionEsablished ) {
                     $this->_view = new WizardView( "step1" );
                     $this->setDbConfigValues( $this->_view );
-                    $this->_view->setErrorMessage("There was an error connecting to the database. Please check your settings." );                    
+                    $this->_view->setErrorMessage( $errorMessage );                    
                     $this->setCommonData( true );
                     return false;
                 }
             }
-            else {
-                // connect to the database if all went fine
-                $this->_db = connectDb( true );
-            }
 
             $config = new ConfigFileStorage();
             $this->_database = $config->getValue( "db_database" );
@@ -780,6 +804,7 @@
 
             // create the database
             if( $createDb ) {
+                $this->_db = connectDb( false, false );
                 if( !$this->_db->Execute( "CREATE DATABASE ".$this->_database )) {
                     $message .= "Error creating the database: ".$this->_db->ErrorMsg();
                     $this->_view = new WizardView( "step1" );
@@ -787,14 +812,14 @@
                     $this->_view->setErrorMessage( $message );
                     $this->setCommonData( true );
                     return false;
+                } else {
+                    $message .= "Database created successfully.<br/>";
                 }
-                else
-                    $message .= "Database created successfully.<br/>";
             }
 
             // reconnect using the new database.
             $config = new ConfigFileStorage();
-            $this->_db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $this->_database );
+            $this->_db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $config->getValue( "db_database" ));
 
             // create the tables
             $errors = false;




More information about the pLog-svn mailing list