/** * Adds an exception to the array of displayed exceptions for the view * by default is displayed in the inc_header, but with the custom destination set to true * the exception won't be displayed by default but can be displayed where ever wanted in the tpl * * @param StandardException|IDisplayError|string $oEr an exception object or just a language local (string), * which will be converted into a oxExceptionToDisplay object * @param bool $blFull if true the whole object is add to display (default false) * @param bool $useCustomDestination true if the exception shouldn't be displayed * at the default position (default false) * @param string $customDestination defines a name of the view variable containing * the messages, overrides Parameter 'CustomError' ("default") * @param string $activeController defines a name of the controller, which should * handle the error. */ public function addErrorToDisplay($oEr, $blFull = false, $useCustomDestination = false, $customDestination = "", $activeController = "") { if ($useCustomDestination && (oxRegistry::getConfig()->getRequestParameter('CustomError') || $customDestination != '')) { // check if the current request wants do display exceptions on its own $destination = oxRegistry::getConfig()->getRequestParameter('CustomError'); if ($customDestination != '') { $destination = $customDestination; } } else { //default $destination = 'default'; } //starting session if not yet started as all exception //messages are stored in session $session = $this->getSession(); if (!$session->getId() && !$session->isHeaderSent()) { $session->setForceNewSession(); $session->start(); } $aEx = oxRegistry::getSession()->getVariable('Errors'); if ($oEr instanceof \OxidEsales\EshopCommunity\Core\Exception\StandardException) { $oEx = oxNew('oxExceptionToDisplay'); $oEx->setMessage($oEr->getMessage()); $oEx->setExceptionType($oEr->getType()); if ($oEr instanceof \OxidEsales\EshopCommunity\Core\Exception\SystemComponentException) { $oEx->setMessageArgs($oEr->getComponent()); } $oEx->setValues($oEr->getValues()); $oEx->setStackTrace($oEr->getTraceAsString()); $oEx->setDebug($blFull); $oEr = $oEx; } elseif ($oEr && !$oEr instanceof \OxidEsales\EshopCommunity\Core\Contract\IDisplayError) { // assuming that a string was given $sTmp = $oEr; $oEr = oxNew('oxDisplayError'); $oEr->setMessage($sTmp); } elseif ($oEr instanceof \OxidEsales\EshopCommunity\Core\Contract\IDisplayError) { // take the object } else { $oEr = null; } if ($oEr) { $aEx[$destination][] = serialize($oEr); oxRegistry::getSession()->setVariable('Errors', $aEx); if ($activeController == '') { $activeController = oxRegistry::getConfig()->getRequestParameter('actcontrol'); } if ($activeController) { $aControllerErrors[$destination] = $activeController; oxRegistry::getSession()->setVariable('ErrorController', $aControllerErrors); } } }
/** * Send an offline warning to the shop owner. * Currently an email is sent to the email address configured as 'sAdminEmail' in the eShop config file. * * This method forms part of the exception handling process. Any further exceptions must be caught. * * @param StandardException $exception * * @return bool Returns true, if the email was sent. */ protected function sendOfflineWarning(StandardException $exception) { $result = false; /** @var $emailAddress Email address to sent the message to */ $emailAddress = Registry::get("OxConfigFile")->getVar('sAdminEmail'); if ($emailAddress) { /** As we are inside the exception handling process, any further exceptions must be caught */ try { $failedShop = isset($_REQUEST['shp']) ? addslashes($_REQUEST['shp']) : 'Base shop'; $date = date(DATE_RFC822); // RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000) $script = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; $referrer = $_SERVER['HTTP_REFERER']; //sending a message to admin $emailSubject = 'Offline warning!'; $emailBody = "\n Database connection error in OXID eShop:\n Date: {$date}\n Shop: {$failedShop}\n\n mysql error: " . $exception->getMessage() . "\n mysql error no: " . $exception->getCode() . "\n\n Script: {$script}\n Referrer: {$referrer}"; $mailer = new PHPMailer(); $mailer->isMail(); $mailer->setFrom($emailAddress); $mailer->addAddress($emailAddress); $mailer->Subject = $emailSubject; $mailer->Body = $emailBody; /** Set the priority of the message * For most clients expecting the Priority header: * 1 = High, 2 = Medium, 3 = Low * */ $mailer->Priority = 1; /** MS Outlook custom header */ $mailer->addCustomHeader("X-MSMail-Priority: Urgent"); /** Set the Importance header: */ $mailer->addCustomHeader("Importance: High"); $result = $mailer->send(); } catch (\Exception $exception) { $this->logException($exception); } } return $result; }