emerg() public static method

public static emerg ( $m, $context = [] )
Esempio n. 1
0
 /**
  * Save document to database
  *
  * @return void
  */
 public function save()
 {
     $data = [];
     $emailLog = get_object_vars($this->model);
     foreach ($emailLog as $key => $value) {
         if (in_array($key, $this->getValidTableColumns(self::$dbTable))) {
             // check if the getter exists
             $getter = "get" . ucfirst($key);
             if (!method_exists($this->model, $getter)) {
                 continue;
             }
             // get the value from the getter
             $value = $this->model->{$getter}();
             if (is_bool($value)) {
                 $value = (int) $value;
             } elseif (is_array($value)) {
                 //converts the dynamic params to a basic json string
                 $preparedData = self::createJsonLoggingObject($value);
                 $value = \Zend_Json::encode($preparedData);
             }
             $data[$key] = $value;
         }
     }
     try {
         $this->db->update(self::$dbTable, $data, $this->db->quoteInto("id = ?", $this->model->getId()));
     } catch (\Exception $e) {
         Logger::emerg('Could not Save emailLog with the id "' . $this->model->getId() . '" ');
     }
 }
 public function generateSitemap()
 {
     $this->prepareSiteMapFolder();
     if (!is_null($this->sitemapDir)) {
         $hosts = $this->getValidHosts();
         if (is_array($hosts)) {
             foreach ($hosts as $hostName) {
                 $query = new \Zend_Search_Lucene_Search_Query_Boolean();
                 $hostTerm = new \Zend_Search_Lucene_Index_Term($hostName, 'host');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hostTerm = new \Zend_Search_Lucene_Index_Term(TRUE, 'restrictionGroup_default');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hits = $this->index->find($query);
                 $name = str_replace('.', '-', $hostName);
                 $filePath = $this->sitemapDir . '/sitemap-' . $name . '.xml';
                 $fh = fopen($filePath, 'w');
                 fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
                 fwrite($fh, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
                 fwrite($fh, "\r\n");
                 for ($i = 0; $i < count($hits); $i++) {
                     $url = $hits[$i]->getDocument()->getField('url');
                     $uri = str_replace(array('?pimcore_outputfilters_disabled=1', '&pimcore_outputfilters_disabled=1'), '', $url->value);
                     fwrite($fh, '<url>' . "\r\n");
                     fwrite($fh, '    <loc>' . htmlspecialchars($uri, ENT_QUOTES) . '</loc>' . "\r\n");
                     fwrite($fh, '</url>' . "\r\n");
                 }
                 fwrite($fh, '</urlset>' . "\r\n");
                 fclose($fh);
             }
             $filePath = $this->sitemapDir . '/sitemap.xml';
             $fh = fopen($filePath, 'w');
             fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
             fwrite($fh, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
             fwrite($fh, "\r\n");
             foreach ($hosts as $hostName) {
                 $name = str_replace('.', '-', $hostName);
                 //first host must be main domain - see hint in plugin settings
                 $currenthost = $hosts[0];
                 fwrite($fh, '<sitemap>' . "\r\n");
                 fwrite($fh, '    <loc>http://' . $currenthost . '/plugin/LuceneSearch/frontend/sitemap/?sitemap=sitemap-' . $name . '.xml' . '</loc>' . "\r\n");
                 fwrite($fh, '</sitemap>' . "\r\n");
                 \Pimcore\Logger::debug('LuceneSearch: ' . $hostName . ' for sitemap.xml added.');
             }
             fwrite($fh, '</sitemapindex>' . "\r\n");
             fclose($fh);
         } else {
             \Pimcore\Logger::debug('LuceneSearch: could not generate sitemaps, did not find any hosts in index.');
         }
     } else {
         \Pimcore\Logger::emerg('LuceneSearch: Cannot generate sitemap. Sitemap directory [ ' . $this->sitemapDir . ' ]  not available/not writeable and cannot be created');
     }
 }
Esempio n. 3
0
File: Db.php Progetto: sfie/pimcore
 /**
  * @param bool $raw
  * @param bool $writeOnly
  * @return Wrapper|\Zend_Db_Adapter_Abstract
  * @throws \Exception
  * @throws \Zend_Db_Profiler_Exception
  */
 public static function getConnection($raw = false, $writeOnly = false)
 {
     // just return the wrapper (for compatibility reasons)
     // the wrapper itself get's then the connection using $raw = true
     if (!$raw) {
         return new Wrapper();
     }
     $charset = "UTF8";
     // explicit set charset for connection (to the adapter)
     $config = Config::getSystemConfig()->database->toArray();
     // write only handling
     if ($writeOnly && isset($config["writeOnly"])) {
         // overwrite params with write only configuration
         $config["params"] = $config["writeOnly"]["params"];
     } else {
         if ($writeOnly) {
             throw new \Exception("writeOnly connection is requested but not configured");
         }
     }
     $config["params"]["charset"] = $charset;
     try {
         $db = \Zend_Db::factory($config["adapter"], $config["params"]);
         $db->query("SET NAMES " . $charset);
     } catch (\Exception $e) {
         \Logger::emerg($e);
         \Pimcore\Tool::exitWithError("Database Error! See debug.log for details");
     }
     // try to set innodb as default storage-engine
     try {
         $db->query("SET storage_engine=InnoDB;");
     } catch (\Exception $e) {
         \Logger::warn($e);
     }
     // try to set mysql mode
     try {
         $db->query("SET sql_mode = '';");
     } catch (\Exception $e) {
         \Logger::warn($e);
     }
     $connectionId = $db->fetchOne("SELECT CONNECTION_ID()");
     // enable the db-profiler if the devmode is on and there is no custom profiler set (eg. in system.xml)
     if (PIMCORE_DEVMODE && !$db->getProfiler()->getEnabled() || array_key_exists("pimcore_log", $_REQUEST) && \Pimcore::inDebugMode()) {
         $profiler = new \Pimcore\Db\Profiler('All DB Queries');
         $profiler->setEnabled(true);
         $profiler->setConnectionId($connectionId);
         $db->setProfiler($profiler);
     }
     \Logger::debug(get_class($db) . ": Successfully established connection to MySQL-Server, Process-ID: " . $connectionId);
     return $db;
 }
Esempio n. 4
0
<?php

/**
 * Pimcore
 *
 * This source file is available under two different licenses:
 * - GNU General Public License version 3 (GPLv3)
 * - Pimcore Enterprise License (PEL)
 * Full copyright and license information is available in
 * LICENSE.md which is distributed with this source code.
 *
 * @copyright  Copyright (c) 2009-2016 pimcore GmbH (http://www.pimcore.org)
 * @license    http://www.pimcore.org/license     GPLv3 and PEL
 */
include_once "pimcore/config/startup.php";
try {
    \Pimcore::run();
} catch (Exception $e) {
    // handle exceptions, log to file
    if (class_exists("Pimcore\\Logger")) {
        \Pimcore\Logger::emerg($e);
    }
    throw $e;
}
Esempio n. 5
0
 /**
  * Sends this email using the given transport or with the settings from "Settings" -> "System" -> "Email Settings"
  *
  * IMPORTANT: If the debug mode is enabled in "Settings" -> "System" -> "Debug" all emails will be sent to the
  * debug email addresses that are given in "Settings" -> "System" -> "Email Settings" -> "Debug email addresses"
  *
  * set DefaultTransport or the internal mail function if no
  * default transport had been set.
  *
  * @param  \Zend_Mail_Transport_Abstract $transport
  * @return \Pimcore\Mail Provides fluent interface
  */
 public function send($transport = null)
 {
     // filter email addresses
     $blockedAddresses = array();
     foreach ($this->getRecipients() as $recipient) {
         if (Model\Tool\Email\Blacklist::getByAddress($recipient)) {
             $blockedAddresses[] = $recipient;
         }
     }
     if (!empty($blockedAddresses)) {
         foreach ($blockedAddresses as $blockedAddress) {
             foreach (["To", "Cc", "Bcc"] as $type) {
                 $tmp = $this->_headers[$type];
                 foreach ($tmp as $key => &$value) {
                     if (strpos($value, $blockedAddress) !== false) {
                         unset($this->_headers[$type][$key]);
                         unset($this->_recipients[$value]);
                     }
                 }
             }
         }
     }
     $this->setSubject($this->getSubjectRendered());
     $bodyHtmlRendered = $this->getBodyHtmlRendered();
     if ($bodyHtmlRendered) {
         $this->setBodyHtml($bodyHtmlRendered);
     }
     $bodyTextRendered = $this->getBodyTextRendered();
     if ($bodyTextRendered) {
         $this->setBodyText($bodyTextRendered);
     }
     if ($this->ignoreDebugMode == false) {
         $this->checkDebugMode();
     }
     $result = parent::send($transport);
     if ($this->loggingIsEnabled()) {
         try {
             MailHelper::logEmail($this);
         } catch (\Exception $e) {
             \Logger::emerg("Couldn't log Email");
         }
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * @throws \Zend_Exception
  */
 public function init()
 {
     parent::init();
     // set language
     if (\Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = (string) \Zend_Registry::get("Zend_Locale");
         $this->setLanguage($locale);
     } else {
         if ($this->getParam("language")) {
             $this->setLanguage($this->getParam("language"));
         } else {
             $config = Config::getSystemConfig();
             $this->setLanguage($config->general->language);
             // try to set browser-language (validation if installed is in $this->setLanguage() )
             $this->setLanguage(new \Zend_Locale());
         }
     }
     if (self::$adminInitialized) {
         // this will be executed on every call to this init() method
         try {
             $this->setUser(\Zend_Registry::get("pimcore_admin_user"));
         } catch (\Exception $e) {
             Logger::emerg("adminInitialized was set to true although there was no user set in the registry -> to be save the process was killed");
             exit;
         }
     } else {
         // the following code is only called once, even when there are some subcalls (eg. with $this->action, ... )
         \Pimcore::getEventManager()->trigger("admin.controller.preInit", $this);
         $this->disableBrowserCache();
         // general definitions
         Model\Document::setHideUnpublished(false);
         Model\Object\AbstractObject::setHideUnpublished(false);
         Model\Object\AbstractObject::setGetInheritedValues(false);
         Model\Object\Localizedfield::setGetFallbackValues(false);
         \Pimcore::setAdminMode();
         // init translations
         self::initTranslations($this);
         // init zend action helpers, we need to leave the prefixed class name here as the plugin loader isn't able to handle namespaces
         \Zend_Controller_Action_HelperBroker::addPrefix('Pimcore_Controller_Action_Helper');
         // this is to make it possible to use the session id as a part of the route (ZF default route) used for external editors, etc.
         if ($this->getParam("pimcore_admin_sid")) {
             $_REQUEST["pimcore_admin_sid"] = $this->getParam("pimcore_admin_sid");
         }
         // authenticate user, first try to authenticate with session information
         $user = Authentication::authenticateSession();
         if ($user instanceof Model\User) {
             $this->setUser($user);
             if ($this->getUser()->getLanguage()) {
                 $this->setLanguage($this->getUser()->getLanguage());
             }
         } else {
             // try to authenticate with http basic auth, but this is only allowed for WebDAV
             if ($this->getParam("module") == "admin" && $this->getParam("controller") == "asset" && $this->getParam("action") == "webdav") {
                 $user = Authentication::authenticateHttpBasic();
                 if ($user instanceof Model\User) {
                     $this->setUser($user);
                     \Zend_Registry::set("pimcore_admin_user", $this->getUser());
                     self::$adminInitialized = true;
                     return;
                 }
             }
         }
         // redirect to the login-page if the user isn't authenticated
         if (!$this->getUser() instanceof Model\User && !($this->getParam("module") == "admin" && $this->getParam("controller") == "login")) {
             // put a detailed message into the debug.log
             Logger::error("Prevented access to " . $_SERVER["REQUEST_URI"] . " because there is no user in the session!", ["server" => $_SERVER, "get" => $_GET, "post" => $_POST, "session" => $_SESSION, "cookie" => $_COOKIE]);
             // send a auth header for the client (is covered by the ajax object in javascript)
             $this->getResponse()->setHeader("X-Pimcore-Auth", "required");
             // redirect to login page
             $this->redirect("/admin/login");
             // exit the execution -> just to be sure
             exit;
         }
         // we're now authenticated so we can remove the default error handler so that we get just the normal PHP errors
         if ($this->getParam("controller") != "login") {
             $front = \Zend_Controller_Front::getInstance();
             $front->unregisterPlugin("Pimcore\\Controller\\Plugin\\ErrorHandler");
             $front->throwExceptions(true);
             @ini_set("display_errors", "On");
             @ini_set("display_startup_errors", "On");
         }
         \Zend_Registry::set("pimcore_admin_user", $this->getUser());
         self::$adminInitialized = true;
         // usage statistics
         $this->logUsageStatistics();
         \Pimcore::getEventManager()->trigger("admin.controller.postInit", $this);
     }
 }