/** * @static * @return mixed|\Zend_Db_Adapter_Abstract */ public static function get() { try { if (\Zend_Registry::isRegistered("Pimcore_Resource_Mysql")) { $connection = \Zend_Registry::get("Pimcore_Resource_Mysql"); if ($connection instanceof Wrapper) { return $connection; } } } catch (\Exception $e) { \Logger::error($e); } // get new connection try { $db = self::getConnection(); self::set($db); return $db; } catch (\Exception $e) { $errorMessage = "Unable to establish the database connection with the given configuration in /website/var/config/system.xml, for details see the debug.log. \nReason: " . $e->getMessage(); \Logger::emergency($errorMessage); \Logger::emergency($e); \Pimcore\Tool::exitWithError($errorMessage); } }
public function testEmergancyLevel() { $this->expectOutputString('emergency: Message contents'); $echo = new Adaptors\EchoAdaptor('debug', '{level}: {message}'); $logger = new Logger($echo); $logger->emergency('Message contents'); }
/** * @param \Zend_Controller_Request_Abstract $request * @throws mixed */ protected function _handleError(\Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = \Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $errorPath = Config::getSystemConfig()->documents->error_pages->default; if (Site::isSiteRequest()) { $site = Site::getCurrentSite(); $errorPath = $site->getErrorDocument(); } if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document\Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document\Page) { $params = Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); \Zend_Registry::set("pimcore_error_document", $document); // ensure that a viewRenderer exists, and is enabled if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) { $viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer(); \Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); } $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer"); $viewRenderer->setNoRender(false); if ($viewRenderer->view === null) { $viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views"); } } } catch (\Exception $e) { \Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
/** * @static * @return Zend_Config */ public static function getSystemConfig() { $config = null; try { $config = Zend_Registry::get("pimcore_config_system"); } catch (Exception $e) { try { $config = new Zend_Config_Xml(PIMCORE_CONFIGURATION_SYSTEM); self::setSystemConfig($config); } catch (Exception $e) { Logger::emergency("Cannot find system configuration, should be located at: " . PIMCORE_CONFIGURATION_SYSTEM); } } return $config; }
/** * @static * @return Zend_Db_Adapter_Abstract */ public static function reset() { // close old connections self::close(); // get new connection try { $db = self::getConnection(); self::set($db); return $db; } catch (Exception $e) { $errorMessage = "Unable to establish the database connection with the given configuration in /website/var/config/system.xml, for details see the debug.log. \nReason: " . $e->getMessage(); Logger::emergency($errorMessage); Logger::emergency($e); die($errorMessage); } }
public function test_methods_Magento() { $CONFIG_FILE_NAME = __DIR__ . '/logging_exception.yaml'; $LOGGER_NAME = 'defaultLoggerName'; /** * Perform testing. */ $log = new Logger($CONFIG_FILE_NAME, $LOGGER_NAME); $context = ['test' => true, 'env' => ['param1' => 'value1']]; $log->debug('debug', $context); $log->info('info', $context); $log->notice('notice', $context); $log->warning('warning', $context); $log->error('error', $context); $log->alert('alert', $context); $log->critical('critical', $context); $log->emergency('emergency', $context); }
/** * @static * @return Zend_Config */ public static function getSystemConfig() { $config = null; if (Zend_Registry::isRegistered("pimcore_config_system")) { $config = Zend_Registry::get("pimcore_config_system"); } else { try { $config = new Zend_Config_Xml(PIMCORE_CONFIGURATION_SYSTEM); self::setSystemConfig($config); } catch (Exception $e) { Logger::emergency("Cannot find system configuration, should be located at: " . PIMCORE_CONFIGURATION_SYSTEM); if (is_file(PIMCORE_CONFIGURATION_SYSTEM)) { die("Your system.xml located at " . PIMCORE_CONFIGURATION_SYSTEM . " is invalid, please check and correct it manually!"); } } } return $config; }
protected function _handleError(Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $siteKey = Pimcore_Tool_Frontend::getSiteKey(); $errorPath = Pimcore_Config::getSystemConfig()->documents->error_pages->{$siteKey}; if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document_Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document_Page) { $params = Pimcore_Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); Zend_Registry::set("pimcore_error_document", $document); } } catch (Exception $e) { Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
/** * @static * @return \Zend_Config */ public static function getConfig() { $config = NULL; if (\Zend_Registry::isRegistered('toolbox_config')) { $config = \Zend_Registry::get('toolbox_config'); } else { $configFile = TOOLBOX_CONFIGURATION_FILE; try { $config = new \Zend_Config(include $configFile); self::setConfig($config, 'toolbox_config'); } catch (\Exception $e) { \Logger::emergency("Cannot find system configuration, should be located at: " . $configFile); if (is_file($configFile)) { Tool::exitWithError("Your toolbox_configuration.php located at " . $configFile . " is invalid, please check and correct it manually!"); } } } return $config; }
/** * @static * @return \Zend_Config */ public static function getConfig() { $config = null; if (\Zend_Registry::isRegistered("coreshop_config")) { $config = \Zend_Registry::get("coreshop_config"); } else { try { $config = new \Zend_Config_Xml(CORESHOP_CONFIGURATION); self::setConfig($config); } catch (\Exception $e) { \Logger::emergency("Cannot find system configuration, should be located at: " . PIMCORE_CONFIGURATION_SYSTEM); if (is_file(CORESHOP_CONFIGURATION)) { $m = "Your coreshop-config.xml located at " . CORESHOP_CONFIGURATION . " is invalid, please check and correct it manually!"; \Pimcore\Tool::exitWithError($m); } } } return $config; }
/** * @param bool $forceReload * @return array|null */ public static function getWorkflowManagementConfig($forceReload = false) { $config = null; if (\Zend_Registry::isRegistered("pimcore_config_workflowmanagement") && !$forceReload) { $config = \Zend_Registry::get("pimcore_config_workflowmanagement"); } else { try { $file = \Pimcore\Config::locateConfigFile("workflowmanagement.php"); if (is_file($file)) { $config = (include $file); if (is_array($config)) { self::setWorkflowManagementConfig($config); } else { \Logger::error("{$file} exists but it is not a valid PHP array configuration."); } } } catch (\Exception $e) { $file = \Pimcore\Config::locateConfigFile("workflowmanagement.php"); \Logger::emergency("Cannot find workflow configuration, should be located at: " . $file); } } return $config; }
/** * @static * @return void */ public static function initSession() { if (!\Zend_Session::isStarted()) { \Zend_Session::setOptions(self::$options); } try { try { if (!\Zend_Session::isStarted()) { $sName = self::getOption("name"); // only set the session id if the cookie isn't present, otherwise Set-Cookie is always in the headers if (array_key_exists($sName, $_REQUEST) && !empty($_REQUEST[$sName]) && (!array_key_exists($sName, $_COOKIE) || empty($_COOKIE[$sName]))) { // get zend_session work with session-id via get (since SwfUpload doesn't support cookies) \Zend_Session::setId($_REQUEST[$sName]); } } } catch (\Exception $e) { \Logger::error("Problem while starting session"); \Logger::error($e); } } catch (\Exception $e) { \Logger::emergency("there is a problem with admin session"); die; } }
/** * @static * @return void */ public static function initSession() { Zend_Session::setOptions(array("throw_startup_exceptions" => false, "gc_maxlifetime" => 7200, "name" => "pimcore_admin_sid", "strict" => false, "use_only_cookies" => false)); try { try { if (!Zend_Session::isStarted()) { $sName = Zend_Session::getOptions("name"); // only set the session id if the cookie isn't present, otherwise Set-Cookie is always in the headers if (array_key_exists($sName, $_REQUEST) && !empty($_REQUEST[$sName]) && (!array_key_exists($sName, $_COOKIE) || empty($_COOKIE[$sName]))) { // get zend_session work with session-id via get (since SwfUpload doesn't support cookies) Zend_Session::setId($_REQUEST[$sName]); } // register session Zend_Session::start(); } } catch (Exception $e) { Logger::error("Problem while starting session"); Logger::error($e); } } catch (Exception $e) { Logger::emergency("there is a problem with admin session"); die; } }
public function checkForErrors() { if ($error = $this->_getParam('error_handler')) { if ($error->exception) { if ($error->exception instanceof Zend_Controller_Router_Exception || $error->exception instanceof Zend_Controller_Action_Exception) { header('HTTP/1.1 404 Not Found'); //$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found'); $this->getResponse()->setHttpResponseCode(404); } else { header('HTTP/1.1 503 Service Temporarily Unavailable'); //$this->getResponse()->setRawHeader('HTTP/1.1 503 Service Temporarily Unavailable'); $this->getResponse()->setHttpResponseCode(503); } Logger::emergency("Unable to load URL: " . $_SERVER["REQUEST_URI"]); Logger::emergency($error->exception); try { $document = Zend_Registry::get("pimcore_error_document"); $this->setDocument($document); $this->_setParam("document", $document); $this->disableLayout(); } catch (Exception $e) { die("Unable to load error document"); } } } }
/** * @param string $namespace * @param bool $readOnly * @return \Zend_Session_Namespace * @throws \Zend_Session_Exception */ public static function get($namespace = "pimcore_admin", $readOnly = false) { $initSession = !\Zend_Session::isStarted(); $forceStart = !$readOnly; // we don't force the session to start in read-only mode (default behavior) $sName = self::getOption("name"); if (self::backupForeignSession()) { $initSession = true; $forceStart = true; } if ($initSession) { \Zend_Session::setOptions(self::$options); } try { try { if ($initSession) { // only set the session id if the cookie isn't present, otherwise Set-Cookie is always in the headers if (array_key_exists($sName, $_REQUEST) && !empty($_REQUEST[$sName]) && (!array_key_exists($sName, $_COOKIE) || empty($_COOKIE[$sName]))) { // get zend_session work with session-id via get (since SwfUpload doesn't support cookies) \Zend_Session::setId($_REQUEST[$sName]); } } } catch (\Exception $e) { \Logger::error("Problem while starting session"); \Logger::error($e); } } catch (\Exception $e) { \Logger::emergency("there is a problem with admin session"); die; } if ($initSession) { \Zend_Session::start(); } if ($forceStart) { @session_start(); self::$sessionCookieCleanupNeeded = true; } if (!array_key_exists($namespace, self::$sessions) || !self::$sessions[$namespace] instanceof \Zend_Session_Namespace) { try { self::$sessions[$namespace] = new Session\Container($namespace); } catch (\Exception $e) { // invalid session, regenerate the session, and return a dummy object \Zend_Session::regenerateId(); return new \stdClass(); } } self::$openedSessions++; self::$sessions[$namespace]->unlock(); return self::$sessions[$namespace]; }
/** * @param $method * @param $args * @throws \Exception */ public function __call($method, $args) { // check if the method is defined in resource if (method_exists($this->getResource(), $method)) { try { $r = call_user_func_array(array($this->getResource(), $method), $args); return $r; } catch (\Exception $e) { \Logger::emergency($e); throw $e; } } else { \Logger::error("Class: " . get_class($this) . " => call to undefined method " . $method); throw new \Exception("Call to undefined method " . $method . " in class " . get_class($this)); } }
/** * @param $method * @param $args * @return mixed * @throws \Exception */ public function __call($method, $args) { // protected / private methods shouldn't be delegated to the dao -> this can have dangerous effects if (!is_callable([$this, $method])) { throw new \Exception("Unable to call private/protected method '" . $method . "' on object " . get_class($this)); } // check if the method is defined in ´dao if (method_exists($this->getDao(), $method)) { try { $r = call_user_func_array(array($this->getDao(), $method), $args); return $r; } catch (\Exception $e) { \Logger::emergency($e); throw $e; } } else { \Logger::error("Class: " . get_class($this) . " => call to undefined method " . $method); throw new \Exception("Call to undefined method " . $method . " in class " . get_class($this)); } }
/** * System is unusable. * * @param string $message * @param array $context * * @return null */ public function emergency($message, array $context = array()) { \Logger::emergency($message); }
public function testEmergency_WithAdditional() { $this->object->emergency('message', 'additional'); }
protected function error($err) { Logger::emergency($err); $this->errors[] = $err; throw new \Exception($err); return false; }
/** * @static * @return void */ public static function initSession() { Zend_Session::setOptions(array("throw_startup_exceptions" => false, "gc_maxlifetime" => 7200, "name" => "pimcore_admin_sid", "strict" => false, "use_only_cookies" => false)); try { // register session $front = Zend_Controller_Front::getInstance(); if ($front->getRequest() != null && $front->getRequest()->getParam("pimcore_admin_sid")) { // hack to get zend_session work with session-id via get (since SwfUpload doesn't support cookies) $_REQUEST["pimcore_admin_sid"] = $front->getRequest()->getParam("pimcore_admin_sid"); $_COOKIE["pimcore_admin_sid"] = $front->getRequest()->getParam("pimcore_admin_sid"); } if (!empty($_GET["pimcore_admin_sid"])) { // hack to get zend_session work with session-id via get (since SwfUpload doesn't support cookies) $_REQUEST["pimcore_admin_sid"] = $_GET["pimcore_admin_sid"]; $_COOKIE["pimcore_admin_sid"] = $_GET["pimcore_admin_sid"]; } try { if (!Zend_Session::isStarted()) { Zend_Session::start(); } } catch (Exception $e) { Logger::error("Problem while starting session"); Logger::error($e); } } catch (Exception $e) { Logger::emergency("there is a problem with admin session"); die; } }