Ejemplo n.º 1
0
 /**
  * Runs the action for the third step of the installation
  * where it tests the connection, sets up the database and the initial scope
  * 
  * @param TBGRequest $request The request object
  * 
  * @return null
  */
 public function runInstallStep3(TBGRequest $request)
 {
     $this->selected_connection_detail = $request->getParameter('connection_type');
     try {
         if ($this->username = $request->getParameter('db_username')) {
             B2DB::setUname($this->username);
             B2DB::setTablePrefix($request->getParameter('db_prefix'));
             if ($this->password = $request->getRawParameter('db_password')) {
                 B2DB::setPasswd($this->password);
             }
             if ($this->selected_connection_detail == 'dsn') {
                 if (($this->dsn = $request->getParameter('db_dsn')) != '') {
                     B2DB::setDSN($this->dsn);
                 } else {
                     throw new Exception('You must provide a valid DSN');
                 }
             } else {
                 if ($this->db_type = $request->getParameter('db_type')) {
                     B2DB::setDBtype($this->db_type);
                     if ($this->db_hostname = $request->getParameter('db_hostname')) {
                         B2DB::setHost($this->db_hostname);
                     } else {
                         throw new Exception('You must provide a database hostname');
                     }
                     if ($this->db_port = $request->getParameter('db_port')) {
                         B2DB::setPort($this->db_port);
                     }
                     if ($this->db_databasename = $request->getParameter('db_name')) {
                         B2DB::setDBname($this->db_databasename);
                     } else {
                         throw new Exception('You must provide a database to use');
                     }
                 } else {
                     throw new Exception('You must provide a database type');
                 }
             }
             B2DB::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
             $engine_path = B2DB::getEngineClassPath();
             if ($engine_path !== null) {
                 TBGContext::addClasspath($engine_path);
             } else {
                 throw new Exception("Cannot initialize the B2DB engine");
             }
             B2DB::doConnect();
             if (B2DB::getDBname() == '') {
                 throw new Exception('You must provide a database to use');
             }
             B2DB::saveConnectionParameters(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
         } else {
             throw new Exception('You must provide a database username');
         }
         // Add table classes to classpath
         $tables_path = THEBUGGENIE_CORE_PATH . 'classes' . DS . 'B2DB' . DS;
         TBGContext::addClasspath($tables_path);
         $tables_path_handle = opendir($tables_path);
         $tables_created = array();
         while ($table_class_file = readdir($tables_path_handle)) {
             if (($tablename = substr($table_class_file, 0, strpos($table_class_file, '.'))) != '') {
                 B2DB::getTable($tablename)->create();
                 $tables_created[] = $tablename;
             }
         }
         sort($tables_created);
         $this->tables_created = $tables_created;
         //TBGScope::setupInitialScope();
     } catch (Exception $e) {
         //throw $e;
         $this->error = $e->getMessage();
     }
 }