Пример #1
0
 /**
  * Save document to database
  *
  * @return void
  */
 public function save()
 {
     $data = array();
     $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;
             } else {
                 if (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() . '" ');
     }
 }
Пример #2
0
 private static function getEncoderClass($fieldtype)
 {
     Logger::emerg('*********************************');
     Logger::emerg('tipo campo: ' . $fieldtype);
     $encoderClass = '';
     switch ($fieldtype) {
         case PimPon_Object_Encoder_Image::TYPE:
             $encoderClass = 'PimPon_Object_Encoder_Image';
             break;
         case PimPon_Object_Encoder_Collection::TYPE:
         case PimPon_Object_Encoder_Collection::TYPE2:
             $encoderClass = 'PimPon_Object_Encoder_Collection';
             break;
         case PimPon_Object_Encoder_Date::TYPE:
             $encoderClass = 'PimPon_Object_Encoder_Date';
             break;
         case PimPon_Object_Encoder_Href::TYPE:
             $encoderClass = 'PimPon_Object_Encoder_Href';
             break;
         case PimPon_Object_Encoder_Table::TYPE:
             $encoderClass = 'PimPon_Object_Encoder_Table';
             break;
         case PimPon_Object_Encoder_Structuredtable::TYPE:
             $encoderClass = 'PimPon_Object_Encoder_Structuredtable';
             break;
         default:
             $encoderClass = 'PimPon_Object_Encoder_Default';
     }
     Logger::emerg('encoder class: ' . $encoderClass);
     return $encoderClass;
 }
Пример #3
0
 /**
  * @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;
 }
Пример #4
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)
 {
     if ($this->getDocument()) {
         $this->setDocumentSettings();
         $this->setSubject($this->getSubjectRendered());
         $this->setBodyHtml($this->getBodyHtmlRendered());
         $this->setBodyText($this->getBodyTextRendered());
     }
     if ($this->ignoreDebugMode == false) {
         $this->checkDebugMode();
     }
     $result = parent::send($transport);
     if ($this->loggingIsEnabled() && $this->getDocument()) {
         try {
             Pimcore_Helper_Mail::logEmail($this);
         } catch (Exception $e) {
             Logger::emerg("Couldn't log Email");
         }
     }
     return $result;
 }
Пример #5
0
 public function init()
 {
     parent::init();
     // set language
     if (Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = Zend_Registry::get("Zend_Locale");
         $this->setLanguage($locale->getLanguage());
     } else {
         if ($this->_getParam("language")) {
             $this->setLanguage($this->_getParam("language"));
         } else {
             $config = Pimcore_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, ... )
         $this->disableBrowserCache();
         // general definitions
         Document::setHideUnpublished(false);
         Object_Abstract::setHideUnpublished(false);
         Object_Abstract::setGetInheritedValues(false);
         Pimcore::setAdminMode();
         // init translations
         self::initTranslations($this);
         // init zend action helpers
         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 pixlr.com 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 = Pimcore_Tool_Authentication::authenticateSession();
         if ($user instanceof User) {
             $this->setUser($user);
             if ($this->getUser()->getLanguage()) {
                 $this->setLanguage($this->getUser()->getLanguage());
             }
         } else {
             // try to authenticate with digest, but this is only allowed for WebDAV
             if ($this->_getParam("module") == "admin" && $this->_getParam("controller") == "asset" && $this->_getParam("action") == "webdav") {
                 $user = Pimcore_Tool_Authentication::authenticateDigest();
                 if ($user instanceof User) {
                     $this->setUser($user);
                     self::$adminInitialized = true;
                     return;
                 }
             }
         }
         // redirect to the login-page if the user isn't authenticated
         if (!$this->getUser() instanceof User && !($this->_getParam("module") == "admin" && $this->_getParam("controller") == "login")) {
             // put a detailed message into the debug.log
             Logger::warn("Prevented access to " . $_SERVER["REQUEST_URI"] . " because there is no user in the session!");
             Logger::warn(array("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;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $newsletter = Model\Tool\Newsletter\Config::getByName($input->getArgument("id"));
     if ($newsletter) {
         $pidFile = $newsletter->getPidFile();
         if (file_exists($pidFile)) {
             \Logger::alert("Cannot send newsletters because there's already one active sending process");
             exit;
         }
         $elementsPerLoop = 10;
         $objectList = "\\Pimcore\\Model\\Object\\" . ucfirst($newsletter->getClass()) . "\\Listing";
         $list = new $objectList();
         $conditions = array("(newsletterActive = 1 AND newsletterConfirmed = 1)");
         if ($newsletter->getObjectFilterSQL()) {
             $conditions[] = $newsletter->getObjectFilterSQL();
         }
         if ($newsletter->getPersonas()) {
             $class = Model\Object\ClassDefinition::getByName($newsletter->getClass());
             if ($class && $class->getFieldDefinition("persona")) {
                 $personas = array();
                 $p = explode(",", $newsletter->getPersonas());
                 if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Persona) {
                     foreach ($p as $value) {
                         if (!empty($value)) {
                             $personas[] = $list->quote($value);
                         }
                     }
                     $conditions[] = "persona IN (" . implode(",", $personas) . ")";
                 } else {
                     if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Personamultiselect) {
                         $personasCondition = array();
                         foreach ($p as $value) {
                             $personasCondition[] = "persona LIKE " . $list->quote("%," . $value . ",%");
                         }
                         $conditions[] = "(" . implode(" OR ", $personasCondition) . ")";
                     }
                 }
             }
         }
         $list->setCondition(implode(" AND ", $conditions));
         $list->setOrderKey("email");
         $list->setOrder("ASC");
         $elementsTotal = $list->getTotalCount();
         $count = 0;
         $pidContents = array("start" => time(), "lastUpdate" => time(), "newsletter" => $newsletter->getName(), "total" => $elementsTotal, "current" => $count);
         $this->writePid($pidFile, $pidContents);
         for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) {
             $list->setLimit($elementsPerLoop);
             $list->setOffset($i * $elementsPerLoop);
             $objects = $list->load();
             foreach ($objects as $object) {
                 try {
                     $count++;
                     \Logger::info("Sending newsletter " . $count . " / " . $elementsTotal . " [" . $newsletter->getName() . "]");
                     \Pimcore\Tool\Newsletter::sendMail($newsletter, $object, null, $input->getArgument("hostUrl"));
                     $note = new Model\Element\Note();
                     $note->setElement($object);
                     $note->setDate(time());
                     $note->setType("newsletter");
                     $note->setTitle("sent newsletter: '" . $newsletter->getName() . "'");
                     $note->setUser(0);
                     $note->setData(array());
                     $note->save();
                     \Logger::info("Sent newsletter to: " . $this->obfuscateEmail($object->getEmail()) . " [" . $newsletter->getName() . "]");
                 } catch (\Exception $e) {
                     \Logger::err($e);
                 }
             }
             // check if pid exists
             if (!file_exists($pidFile)) {
                 \Logger::alert("Newsletter PID not found, cancel sending process");
                 exit;
             }
             // update pid
             $pidContents["lastUpdate"] = time();
             $pidContents["current"] = $count;
             $this->writePid($pidFile, $pidContents);
             \Pimcore::collectGarbage();
         }
         // remove pid
         @unlink($pidFile);
     } else {
         \Logger::emerg("Newsletter '" . $input->getArgument("id") . "' doesn't exist");
     }
 }
                $note->save();
                \Logger::info("Sent newsletter to: " . obfuscateEmail($object->getEmail()) . " [" . $newsletter->getName() . "]");
            } catch (\Exception $e) {
                \Logger::err($e);
            }
        }
        // check if pid exists
        if (!file_exists($pidFile)) {
            \Logger::alert("Newsletter PID not found, cancel sending process");
            exit;
        }
        // update pid
        $pidContents["lastUpdate"] = time();
        $pidContents["current"] = $count;
        writePid($pidFile, $pidContents);
        \Pimcore::collectGarbage();
    }
    // remove pid
    @unlink($pidFile);
} else {
    \Logger::emerg("Newsletter '" . $argv[1] . "' doesn't exist");
}
function obfuscateEmail($email)
{
    $email = substr_replace($email, ".xxx", strrpos($email, "."));
    return $email;
}
function writePid($file, $content)
{
    \Pimcore\File::put($file, serialize($content));
}
Пример #8
0
<?php

/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2014 pimcore GmbH (http://www.pimcore.org)
 * @license    http://www.pimcore.org/license     New BSD License
 */
include_once "pimcore/config/startup.php";
try {
    Pimcore::run();
} catch (Exception $e) {
    // handle exceptions, log to file
    if (class_exists("Logger")) {
        Logger::emerg($e);
    }
    throw $e;
}
Пример #9
0
 /**
  * @param  $path
  * @param bool $partial
  * @return array|bool
  */
 public function match($path, $partial = false)
 {
     $matchFound = false;
     $config = Pimcore_Config::getSystemConfig();
     $routeingDefaults = Pimcore_Tool::getRoutingDefaults();
     $params = array_merge($_GET, $_POST);
     $params = array_merge($routeingDefaults, $params);
     // set the original path
     $originalPath = $path;
     // check for a registered site
     try {
         if ($config->general->domain != $_SERVER["HTTP_HOST"]) {
             $domain = $_SERVER["HTTP_HOST"];
             $site = Site::getByDomain($domain);
             $site->setRootPath($site->getRootDocument()->getFullPath());
             $path = $site->getRootDocument()->getFullPath() . $path;
             Zend_Registry::set("pimcore_site", $site);
         }
     } catch (Exception $e) {
     }
     // check for direct definition of controller/action
     if (!empty($_REQUEST["controller"]) && !empty($_REQUEST["action"])) {
         $matchFound = true;
         //$params["document"] = $this->getNearestDocumentByPath($path);
     }
     // you can also call a page by it's ID /?pimcore_document=XXXX
     if (!$matchFound) {
         if (!empty($params["pimcore_document"]) || !empty($params["pdid"])) {
             $doc = Document::getById($params["pimcore_document"] ? $params["pimcore_document"] : $params["pdid"]);
             if ($doc instanceof Document) {
                 $path = $doc->getFullPath();
             }
         }
     }
     // test if there is a suitable redirect with override = all (=> priority = 99)
     if (!$matchFound) {
         $this->checkForRedirect(true);
     }
     // test if there is a suitable page
     if (!$matchFound) {
         try {
             $document = Document::getByPath($path);
             // check for a parent hardlink with childs
             if (!$document instanceof Document) {
                 $hardlinkedParentDocument = $this->getNearestDocumentByPath($path, true);
                 if ($hardlinkedParentDocument instanceof Document_Hardlink) {
                     if ($hardLinkedDocument = Document_Hardlink_Service::getChildByPath($hardlinkedParentDocument, $path)) {
                         $document = $hardLinkedDocument;
                     }
                 }
             }
             // check for direct hardlink
             if ($document instanceof Document_Hardlink) {
                 $hardlinkParentDocument = $document;
                 $document = Document_Hardlink_Service::wrap($hardlinkParentDocument);
             }
             if ($document instanceof Document) {
                 if (in_array($document->getType(), array("page", "snippet", "email"))) {
                     if (!empty($params["pimcore_version"]) || !empty($params["pimcore_preview"]) || !empty($params["pimcore_admin"]) || !empty($params["pimcore_editmode"]) || $document->isPublished() || !empty($_COOKIE["pimcore_admin_sid"])) {
                         $params["document"] = $document;
                         if ($controller = $document->getController()) {
                             $params["controller"] = $controller;
                             $params["action"] = "index";
                         }
                         if ($action = $document->getAction()) {
                             $params["action"] = $action;
                         }
                         if ($module = $document->getModule()) {
                             $params["module"] = $module;
                         }
                         // check for a trailing slash in path, if exists, redirect to this page without the slash
                         // the only reason for this is: SEO, Analytics, ... there is no system specific reason, pimcore would work also with a trailing slash without problems
                         // use $originalPath because of the sites
                         if ($config->documents->allowtrailingslash) {
                             if ($config->documents->allowtrailingslash == "no") {
                                 if (substr($originalPath, strlen($originalPath) - 1, 1) == "/" && $originalPath != "/") {
                                     $redirectUrl = rtrim($originalPath, "/");
                                     if ($_SERVER["QUERY_STRING"]) {
                                         $redirectUrl .= "?" . $_SERVER["QUERY_STRING"];
                                     }
                                     header("Location: " . $redirectUrl, true, 301);
                                     exit;
                                 }
                             }
                         }
                         if ($config->documents->allowcapitals) {
                             if ($config->documents->allowcapitals == "no") {
                                 if (strtolower($originalPath) != $originalPath) {
                                     $redirectUrl = strtolower($originalPath);
                                     if ($_SERVER["QUERY_STRING"]) {
                                         $redirectUrl .= "?" . $_SERVER["QUERY_STRING"];
                                     }
                                     header("Location: " . $redirectUrl, true, 301);
                                     exit;
                                 }
                             }
                         }
                         $matchFound = true;
                     }
                 } else {
                     if ($document->getType() == "link") {
                         // if the document is a link just redirect to the location/href of the link
                         header("Location: " . $document->getHref(), true, 301);
                         exit;
                     }
                 }
             }
         } catch (Exception $e) {
             // no suitable page found
         }
     }
     // test if there is a suitable static route
     if (!$matchFound) {
         try {
             $cacheKey = "system_route_staticroute";
             if (!($routes = Pimcore_Model_Cache::load($cacheKey))) {
                 $list = new Staticroute_List();
                 $list->setOrderKey("priority");
                 $list->setOrder("DESC");
                 $routes = $list->load();
                 Pimcore_Model_Cache::save($routes, $cacheKey, array("system", "staticroute", "route"), null, 998);
             }
             foreach ($routes as $route) {
                 if (@preg_match($route->getPattern(), $originalPath) && !$matchFound) {
                     $params = array_merge($route->getDefaultsArray(), $params);
                     $variables = explode(",", $route->getVariables());
                     preg_match_all($route->getPattern(), $originalPath, $matches);
                     if (is_array($matches) && count($matches) > 1) {
                         foreach ($matches as $index => $match) {
                             if ($variables[$index - 1]) {
                                 $params[$variables[$index - 1]] = $match[0];
                             }
                         }
                     }
                     $controller = $route->getController();
                     $action = $route->getAction();
                     $module = trim($route->getModule());
                     // check for dynamic controller / action / module
                     $dynamicRouteReplace = function ($item, $params) {
                         if (strpos($item, "%") !== false) {
                             foreach ($params as $key => $value) {
                                 $dynKey = "%" . $key;
                                 if (strpos($item, $dynKey) !== false) {
                                     return str_replace($dynKey, $value, $item);
                                 }
                             }
                         }
                         return $item;
                     };
                     $controller = $dynamicRouteReplace($controller, $params);
                     $action = $dynamicRouteReplace($action, $params);
                     $module = $dynamicRouteReplace($module, $params);
                     $params["controller"] = $controller;
                     $params["action"] = $action;
                     if (!empty($module)) {
                         $params["module"] = $module;
                     }
                     // try to get nearest document to the route
                     $params["document"] = $this->getNearestDocumentByPath($path);
                     $matchFound = true;
                     Staticroute::setCurrentRoute($route);
                     break;
                 }
             }
         } catch (Exception $e) {
             // no suitable route found
         }
     }
     // test if there is a suitable redirect
     if (!$matchFound) {
         $this->checkForRedirect(false);
     }
     if (!$matchFound && $site instanceof Site) {
         if ($config->general->domain) {
             header("Location: http://" . $_SERVER["HTTP_HOST"], true, 301);
         } else {
             $errorMessage = "You have to specify a main domain in system-settings (Settings -> System -> Website -> Domain) if you want to use sites!";
             Logger::emerg($errorMessage);
             die($errorMessage);
         }
         exit;
     }
     if (!$matchFound) {
         return false;
     }
     // remove pimcore magic parameters
     unset($params["pimcore_outputfilters_disabled"]);
     unset($params["pimcore_document"]);
     unset($params["nocache"]);
     return $params;
 }
Пример #10
0
 protected static function l($m)
 {
     Logger::emerg($m);
 }