Exemple #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 framework\Request $request The request object
  *
  * @return null
  */
 public function runInstallStep3(framework\Request $request)
 {
     $this->selected_connection_detail = $request['connection_type'];
     try {
         if ($this->username = $request['db_username']) {
             \b2db\Core::setUname($this->username);
             \b2db\Core::setTablePrefix($request['db_prefix']);
             if ($this->password = $request->getRawParameter('db_password')) {
                 \b2db\Core::setPasswd($this->password);
             }
             if ($this->selected_connection_detail == 'dsn') {
                 if (($this->dsn = $request['db_dsn']) != '') {
                     \b2db\Core::setDSN($this->dsn);
                 } else {
                     throw new \Exception('You must provide a valid DSN');
                 }
             } else {
                 if ($this->db_type = $request['db_type']) {
                     \b2db\Core::setDBtype($this->db_type);
                     if ($this->db_hostname = $request['db_hostname']) {
                         \b2db\Core::setHost($this->db_hostname);
                     } else {
                         throw new \Exception('You must provide a database hostname');
                     }
                     if ($this->db_port = $request['db_port']) {
                         \b2db\Core::setPort($this->db_port);
                     }
                     if ($this->db_databasename = $request['db_name']) {
                         \b2db\Core::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');
                 }
             }
             try {
                 \b2db\Core::doConnect();
             } catch (\b2db\Exception $e) {
                 throw new \Exception('There was an error connecting to the database: ' . $e->getMessage());
             }
             if (\b2db\Core::getDBname() == '') {
                 throw new \Exception('You must provide a database to use');
             }
             \b2db\Core::saveConnectionParameters(\THEBUGGENIE_CONFIGURATION_PATH . "b2db.yml");
         } else {
             throw new \Exception('You must provide a database username');
         }
         // Create v4 tables
         $b2db_entities_path = THEBUGGENIE_CORE_PATH . 'entities' . DS . 'tables' . DS;
         $tables_created = array();
         foreach (scandir($b2db_entities_path) as $tablefile) {
             if (in_array($tablefile, array('.', '..'))) {
                 continue;
             }
             if (($tablename = mb_substr($tablefile, 0, mb_strpos($tablefile, '.'))) != '') {
                 $tablename = "\\thebuggenie\\core\\entities\\tables\\{$tablename}";
                 $reflection = new \ReflectionClass($tablename);
                 $docblock = $reflection->getDocComment();
                 $annotationset = new \b2db\AnnotationSet($docblock);
                 if ($annotationset->hasAnnotation('Table')) {
                     \b2db\Core::getTable($tablename)->create();
                     \b2db\Core::getTable($tablename)->createIndexes();
                     $tables_created[] = $tablename;
                 }
             }
         }
         sort($tables_created);
         $this->tables_created = $tables_created;
     } catch (\Exception $e) {
         $this->error = $e->getMessage();
     }
     $server_type = strtolower(trim($_SERVER['SERVER_SOFTWARE']));
     switch (true) {
         case stripos($server_type, 'apache') !== false:
             $this->server_type = 'apache';
             break;
         case stripos($server_type, 'nginx') !== false:
             $this->server_type = 'nginx';
             break;
         case stripos($server_type, 'iis') !== false:
             $this->server_type = 'iis';
             break;
         default:
             $this->server_type = 'unknown';
     }
     $dirname = dirname($_SERVER['PHP_SELF']);
     if (mb_stristr(PHP_OS, 'WIN')) {
         $dirname = str_replace("\\", "/", $dirname);
         /* Windows adds a \ to the URL which we don't want */
     }
     $this->dirname = $dirname != '/' ? $dirname . '/' : $dirname;
 }
Exemple #2
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['connection_type'];
     try {
         if ($this->username = $request['db_username']) {
             \b2db\Core::setUname($this->username);
             \b2db\Core::setTablePrefix($request['db_prefix']);
             if ($this->password = $request->getRawParameter('db_password')) {
                 \b2db\Core::setPasswd($this->password);
             }
             if ($this->selected_connection_detail == 'dsn') {
                 if (($this->dsn = $request['db_dsn']) != '') {
                     \b2db\Core::setDSN($this->dsn);
                 } else {
                     throw new Exception('You must provide a valid DSN');
                 }
             } else {
                 if ($this->db_type = $request['db_type']) {
                     \b2db\Core::setDBtype($this->db_type);
                     if ($this->db_hostname = $request['db_hostname']) {
                         \b2db\Core::setHost($this->db_hostname);
                     } else {
                         throw new Exception('You must provide a database hostname');
                     }
                     if ($this->db_port = $request['db_port']) {
                         \b2db\Core::setPort($this->db_port);
                     }
                     if ($this->db_databasename = $request['db_name']) {
                         \b2db\Core::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\Core::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
             \b2db\Core::doConnect();
             if (\b2db\Core::getDBname() == '') {
                 throw new Exception('You must provide a database to use');
             }
             \b2db\Core::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::addAutoloaderClassPath($tables_path);
         $tables_path_handle = opendir($tables_path);
         $tables_created = array();
         while ($table_class_file = readdir($tables_path_handle)) {
             if (($tablename = mb_substr($table_class_file, 0, mb_strpos($table_class_file, '.'))) != '') {
                 \b2db\Core::getTable($tablename)->create();
                 \b2db\Core::getTable($tablename)->createIndexes();
                 $tables_created[] = $tablename;
             }
         }
         sort($tables_created);
         $this->tables_created = $tables_created;
         //TBGScope::setupInitialScope();
     } catch (Exception $e) {
         throw $e;
         $this->error = $e->getMessage();
     }
 }