Exemple #1
0
 /**
  * Class constructor, initiates parent constructor (parent::oxBase()).
  *
  * @param string $sDbDriver   Database driver
  * @param string $sFunction   The name of the calling function (in uppercase)
  * @param int    $iErrorNr    The native error number from the database
  * @param string $sErrorMsg   the native error message from the database
  * @param string $sParam1     $sFunction specific parameter
  * @param string $sParam2     $sFunction specific parameter
  * @param string $oConnection Database connection object
  */
 public function __construct($sDbDriver, $sFunction, $iErrorNr, $sErrorMsg, $sParam1, $sParam2, $oConnection)
 {
     $sUser = $oConnection->username;
     $iErrorNr = is_numeric($iErrorNr) ? $iErrorNr : -1;
     $sMessage = "{$sDbDriver} error: [{$iErrorNr}: {$sErrorMsg}] in {$sFunction} ({$sParam1}, {$sParam2}) with user {$sUser}\n";
     parent::__construct($sMessage, $iErrorNr);
 }
 /**
  * Returns database object
  *
  * @param boolean $blAssoc default false
  *
  * @throws oxConnectionException error while initiating connection to DB
  *
  * @return ADOConnection
  */
 public static function getDb($blAssoc = false)
 {
     global $ADODB_FETCH_MODE;
     if ($blAssoc) {
         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
     } else {
         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     }
     if (defined('OXID_PHP_UNIT')) {
         if (isset(modDB::$unitMOD) && is_object(modDB::$unitMOD)) {
             return modDB::$unitMOD;
         }
     }
     if (self::$_oDB !== null) {
         return self::$_oDB;
     }
     global $ADODB_CACHE_DIR;
     global $ADODB_DRIVER, $ADODB_SESSION_TBL, $ADODB_SESSION_CONNECT, $ADODB_SESSION_DRIVER, $ADODB_SESSION_USER, $ADODB_SESSION_PWD, $ADODB_SESSION_DB, $ADODB_SESS_LIFE, $ADODB_SESS_DEBUG;
     //adding exception handler for SQL errors
     $myConfig = self::getInstance()->getConfig();
     $iDebug = $myConfig->getConfigParam('iDebug');
     if ($iDebug) {
         include_once getShopBasePath() . 'core/adodblite/adodb-exceptions.inc.php';
     }
     // session related parameters. don't change.
     //Tomas
     //the default setting is 3000 * 60, but actually changing this will give no effect as now redefinition of this constant
     //appears after OXID custom settings are loaded and $ADODB_SESS_LIFE depends on user settings.
     //You can find the redefinition of ADODB_SESS_LIFE @ oxconfig.php:: line ~ 390.
     $ADODB_SESS_LIFE = 3000 * 60;
     $ADODB_SESSION_TBL = "oxsessions";
     $ADODB_SESSION_DRIVER = $myConfig->getConfigParam('dbType');
     $ADODB_SESSION_USER = $myConfig->getConfigParam('dbUser');
     $ADODB_SESSION_PWD = $myConfig->getConfigParam('dbPwd');
     $ADODB_SESSION_DB = $myConfig->getConfigParam('dbName');
     $ADODB_SESSION_CONNECT = $myConfig->getConfigParam('dbHost');
     $ADODB_SESS_DEBUG = false;
     $ADODB_CACHE_DIR = $myConfig->getConfigParam('sCompileDir');
     $sModules = '';
     if ($iDebug == 2 || $iDebug == 3 || $iDebug == 4 || $iDebug == 7) {
         $sModules = 'perfmon';
     }
     // log admin changes ?
     if ($myConfig->isAdmin() && $myConfig->getConfigParam('blLogChangesInAdmin')) {
         $sModules = ($sModules ? ':' : '') . 'oxadminlog';
     }
     self::$_oDB = ADONewConnection($myConfig->getConfigParam('dbType'), $sModules);
     $sVerPrefix = '';
     $sVerPrefix = '_ce';
     if (!self::$_oDB->connect($myConfig->getConfigParam('dbHost'), $myConfig->getConfigParam('dbUser'), $myConfig->getConfigParam('dbPwd'), $myConfig->getConfigParam('dbName'))) {
         $sConfig = join('', file(getShopBasePath() . 'config.inc.php'));
         if (strpos($sConfig, '<dbHost' . $sVerPrefix . '>') !== false && strpos($sConfig, '<dbName' . $sVerPrefix . '>') !== false) {
             header('location:setup/index.php');
             // pop to setup as there is something wrong
             oxUtils::getInstance()->showMessageAndExit("");
         } else {
             // notifying shop owner about connection problems
             $sFailedShop = isset($_REQUEST['shp']) ? addslashes($_REQUEST['shp']) : 'Base shop';
             $sDate = date('l dS of F Y h:i:s A');
             $sScript = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
             $sReferer = $_SERVER['HTTP_REFERER'];
             //sending a message to admin
             $sWarningSubject = 'Offline warning!';
             $sWarningBody = "\n                Database error in OXID eShop:\n                Date: {$sDate}\n                Shop: {$sFailedShop}\n\n                mysql error: " . self::$_oDB->errorMsg() . "\n                mysql error no: " . self::$_oDB->errorNo() . "\n\n                Script: {$sScript}\n                Referer: {$sReferer}";
             if ($sAdminEmail = $myConfig->getConfigParam('sAdminEmail')) {
                 include 'core/phpmailer/class.phpmailer.php';
                 $oMailer = new phpmailer();
                 $oMailer->isMail();
                 $oMailer->From = $sAdminEmail;
                 $oMailer->AddAddress($sAdminEmail);
                 $oMailer->Subject = $sWarningSubject;
                 $oMailer->Body = $sWarningBody;
                 $oMailer->send();
             }
             //only exception to default construction method
             $oEx = new oxConnectionException();
             $oEx->setMessage('EXCEPTION_CONNECTION_NODB');
             $oEx->setConnectionError($myConfig->getConfigParam('dbUser') . 's' . getShopBasePath() . self::$_oDB->errorMsg());
             throw $oEx;
         }
     }
     if ($iDebug == 2 || $iDebug == 3 || $iDebug == 4 || $iDebug == 7) {
         try {
             self::$_oDB->execute('truncate table adodb_logsql;');
         } catch (ADODB_Exception $e) {
             // nothing
         }
         self::$_oDB->logSQL(true);
     }
     self::$_oDB->cacheSecs = 60 * 10;
     // 10 minute caching
     self::$_oDB->execute('SET @@session.sql_mode = ""');
     if ($myConfig->isUtf()) {
         self::$_oDB->execute('SET NAMES "utf8"');
         self::$_oDB->execute('SET CHARACTER SET utf8');
         self::$_oDB->execute('SET CHARACTER_SET_CONNECTION = utf8');
         self::$_oDB->execute('SET CHARACTER_SET_DATABASE = utf8');
         self::$_oDB->execute('SET character_set_results = utf8');
         self::$_oDB->execute('SET character_set_server = utf8');
     } elseif ($myConfig->getConfigParam('sDefaultDatabaseConnection') != '') {
         self::$_oDB->execute('SET NAMES ' . $myConfig->getConfigParam('sDefaultDatabaseConnection'));
     }
     return self::$_oDB;
 }
Exemple #3
0
 /**
  * Notifying shop owner about connection problems
  *
  * @param ADOConnection $oDb database connection instance
  */
 protected function _notifyConnectionErrors($oDb)
 {
     // notifying shop owner about connection problems
     if ($sAdminEmail = self::_getConfigParam('_sAdminEmail')) {
         $sFailedShop = isset($_REQUEST['shp']) ? addslashes($_REQUEST['shp']) : 'Base shop';
         $sDate = date('l dS of F Y h:i:s A');
         $sScript = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
         $sReferer = $_SERVER['HTTP_REFERER'];
         //sending a message to admin
         $sWarningSubject = 'Offline warning!';
         $sWarningBody = "\n                Database error in OXID eShop:\n                Date: {$sDate}\n                Shop: {$sFailedShop}\n\n                mysql error: " . $oDb->errorMsg() . "\n                mysql error no: " . $oDb->errorNo() . "\n\n                Script: {$sScript}\n                Referer: {$sReferer}";
         $this->_sendMail($sAdminEmail, $sWarningSubject, $sWarningBody);
     }
     //only exception to default construction method
     $oEx = new oxConnectionException();
     $oEx->setMessage('EXCEPTION_CONNECTION_NODB');
     $oEx->setConnectionError(self::_getConfigParam('_dbUser') . 's' . getShopBasePath() . $oDb->errorMsg());
     throw $oEx;
 }
Exemple #4
0
 /**
  * Starts session manager
  *
  * @throws oxConnectionException
  *
  * @return null
  */
 public function init()
 {
     // Duplicated init protection
     if ($this->_blInit) {
         return;
     }
     $this->_blInit = true;
     $this->_loadVarsFromFile();
     include getShopBasePath() . 'core/oxconfk.php';
     // setting ADODB timeout
     global $ADODB_SESS_LIFE;
     $ADODB_SESS_LIFE = 1;
     $this->_setDefaults();
     try {
         $sShopID = $this->getShopId();
         $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
         // loading shop config
         if (empty($sShopID) || !$blConfigLoaded) {
             // if no config values where loaded (some problems with DB), throwing an exception
             $oEx = new oxConnectionException();
             $oEx->setMessage("Unable to load shop config values from database");
             throw $oEx;
         }
         // loading theme config options
         $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
         // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
         if ($this->getConfigParam('sCustomTheme')) {
             $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
         }
         // loading modules config
         $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
         $this->_processSeoCall();
         //starting up the session
         $this->getSession()->start();
         // Admin handling
         $this->setConfigParam('blAdmin', isAdmin());
         if (defined('OX_ADMIN_DIR')) {
             $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
         }
         $this->_loadVarsFromFile();
         //application initialization
         $this->_oStart = new oxStart();
         $this->_oStart->appInit();
     } catch (oxConnectionException $oEx) {
         return $this->_handleDbConnectionException($oEx);
     } catch (oxCookieException $oEx) {
         return $this->_handleCookieException($oEx);
     }
 }
Exemple #5
0
 /**
  * Shows exception message if debug mode is enabled, redirects otherwise.
  *
  * @param oxConnectionException $oEx message to show on exit
  */
 protected function _handleDbConnectionException($oEx)
 {
     $oEx->debugOut();
     if ($this->_isDebugMode()) {
         oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
     }
     oxRegistry::getUtils()->redirectOffline();
 }