コード例 #1
0
ファイル: Admin.php プロジェクト: ngocanh/pimcore
 public function init()
 {
     parent::init();
     // set language
     try {
         $locale = Zend_Registry::get("Zend_Locale");
         $this->setLanguage($locale->getLanguage());
     } catch (Exception $e) {
         if ($this->_getParam("language")) {
             $this->setLanguage($this->_getParam("language"));
         } else {
             $config = Pimcore_Config::getSystemConfig();
             $this->setLanguage($config->general->language);
         }
     }
     try {
         Zend_Registry::get("pimcore_admin_initialized");
         $this->setUser(Zend_Registry::get("pimcore_admin_user"));
     } catch (Exception $e) {
         // 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');
         // 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);
                     return;
                 }
             }
         }
         // send a auth header for the client (is covered by the ajax object in javascript)
         if (!$this->getUser() instanceof User) {
             $this->getResponse()->setHeader("X-Pimcore-Auth", "required");
         }
         // redirect to the login-page if the user isn't authenticated
         if (!$this->getUser() instanceof User && !($this->_getParam("module") == "admin" && $this->_getParam("controller") == "login")) {
             $this->_redirect("/admin/login");
             $this->getResponse()->sendResponse();
             exit;
         }
         Zend_Registry::set("pimcore_admin_user", $this->getUser());
         Zend_Registry::set("pimcore_admin_initialized", true);
     }
 }
コード例 #2
0
 public function endpointAction()
 {
     // disable wsdl cache
     if (PIMCORE_DEVMODE) {
         ini_set("soap.wsdl_cache_enabled", "0");
     }
     // create classmappings
     $classMap = Webservice_Tool::createClassMappings();
     //        p_r($classMap); die();
     // create wsdl
     // @TODO create a cache here
     $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array("object[]" => "Zend_Soap_Wsdl_Strategy_AnyType"), "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
     $autodiscover = new Zend_Soap_AutoDiscover($strategy);
     $autodiscover->setClass('Webservice_Service');
     $wsdl = $autodiscover->toXml();
     //TODO: do we really want to normalize class names since we had to introduce request and response objects anyway?
     $wsdl = str_replace("Webservice_Data_", "", $wsdl);
     // normalize classnames
     $wsdlFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/wsdl.xml";
     file_put_contents($wsdlFile, $wsdl);
     chmod($wsdlFile, 0766);
     // let's go
     if (isset($_GET["wsdl"])) {
         header("Content-Type: text/xml; charset=utf8");
         echo $wsdl;
     } else {
         Pimcore::setAdminMode();
         Document::setHideUnpublished(false);
         Object_Abstract::setHideUnpublished(false);
         Object_Abstract::setGetInheritedValues(false);
         try {
             $server = new Zend_Soap_Server($wsdlFile, array("cache_wsdl" => false, "soap_version" => SOAP_1_2, "classmap" => $classMap));
             $server->registerFaultException("Exception");
             $server->setClass("Webservice_Service");
             $server->handle();
         } catch (Exception $e) {
             Logger::log("Soap request failed");
             Logger::log($e);
             throw $e;
         }
     }
     exit;
 }
コード例 #3
0
ファイル: Admin.php プロジェクト: shanky0110/pimcore-custom
 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;
     }
 }
コード例 #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);
 }