Ejemplo n.º 1
0
 /**
  * A method for setting up a test database.
  *
  * @param bool $ignore_errors True if setup errors should be ignored.
  */
 static function setupDB($ignore_errors = false)
 {
     $oDbh =& OA_DB::singleton();
     if (PEAR::isError($oDbh)) {
         $aConf = $GLOBALS['_MAX']['CONF'];
         $result = OA_DB::createDatabase($aConf['database']['name']);
         if (PEAR::isError($result) && !$ignore_errors) {
             PEAR::raiseError("TestEnv unable to create the {$aConf['database']['name']} test database." . $result->getUserInfo(), PEAR_LOG_ERR);
             die(1);
         }
         $result = OA_DB::createFunctions();
         if (PEAR::isError($result) && !$ignore_errors) {
             PEAR::raiseError("TestEnv unable to create the required functions." . $result->getUserInfo(), PEAR_LOG_ERR);
             die(1);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * create the empty database
  *
  * @return boolean
  */
 function _createDatabase($aDsn = '')
 {
     if ($aDsn) {
         $this->aDsn = $aDsn;
     }
     $GLOBALS['_MAX']['CONF']['database'] = $this->aDsn['database'];
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = $this->aDsn['table']['prefix'];
     $GLOBALS['_MAX']['CONF']['table']['type'] = $this->aDsn['table']['type'];
     // Try connecting to the database
     $this->oDbh =& OA_DB::singleton(OA_DB::getDsn($this->aDsn));
     if (PEAR::isError($this->oDbh)) {
         $GLOBALS['_OA']['CONNECTIONS'] = array();
         $GLOBALS['_MDB2_databases'] = array();
         if (PEAR::isError($result)) {
             $this->oLogger->logError($result->getMessage());
             $this->oLogger->logErrorUnlessEmpty($result->getUserInfo());
             return false;
         }
         //attempt to create DB
         $result = OA_DB::createDatabase($this->aDsn['database']['name']);
         if (PEAR::isError($result)) {
             $this->oLogger->logError($result->getMessage());
             $this->oLogger->logErrorUnlessEmpty($result->getUserInfo());
             return false;
         }
         $this->oDbh = OA_DB::changeDatabase($this->aDsn['database']['name']);
         if (PEAR::isError($this->oDbh)) {
             $this->oLogger->logError($this->oDbh->getMessage());
             $this->oLogger->logErrorUnlessEmpty($this->getUserInfo());
             $this->oDbh = null;
             return false;
         }
         $this->oLogger->log('Database created ' . $this->aDsn['database']['name']);
         $this->can_drop_database = true;
     }
     $result = OA_DB::createFunctions();
     if (PEAR::isError($result)) {
         $this->oLogger->logError($result->getMessage());
         return false;
     }
     return true;
 }