コード例 #1
0
ファイル: Frontend.php プロジェクト: tododo/pimcore
 /**
  * @throws \Zend_Controller_Router_Exception
  */
 public function init()
 {
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         \Pimcore::getEventManager()->trigger("frontend.controller.preInit", $this);
     }
     parent::init();
     // log exceptions if handled by error_handler
     $this->checkForErrors();
     // general definitions
     if (self::$isInitial) {
         \Pimcore::unsetAdminMode();
         Document::setHideUnpublished(true);
         Object\AbstractObject::setHideUnpublished(true);
         Object\AbstractObject::setGetInheritedValues(true);
         Object\Localizedfield::setGetFallbackValues(true);
     }
     // assign variables
     $this->view->controller = $this;
     // init website config
     $config = Config::getWebsiteConfig();
     $this->config = $config;
     $this->view->config = $config;
     $document = $this->getParam("document");
     if (!$document instanceof Document) {
         \Zend_Registry::set("pimcore_editmode", false);
         $this->editmode = false;
         $this->view->editmode = false;
         self::$isInitial = false;
         // check for a locale first, and set it if available
         if ($this->getParam("pimcore_parentDocument")) {
             // this is a special exception for renderlets in editmode (ajax request), because they depend on the locale of the parent document
             // otherwise there'll be notices like:  Notice: 'No translation for the language 'XX' available.'
             if ($parentDocument = Document::getById($this->getParam("pimcore_parentDocument"))) {
                 if ($parentDocument->getProperty("language")) {
                     $this->setLocaleFromDocument($parentDocument->getProperty("language"));
                 }
             }
         }
         // no document available, continue, ...
         return;
     } else {
         $this->setDocument($document);
         // register global locale if the document has the system property "language"
         if ($this->getDocument()->getProperty("language")) {
             $this->setLocaleFromDocument($this->getDocument()->getProperty("language"));
         }
         if (self::$isInitial) {
             // append meta-data to the headMeta() view helper,  if it is a document-request
             if (!Model\Staticroute::getCurrentRoute() && $this->getDocument() instanceof Document\Page) {
                 if (is_array($this->getDocument()->getMetaData())) {
                     foreach ($this->getDocument()->getMetaData() as $meta) {
                         // only name
                         if (!empty($meta["idName"]) && !empty($meta["idValue"]) && !empty($meta["contentValue"])) {
                             $method = "append" . ucfirst($meta["idName"]);
                             $this->view->headMeta()->{$method}($meta["idValue"], $meta["contentValue"]);
                         }
                     }
                 }
             }
         }
     }
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         // contains the logged in user if necessary
         $user = null;
         // default is to set the editmode to false, is enabled later if necessary
         \Zend_Registry::set("pimcore_editmode", false);
         if (Tool::isFrontentRequestByAdmin()) {
             $this->disableBrowserCache();
             // start admin session & get logged in user
             $user = Authentication::authenticateSession();
         }
         if (\Pimcore::inDebugMode()) {
             $this->disableBrowserCache();
         }
         if (!$this->document->isPublished()) {
             if (Tool::isFrontentRequestByAdmin()) {
                 if (!$user) {
                     throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
                 }
             } else {
                 throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
             }
         }
         // logged in users only
         if ($user) {
             // set the user to registry so that it is available via \Pimcore\Tool\Admin::getCurrentUser();
             \Zend_Registry::set("pimcore_admin_user", $user);
             // document editmode
             if ($this->getParam("pimcore_editmode")) {
                 \Zend_Registry::set("pimcore_editmode", true);
                 // check if there is the document in the session
                 $docKey = "document_" . $this->getDocument()->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     // if there is a document in the session use it
                     $this->setDocument($docSession->{$docKey});
                 } else {
                     // set the latest available version for editmode if there is no doc in the session
                     $latestVersion = $this->getDocument()->getLatestVersion();
                     if ($latestVersion) {
                         $latestDoc = $latestVersion->loadData();
                         if ($latestDoc instanceof Document\PageSnippet) {
                             $this->setDocument($latestDoc);
                         }
                     }
                 }
                 // register editmode plugin
                 $front = \Zend_Controller_Front::getInstance();
                 $front->registerPlugin(new \Pimcore\Controller\Plugin\Frontend\Editmode($this), 1000);
             }
             // document preview
             if ($this->getParam("pimcore_preview")) {
                 // get document from session
                 $docKey = "document_" . $this->getParam("document")->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     $this->setDocument($docSession->{$docKey});
                 }
             }
             // object preview
             if ($this->getParam("pimcore_object_preview")) {
                 $key = "object_" . $this->getParam("pimcore_object_preview");
                 $session = Session::getReadOnly("pimcore_objects");
                 if ($session->{$key}) {
                     $object = $session->{$key};
                     // add the object to the registry so every call to Object::getById() will return this object instead of the real one
                     \Zend_Registry::set("object_" . $object->getId(), $object);
                 }
             }
             // for version preview
             if ($this->getParam("pimcore_version")) {
                 // only get version data at the first call || because of embedded Snippets ...
                 if (!\Zend_Registry::isRegistered("pimcore_version_active")) {
                     $version = Model\Version::getById($this->getParam("pimcore_version"));
                     $this->setDocument($version->getData());
                     \Zend_Registry::set("pimcore_version_active", true);
                 }
             }
         }
         // for public versions
         if ($this->getParam("v")) {
             try {
                 $version = Model\Version::getById($this->getParam("v"));
                 if ($version->getPublic()) {
                     $this->setDocument($version->getData());
                 }
             } catch (\Exception $e) {
             }
         }
         // check for persona
         if ($this->getDocument() instanceof Document\Page) {
             $this->getDocument()->setUsePersona(null);
             // reset because of preview and editmode (saved in session)
             if ($this->getParam("_ptp") && self::$isInitial) {
                 $this->getDocument()->setUsePersona($this->getParam("_ptp"));
             }
         }
         // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document
         if ($this->getDocument() instanceof Document\Hardlink\Wrapper\WrapperInterface) {
             // get the cononical (source) document
             $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId());
             $request = $this->getRequest();
             if (\Pimcore\Tool\Frontend::isDocumentInCurrentSite($hardlinkCanonicalSourceDocument)) {
                 $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"');
             }
         }
         \Pimcore::getEventManager()->trigger("frontend.controller.postInit", $this);
     }
     // set some parameters
     $this->editmode = \Zend_Registry::get("pimcore_editmode");
     $this->view->editmode = \Zend_Registry::get("pimcore_editmode");
     self::$isInitial = false;
 }
コード例 #2
0
 public function init()
 {
     parent::init();
     // log exceptions if handled by error_handler
     $this->checkForErrors();
     // general definitions
     Pimcore::unsetAdminMode();
     Document::setHideUnpublished(true);
     Object_Abstract::setHideUnpublished(true);
     Object_Abstract::setGetInheritedValues(true);
     // contains the logged in user if necessary
     $user = null;
     // assign variables
     $this->view->controller = $this;
     // init website config
     $config = Pimcore_Config::getWebsiteConfig();
     $this->config = $config;
     $this->view->config = $config;
     if (!$this->_getParam("document")) {
         Zend_Registry::set("pimcore_editmode", false);
         $this->editmode = false;
         $this->view->editmode = false;
         // no document available, continue, ...
         return;
     } else {
         $this->setDocument($this->_getParam("document"));
     }
     if ($this->_getParam("pimcore_editmode") || $this->_getParam("pimcore_version") || $this->_getParam("pimcore_preview") || $this->_getParam("pimcore_admin") || $this->_getParam("pimcore_object_preview")) {
         $specialAdminRequest = true;
         $this->disableBrowserCache();
         // start admin session & get logged in user
         $user = Pimcore_Tool_Authentication::authenticateSession();
     }
     if (!$this->document->isPublished()) {
         if ($specialAdminRequest) {
             if (!$user) {
                 throw new Exception("access denied for " . $this->document->getFullPath());
             }
         } else {
             throw new Exception("access denied for " . $this->document->getFullPath());
         }
     }
     // register global locale if the document has the system property "language"
     if ($this->document->getProperty("language")) {
         $locale = new Zend_Locale($this->document->getProperty("language"));
         Zend_Registry::set('Zend_Locale', $locale);
         $this->getResponse()->setHeader("Content-Language", strtolower(str_replace("_", "-", (string) $locale)), true);
     }
     // for editmode
     if ($user) {
         if ($this->_getParam("pimcore_editmode") and !Zend_Registry::isRegistered("pimcore_editmode")) {
             Zend_Registry::set("pimcore_editmode", true);
             // check if there is the document in the session
             $docKey = "document_" . $this->getDocument()->getId();
             $docSession = new Zend_Session_Namespace("pimcore_documents");
             if ($docSession->{$docKey}) {
                 // if there is a document in the session use it
                 $this->setDocument($docSession->{$docKey});
             } else {
                 // set the latest available version for editmode if there is no doc in the session
                 $latestVersion = $this->getDocument()->getLatestVersion();
                 if ($latestVersion) {
                     $latestDoc = $latestVersion->loadData();
                     if ($latestDoc instanceof Document_PageSnippet) {
                         $this->setDocument($latestDoc);
                     }
                 }
             }
             // register editmode plugin
             $front = Zend_Controller_Front::getInstance();
             $front->registerPlugin(new Pimcore_Controller_Plugin_Frontend_Editmode($this), 1000);
         } else {
             Zend_Registry::set("pimcore_editmode", false);
         }
     } else {
         Zend_Registry::set("pimcore_editmode", false);
     }
     // for preview
     if ($user) {
         // document preview
         if ($this->_getParam("pimcore_preview")) {
             // get document from session
             $docKey = "document_" . $this->_getParam("document")->getId();
             $docSession = new Zend_Session_Namespace("pimcore_documents");
             if ($docSession->{$docKey}) {
                 $this->setDocument($docSession->{$docKey});
             }
         }
         // object preview
         if ($this->_getParam("pimcore_object_preview")) {
             $key = "object_" . $this->_getParam("pimcore_object_preview");
             $session = new Zend_Session_Namespace("pimcore_objects");
             if ($session->{$key}) {
                 $object = $session->{$key};
                 // add the object to the registry so every call to Object_Abstract::getById() will return this object instead of the real one
                 Zend_Registry::set("object_" . $object->getId(), $object);
             }
         }
     }
     // for version preview
     if ($this->_getParam("pimcore_version")) {
         if ($user) {
             // only get version data at the first call || because of embedded Snippets ...
             if (!Zend_Registry::isRegistered("pimcore_version_active")) {
                 $version = Version::getById($this->_getParam("pimcore_version"));
                 $this->setDocument($version->getData());
                 Zend_Registry::set("pimcore_version_active", true);
             }
         }
     }
     // for public versions
     if ($this->_getParam("v")) {
         try {
             $version = Version::getById($this->_getParam("v"));
             if ($version->getPublic()) {
                 $this->setDocument($version->getData());
             }
         } catch (Exception $e) {
         }
     }
     // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document
     if ($this->getDocument() instanceof Document_Hardlink_Wrapper_Interface) {
         // get the cononical (source) document
         $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId());
         $request = $this->getRequest();
         $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"');
     }
     // set some parameters
     $this->editmode = Zend_Registry::get("pimcore_editmode");
     $this->view->editmode = Zend_Registry::get("pimcore_editmode");
 }
コード例 #3
0
$request = new \Zend_Controller_Request_Http();
$request->setModuleName(PIMCORE_FRONTEND_MODULE);
$request->setControllerName("default");
$request->setActionName("default");
$front->setRequest($request);
$front->setResponse(new \Zend_Controller_Response_Cli());
// generic pimcore setup
\Pimcore::setSystemRequirements();
\Pimcore::initAutoloader();
\Pimcore::initConfiguration();
\Pimcore::setupFramework();
\Pimcore::initLogger();
\Pimcore::initModules();
\Pimcore::initPlugins();
//Activate Inheritance for cli-scripts
\Pimcore::unsetAdminMode();
Document::setHideUnpublished(true);
Object\AbstractObject::setHideUnpublished(true);
Object\AbstractObject::setGetInheritedValues(true);
Object\Localizedfield::setGetFallbackValues(true);
// CLI has no memory/time limits
@ini_set('memory_limit', -1);
@ini_set('max_execution_time', -1);
@ini_set('max_input_time', -1);
// Error reporting is enabled in CLI
@ini_set("display_errors", "On");
@ini_set("display_startup_errors", "On");
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
// Pimcore\Console handles maintenance mode through the AbstractCommand
if (!$pimcoreConsole) {
    // skip if maintenance mode is on and the flag is not set
コード例 #4
0
ファイル: BatchProcessing.php プロジェクト: ascertain/NGshop
 /**
  * prepare data for index creation and store is in store table
  *
  * @param OnlineShop_Framework_ProductInterfaces_IIndexable $object
  */
 public function prepareDataForIndex(OnlineShop_Framework_ProductInterfaces_IIndexable $object)
 {
     $subObjectIds = $this->tenantConfig->createSubIdsForObject($object);
     foreach ($subObjectIds as $subObjectId => $object) {
         /**
          * @var OnlineShop_Framework_ProductInterfaces_IIndexable $object
          */
         if ($object->getOSDoIndexProduct() && $this->tenantConfig->inIndex($object)) {
             $a = Pimcore::inAdmin();
             $b = \Pimcore\Model\Object\AbstractObject::doGetInheritedValues();
             Pimcore::unsetAdminMode();
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues(true);
             $hidePublishedMemory = \Pimcore\Model\Object\AbstractObject::doHideUnpublished();
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished(false);
             $categories = $object->getCategories();
             $categoryIds = array();
             $parentCategoryIds = array();
             if ($categories) {
                 foreach ($categories as $c) {
                     $parent = $c;
                     if ($parent != null) {
                         if ($parent->getOSProductsInParentCategoryVisible()) {
                             while ($parent && $parent instanceof OnlineShop_Framework_AbstractCategory) {
                                 $parentCategoryIds[$parent->getId()] = $parent->getId();
                                 $parent = $parent->getParent();
                             }
                         } else {
                             $parentCategoryIds[$parent->getId()] = $parent->getId();
                         }
                         $categoryIds[$c->getId()] = $c->getId();
                     }
                 }
             }
             ksort($categoryIds);
             $virtualProductId = $subObjectId;
             $virtualProductActive = $object->isActive();
             if ($object->getOSIndexType() == "variant") {
                 $virtualProductId = $this->tenantConfig->createVirtualParentIdForSubId($object, $subObjectId);
             }
             $virtualProduct = \Pimcore\Model\Object\AbstractObject::getById($virtualProductId);
             if ($virtualProduct && method_exists($virtualProduct, "isActive")) {
                 $virtualProductActive = $virtualProduct->isActive();
             }
             $data = array("o_id" => $subObjectId, "o_classId" => $object->getClassId(), "o_virtualProductId" => $virtualProductId, "o_virtualProductActive" => $virtualProductActive, "o_parentId" => $object->getOSParentId(), "o_type" => $object->getOSIndexType(), "categoryIds" => ',' . implode(",", $categoryIds) . ",", "parentCategoryIds" => ',' . implode(",", $parentCategoryIds) . ",", "priceSystemName" => $object->getPriceSystemName(), "active" => $object->isActive(), "inProductList" => $object->isActive(true));
             $relationData = array();
             $columnConfig = $this->columnConfig->column;
             if (!empty($columnConfig->name)) {
                 $columnConfig = array($columnConfig);
             } else {
                 if (empty($columnConfig)) {
                     $columnConfig = array();
                 }
             }
             foreach ($columnConfig as $column) {
                 try {
                     //$data[$column->name] = null;
                     $value = null;
                     if (!empty($column->getter)) {
                         $getter = $column->getter;
                         $value = $getter::get($object, $column->config, $subObjectId, $this->tenantConfig);
                     } else {
                         if (!empty($column->fieldname)) {
                             $getter = "get" . ucfirst($column->fieldname);
                         } else {
                             $getter = "get" . ucfirst($column->name);
                         }
                         if (method_exists($object, $getter)) {
                             $value = $object->{$getter}($column->locale);
                         }
                     }
                     if (!empty($column->interpreter)) {
                         $interpreter = $column->interpreter;
                         $value = $interpreter::interpret($value, $column->config);
                         $interpreterObject = new $interpreter();
                         if ($interpreterObject instanceof OnlineShop_Framework_IndexService_RelationInterpreter) {
                             foreach ($value as $v) {
                                 $relData = array();
                                 $relData['src'] = $subObjectId;
                                 $relData['src_virtualProductId'] = $virtualProductId;
                                 $relData['dest'] = $v['dest'];
                                 $relData['fieldname'] = $column->name;
                                 $relData['type'] = $v['type'];
                                 $relationData[] = $relData;
                             }
                         } else {
                             $data[$column->name] = $value;
                         }
                     } else {
                         $data[$column->name] = $value;
                     }
                     if (is_array($data[$column->name])) {
                         $data[$column->name] = OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER . implode($data[$column->name], OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER) . OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER;
                     }
                 } catch (Exception $e) {
                     Logger::err("Exception in IndexService: " . $e->getMessage(), $e);
                 }
             }
             if ($a) {
                 Pimcore::setAdminMode();
             }
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues($b);
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished($hidePublishedMemory);
             $subTenantData = $this->tenantConfig->prepareSubTenantEntries($object, $subObjectId);
             $jsonData = json_encode(array("data" => $data, "relations" => $relationData ? $relationData : [], "subtenants" => $subTenantData ? $subTenantData : []));
             $crc = crc32($jsonData);
             $insertData = array("id" => $subObjectId, "tenant" => $this->name, "data" => $jsonData, "crc_current" => $crc, "preparation_worker_timestamp" => 0, "preparation_worker_id" => $this->db->quote(null), "in_preparation_queue" => 0);
             $currentEntry = $this->db->fetchRow("SELECT crc_current, in_preparation_queue FROM " . $this->getStoreTableName() . " WHERE id = ? AND tenant = ?", array($subObjectId, $this->name));
             if (!$currentEntry) {
                 $this->db->insert($this->getStoreTableName(), $insertData);
             } else {
                 if ($currentEntry['crc_current'] != $crc) {
                     $this->db->update($this->getStoreTableName(), $insertData, "id = " . $this->db->quote((string) $subObjectId) . " AND tenant = " . $this->db->quote($this->name));
                 } else {
                     if ($currentEntry['in_preparation_queue']) {
                         $this->db->query("UPDATE " . $this->getStoreTableName() . " SET in_preparation_queue = 0, preparation_worker_timestamp = 0, preparation_worker_id = null WHERE id = ? AND tenant = ?", array($subObjectId, $this->name));
                     }
                 }
             }
         } else {
             Logger::info("Don't adding product " . $subObjectId . " to index " . $this->name . ".");
             $this->doDeleteFromIndex($subObjectId);
         }
     }
     //cleans up all old zombie data
     $this->doCleanupOldZombieData($object, $subObjectIds);
 }
コード例 #5
0
ファイル: DefaultMysql.php プロジェクト: ascertain/NGshop
 public function updateIndex(OnlineShop_Framework_ProductInterfaces_IIndexable $object)
 {
     if (!$this->tenantConfig->isActive($object)) {
         Logger::info("Tenant {$this->name} is not active.");
         return;
     }
     $subObjectIds = $this->tenantConfig->createSubIdsForObject($object);
     foreach ($subObjectIds as $subObjectId => $object) {
         if ($object->getOSDoIndexProduct() && $this->tenantConfig->inIndex($object)) {
             $a = Pimcore::inAdmin();
             $b = \Pimcore\Model\Object\AbstractObject::doGetInheritedValues();
             Pimcore::unsetAdminMode();
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues(true);
             $hidePublishedMemory = \Pimcore\Model\Object\AbstractObject::doHideUnpublished();
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished(false);
             $categories = $object->getCategories();
             $themes = $object->getTheme();
             $categoryIds = array();
             $parentCategoryIds = array();
             if ($categories) {
                 foreach ($categories as $c) {
                     $parent = $c;
                     if ($parent != null) {
                         if ($parent->getOSProductsInParentCategoryVisible()) {
                             while ($parent && $parent instanceof OnlineShop_Framework_AbstractCategory) {
                                 $parentCategoryIds[$parent->getId()] = $parent->getId();
                                 $parent = $parent->getParent();
                             }
                         } else {
                             $parentCategoryIds[$parent->getId()] = $parent->getId();
                         }
                         $categoryIds[$c->getId()] = $c->getId();
                     }
                 }
             }
             $themeIds = array();
             if ($themes) {
                 foreach ($themes as $theme) {
                     $parent = $theme;
                     if ($parent != null) {
                         $themeIds[$theme->getId()] = $theme->getId();
                     }
                 }
             }
             ksort($categoryIds);
             $virtualProductId = $subObjectId;
             $virtualProductActive = $object->isActive();
             if ($object->getOSIndexType() == "variant") {
                 $virtualProductId = $this->tenantConfig->createVirtualParentIdForSubId($object, $subObjectId);
             }
             $virtualProduct = \Pimcore\Model\Object\AbstractObject::getById($virtualProductId);
             if ($virtualProduct && method_exists($virtualProduct, "isActive")) {
                 $virtualProductActive = $virtualProduct->isActive();
             }
             $data = array("o_id" => $subObjectId, "o_classId" => $object->getClassId(), "o_virtualProductId" => $virtualProductId, "o_virtualProductActive" => $virtualProductActive, "o_parentId" => $object->getOSParentId(), "o_type" => $object->getOSIndexType(), "categoryIds" => ',' . implode(",", $categoryIds) . ",", "parentCategoryIds" => ',' . implode(",", $parentCategoryIds) . ",", "priceSystemName" => $object->getPriceSystemName(), "active" => $object->isActive(), "inProductList" => $object->isActive(true), "theme" => ',' . implode(",", $themeIds) . ",");
             $relationData = array();
             $columnConfig = $this->columnConfig->column;
             if (!empty($columnConfig->name)) {
                 $columnConfig = array($columnConfig);
             } else {
                 if (empty($columnConfig)) {
                     $columnConfig = array();
                 }
             }
             foreach ($columnConfig as $column) {
                 try {
                     $value = null;
                     if (!empty($column->getter)) {
                         $getter = $column->getter;
                         $value = $getter::get($object, $column->config, $subObjectId, $this->tenantConfig);
                     } else {
                         if (!empty($column->fieldname)) {
                             $getter = "get" . ucfirst($column->fieldname);
                         } else {
                             $getter = "get" . ucfirst($column->name);
                         }
                         if (method_exists($object, $getter)) {
                             $value = $object->{$getter}($column->locale);
                         }
                     }
                     if (!empty($column->interpreter)) {
                         $interpreter = $column->interpreter;
                         $value = $interpreter::interpret($value, $column->config);
                         $interpreterObject = new $interpreter();
                         if ($interpreterObject instanceof OnlineShop_Framework_IndexService_RelationInterpreter) {
                             foreach ($value as $v) {
                                 $relData = array();
                                 $relData['src'] = $subObjectId;
                                 $relData['src_virtualProductId'] = $virtualProductId;
                                 $relData['dest'] = $v['dest'];
                                 $relData['fieldname'] = $column->name;
                                 $relData['type'] = $v['type'];
                                 $relationData[] = $relData;
                             }
                         } else {
                             $data[$column->name] = $value;
                         }
                     } else {
                         $data[$column->name] = $value;
                     }
                     if (is_array($data[$column->name])) {
                         $data[$column->name] = OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER . implode($data[$column->name], OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER) . OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER;
                     }
                 } catch (Exception $e) {
                     Logger::err("Exception in IndexService: " . $e->getMessage(), $e);
                 }
             }
             if ($a) {
                 Pimcore::setAdminMode();
             }
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues($b);
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished($hidePublishedMemory);
             try {
                 $this->doInsertData($data);
             } catch (Exception $e) {
                 Logger::warn("Error during updating index table: " . $e);
             }
             try {
                 $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId));
                 foreach ($relationData as $rd) {
                     $this->db->insert($this->tenantConfig->getRelationTablename(), $rd);
                 }
             } catch (Exception $e) {
                 Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e);
             }
         } else {
             Logger::info("Don't adding product " . $subObjectId . " to index.");
             try {
                 $this->db->delete($this->tenantConfig->getTablename(), "o_id = " . $this->db->quote($subObjectId));
             } catch (Exception $e) {
                 Logger::warn("Error during updating index table: " . $e->getMessage(), $e);
             }
             try {
                 $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId));
             } catch (Exception $e) {
                 Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e);
             }
             try {
                 if ($this->tenantConfig->getTenantRelationTablename()) {
                     $this->db->delete($this->tenantConfig->getTenantRelationTablename(), "o_id = " . $this->db->quote($subObjectId));
                 }
             } catch (Exception $e) {
                 Logger::warn("Error during updating index tenant relation table: " . $e->getMessage(), $e);
             }
         }
         $this->tenantConfig->updateSubTenantEntries($object, $subObjectId);
     }
     //cleans up all old zombie data
     $this->doCleanupOldZombieData($object, $subObjectIds);
 }
コード例 #6
0
ファイル: Frontend.php プロジェクト: ngocanh/pimcore
 public function init()
 {
     parent::init();
     // log exceptions if handled by error_handler
     $this->checkForErrors();
     // general definitions
     Pimcore::unsetAdminMode();
     Document::setHideUnpublished(true);
     Object_Abstract::setHideUnpublished(true);
     Object_Abstract::setGetInheritedValues(true);
     $adminSession = null;
     // assign variables
     $this->view->controller = $this;
     // init website config
     $config = Pimcore_Config::getWebsiteConfig();
     $this->config = $config;
     $this->view->config = $config;
     if (!$this->_getParam("document")) {
         Zend_Registry::set("pimcore_editmode", false);
         $this->editmode = false;
         $this->view->editmode = false;
         // no document available, continue, ...
         return;
     } else {
         $this->setDocument($this->_getParam("document"));
     }
     if ($this->_getParam("pimcore_editmode") || $this->_getParam("pimcore_version") || $this->_getParam("pimcore_preview") || $this->_getParam("pimcore_admin") || $this->_getParam("pimcore_object_preview")) {
         $specialAdminRequest = true;
         Pimcore_Tool_Authentication::initSession();
         // start admin session
         $adminSession = new Zend_Session_Namespace("pimcore_admin");
     }
     if (!$this->document->isPublished()) {
         if ($specialAdminRequest) {
             if (!$adminSession->user instanceof User) {
                 throw new Exception("access denied for " . $this->document->getFullPath());
             }
         } else {
             throw new Exception("access denied for " . $this->document->getFullPath());
         }
     }
     // register global locale if the document has the system property "language"
     if ($this->document->getProperty("language")) {
         $locale = new Zend_Locale($this->document->getProperty("language"));
         Zend_Registry::set('Zend_Locale', $locale);
     }
     // for editmode
     if ($adminSession && $adminSession->user instanceof User) {
         if ($this->_getParam("pimcore_editmode") and !Zend_Registry::isRegistered("pimcore_editmode")) {
             Zend_Registry::set("pimcore_editmode", true);
             // check if there is the document in the session
             $docKey = "document_" . $this->getDocument()->getId();
             $docSession = new Zend_Session_Namespace("pimcore_documents");
             if ($docSession->{$docKey}) {
                 // if there is a document in the session use it
                 $this->setDocument($docSession->{$docKey});
             } else {
                 // set the latest available version for editmode if there is no doc in the session
                 $latestVersion = $this->getDocument()->getLatestVersion();
                 if ($latestVersion) {
                     $latestDoc = $latestVersion->loadData();
                     if ($latestDoc instanceof Document_PageSnippet) {
                         $this->setDocument($latestDoc);
                     }
                 }
             }
             // register editmode plugin
             $front = Zend_Controller_Front::getInstance();
             $front->registerPlugin(new Pimcore_Controller_Plugin_Frontend_Editmode($this), 1000);
         } else {
             Zend_Registry::set("pimcore_editmode", false);
         }
     } else {
         Zend_Registry::set("pimcore_editmode", false);
     }
     // for preview
     if ($adminSession && $adminSession->user instanceof User) {
         // document preview
         if ($this->_getParam("pimcore_preview")) {
             // get document from session
             $docKey = "document_" . $this->_getParam("document")->getId();
             $docSession = new Zend_Session_Namespace("pimcore_documents");
             if ($docSession->{$docKey}) {
                 $this->setDocument($docSession->{$docKey});
             }
         }
         // object preview
         if ($this->_getParam("pimcore_object_preview")) {
             $key = "object_" . $this->_getParam("pimcore_object_preview");
             $session = new Zend_Session_Namespace("pimcore_objects");
             if ($session->{$key}) {
                 $object = $session->{$key};
                 // add the object to the registry so every call to Object_Abstract::getById() will return this object instead of the real one
                 Zend_Registry::set("object_" . $object->getId(), $object);
             }
         }
     }
     // for version preview
     if ($this->_getParam("pimcore_version")) {
         if ($adminSession && $adminSession->user instanceof User) {
             // only get version data at the first call || because of embedded Snippets ...
             try {
                 Zend_Registry::get("pimcore_version_active");
             } catch (Exception $e) {
                 $version = Version::getById($this->_getParam("pimcore_version"));
                 $this->setDocument($version->getData());
                 Zend_Registry::set("pimcore_version_active", true);
             }
         }
     }
     // for public versions
     if ($this->_getParam("v")) {
         try {
             $version = Version::getById($this->_getParam("v"));
             if ($version->getPublic()) {
                 $this->setDocument($version->getData());
             }
         } catch (Exception $e) {
         }
     }
     // set some parameters
     $this->editmode = Zend_Registry::get("pimcore_editmode");
     $this->view->editmode = Zend_Registry::get("pimcore_editmode");
 }