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); } }
public function __construct($element) { parent::__construct($element); if ($element instanceof Object_Product) { $backup = Object_Abstract::doGetInheritedValues($element); Object_Abstract::setGetInheritedValues(true); if ($element->getParent() instanceof Object_Product) { $this->elementIcon = '/pimcore/static/img/icon/tag_green.png'; $this->elementIconClass = null; } else { $this->elementIcon = '/pimcore/static/img/icon/tag_blue.png'; $this->elementIconClass = null; } Object_Abstract::setGetInheritedValues($backup); } }
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; }
public function init() { parent::init(); // enable layout only if its a normal request if ($this->getRequest()->isXmlHttpRequest() === false) { $this->enableLayout(); $this->setLayout('back-office'); } // sprache setzen $language = $this->getUser() ? $this->getUser()->getLanguage() : 'en'; Zend_Registry::set("Zend_Locale", new Zend_Locale($language)); $this->language = $language; $this->view->language = $language; $this->initTranslation(); // enable inherited values Object_Abstract::setGetInheritedValues(true); Object_Localizedfield::setGetFallbackValues(true); // init $this->orderManager = OnlineShop_Framework_Factory::getInstance()->getOrderManager(); }
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; } }
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"); }
* 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-2010 elements.at New Media Solutions GmbH (http://www.elements.at) * @license http://www.pimcore.org/license New BSD License */ $workingDirectory = getcwd(); chdir(__DIR__); include_once "../config/startup.php"; chdir($workingDirectory); Pimcore::initAutoloader(); Pimcore::initConfiguration(); Pimcore::setupFramework(); Pimcore::initLogger(); Pimcore::initModules(); Pimcore::initPlugins(); //Activate Inheritance for cli-scripts Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); Object_Abstract::setHideUnpublished(true); Object_Abstract::setGetInheritedValues(true); // Error reporting is enabled in CLI @ini_set("display_errors", "On"); @ini_set("display_startup_errors", "On"); error_reporting(E_ALL ^ E_NOTICE);
/** * @return void */ protected function update() { $fieldDefintions = $this->getO_class()->getFieldDefinitions(); foreach ($fieldDefintions as $fd) { $getter = "get" . ucfirst($fd->getName()); $setter = "set" . ucfirst($fd->getName()); if (method_exists($this, $getter)) { //To make sure, inherited values are not set again $inheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(false); $value = $this->{$getter}(); if (is_array($value) and ($fd instanceof Object_Class_Data_Multihref or $fd instanceof Object_Class_Data_Objects)) { //don't save relations twice $this->{$setter}(array_unique($value)); } Object_Abstract::setGetInheritedValues($inheritedValues); $value = $this->{$getter}(); $omitMandatoryCheck = $this->getOmitMandatoryCheck(); /*$timeSinceCreation = (time()-$this->getCreationDate()); if($timeSinceCreation <= 5){ // legacy hack: in previous version there was no check for mandatory fields, // and everybody uses the save method for new object creation - so now let's evict the mandatory check // if the object was created within the last 5 seconds $omitMandatoryCheck=true; Logger::debug("executing mandatory fields check for object [ ".$this->getId()." ]"); } */ //check throws Exception try { $fd->checkValidity($value, $omitMandatoryCheck); } catch (Exception $e) { if ($this->getO_class()->getAllowInherit()) { //try again with parent data when inheritance in activated try { $getInheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); $value = $this->{$getter}(); $fd->checkValidity($value, $omitMandatoryCheck); Object_Abstract::setGetInheritedValues($getInheritedValues); } catch (Exception $e) { throw new Exception($e->getMessage() . " fieldname=" . $fd->getName()); } } else { throw new Exception($e->getMessage() . " fieldname=" . $fd->getName()); } } } } parent::update(); $this->getResource()->update(); $this->saveScheduledTasks(); $this->saveVersion(false, false); $this->saveChilds(); Pimcore_API_Plugin_Broker::getInstance()->postUpdateObject($this); }
/** * @param Element_Interface $element * @return void */ public function setDataFromElement($element) { $this->data = null; $this->id = new Search_Backend_Data_Id($element); $this->fullPath = $element->getFullPath(); $this->creationDate = $element->getCreationDate(); $this->modificationDate = $element->getModificationDate(); $this->userModification = $element->getUserModification(); $this->userOwner = $element->getUserOwner(); $this->type = $element->getType(); if ($element instanceof Object_Concrete) { $this->subtype = $element->getO_className(); } else { $this->subtype = $this->type; } $properties = $element->getProperties(); if (is_array($properties)) { foreach ($properties as $nextProperty) { if ($nextProperty->getType() == 'text') { $this->properties .= $nextProperty->getData() . " "; } } } if ($element instanceof Document) { if ($element instanceof Document_Folder) { $this->data = $element->getKey(); $this->published = true; } else { if ($element instanceof Document_Link) { $this->published = $element->isPublished(); $this->data = $element->getName() . " " . $element->getTitle() . " " . $element->getHref(); } else { if ($element instanceof Document_PageSnippet) { $this->published = $element->isPublished(); $elements = $element->getElements(); if (is_array($elements)) { foreach ($elements as $tag) { if ($tag instanceof Document_Tag_Interface) { ob_start(); $this->data .= strip_tags($tag->frontend()) . " "; $this->data .= ob_get_clean(); } } } if ($element instanceof Document_Page) { $this->published = $element->isPublished(); $this->data .= " " . $element->getName() . " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords(); } } } } } else { if ($element instanceof Asset) { $this->data = $element->getFilename(); $this->published = true; } else { if ($element instanceof Object_Abstract) { if ($element instanceof Object_Concrete) { $getInheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); $this->published = $element->isPublished(); foreach ($element->getClass()->getFieldDefinitions() as $key => $value) { // Object_Class_Data_Fieldcollections is special because it doesn't support the csv export if ($value instanceof Object_Class_Data_Fieldcollections) { $getter = "get" . $value->getName(); $this->fieldcollectionData .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->{$getter}(), $element)) . " "; } else { if ($value instanceof Object_Class_Data_Localizedfields) { $getter = "get" . $value->getName(); $this->localizedData .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->{$getter}(), $element)) . " "; } else { $this->data .= $value->getForCsvExport($element) . " "; } } } Object_Abstract::setGetInheritedValues($getInheritedValues); } else { if ($element instanceof Object_Folder) { $this->data = $element->getKey(); $this->published = true; } } } else { Logger::crit("Search_Backend_Data received an unknown element!"); } } } }
/** * @param Object_Concrete $object * @return void */ public function save(Object_Concrete $object) { // HACK: set the pimcore admin mode to false to get the inherited values from parent if this source one is empty $inheritedValues = Object_Abstract::doGetInheritedValues(); $storetable = $this->model->getDefinition()->getTableName($object->getClass(), false); $querytable = $this->model->getDefinition()->getTableName($object->getClass(), true); $this->inheritanceHelper = new Object_Concrete_Resource_InheritanceHelper($object->getClassId(), "o_id", $storetable, $querytable); $this->createDataRows($object); Object_Abstract::setGetInheritedValues(false); $fd = $this->model->getDefinition()->getFieldDefinitions(); $data = array(); $data["o_id"] = $object->getId(); $data["fieldname"] = $this->model->getFieldname(); // remove all relations try { $this->db->delete("object_relations_" . $object->getClassId(), "src_id = " . $object->getId() . " AND ownertype = 'objectbrick' AND ownername = '" . $this->model->getFieldname() . "'"); } catch (Exception $e) { Logger::warning("Error during removing old relations: " . $e); } foreach ($fd as $key => $value) { $getter = "get" . ucfirst($value->getName()); if (method_exists($fd, "save")) { // for fieldtypes which have their own save algorithm eg. objects, multihref, ... $value->save($this->model); } else { if ($value->getColumnType()) { if (is_array($value->getColumnType())) { $insertDataArray = $value->getDataForResource($this->model->{$getter}(), $object); $data = array_merge($data, $insertDataArray); } else { $insertData = $value->getDataForResource($this->model->{$getter}(), $object); $data[$key] = $insertData; } } else { if (method_exists($value, "save")) { // for fieldtypes which have their own save algorithm eg. fieldcollections $value->save($this->model); } } } } $this->db->update($storetable, $data, $this->db->quoteInto("o_id = ?", $object->getId())); // get data for query table // $tableName = $this->model->getDefinition()->getTableName($object->getClass(), true); // this is special because we have to call each getter to get the inherited values from a possible parent object Object_Abstract::setGetInheritedValues(true); $objectVars = get_object_vars($this->model); $data = array(); $data["o_id"] = $object->getId(); $data["fieldname"] = $this->model->getFieldname(); $this->inheritanceHelper->resetFieldsToCheck(); $oldData = $this->db->fetchRow("SELECT * FROM " . $querytable . " WHERE o_id = ?", $object->getId()); foreach ($objectVars as $key => $value) { $fd = $this->model->getDefinition()->getFieldDefinition($key); if ($fd) { if ($fd->getQueryColumnType()) { //exclude untouchables if value is not an array - this means data has not been loaded if (!is_array($this->model->{$key})) { $method = "get" . $key; $insertData = $fd->getDataForQueryResource($this->model->{$method}(), $object); if (is_array($insertData)) { $data = array_merge($data, $insertData); } else { $data[$key] = $insertData; } //get changed fields for inheritance if ($fd->isRelationType()) { if (is_array($insertData)) { $doInsert = false; foreach ($insertData as $insertDataKey => $insertDataValue) { if ($oldData[$insertDataKey] != $insertDataValue) { $doInsert = true; } } if ($doInsert) { $this->inheritanceHelper->addRelationToCheck($key, array_keys($insertData)); } } else { if ($oldData[$key] != $insertData) { $this->inheritanceHelper->addRelationToCheck($key); } } } else { if (is_array($insertData)) { foreach ($insertData as $insertDataKey => $insertDataValue) { if ($oldData[$insertDataKey] != $insertDataValue) { $this->inheritanceHelper->addFieldToCheck($insertDataKey); } } } else { if ($oldData[$key] != $insertData) { $this->inheritanceHelper->addFieldToCheck($key); } } } } else { Logger::debug("Excluding untouchable query value for object - objectbrick [ " . $object->getId() . " ] key [ {$key} ] because it has not been loaded"); } } } } $this->db->update($querytable, $data, "o_id = " . $object->getId()); $this->inheritanceHelper->doUpdate($object->getId()); $this->inheritanceHelper->resetFieldsToCheck(); // HACK: see a few lines above! Object_Abstract::setGetInheritedValues($inheritedValues); }
/** * @param Object_Concrete $object * @return void */ public function save($object) { $getters = $this->getBrickGetters(); foreach ($getters as $getter) { $brick = $this->{$getter}(); if ($brick instanceof Object_Objectbrick_Data_Abstract) { if ($brick->getDoDelete()) { $brick->delete($object); $setter = "s" . substr($getter, 1); $this->{$setter}(null); //check if parent object has brick, and if so, create an empty brick to enable inheritance $parentBrick = null; $inheritanceModeBackup = Object_Abstract::getGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); if (Object_Abstract::doGetInheritedValues($object)) { $container = $object->getValueFromParent($this->fieldname); if (!empty($container)) { $parentBrick = $container->{$getter}(); } } Object_Abstract::setGetInheritedValues($inheritanceModeBackup); if (!empty($parentBrick)) { $brickType = "Object_Objectbrick_Data_" . ucfirst($parentBrick->getType()); $brick = new $brickType($object); $brick->setFieldname($this->getFieldname()); $brick->save($object); $this->{$setter}($brick); } } else { $brick->setFieldname($this->getFieldname()); $brick->save($object); } } else { if ($brick == null) { $parentBrick = null; $inheritanceModeBackup = Object_Abstract::getGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); if (Object_Abstract::doGetInheritedValues($object)) { $container = $object->getValueFromParent($this->fieldname); if (!empty($container)) { $parentBrick = $container->{$getter}(); } } Object_Abstract::setGetInheritedValues($inheritanceModeBackup); if (!empty($parentBrick)) { $brickType = "Object_Objectbrick_Data_" . ucfirst($parentBrick->getType()); $brick = new $brickType($object); $brick->setFieldname($this->getFieldname()); $brick->save($object); } } } } }
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"); }
/** * Save changes to database, it's an good idea to use save() instead * * @return void */ public function update() { // check if the rows must be inserted or updated in the query and store table if ($this->model->getId()) { try { $this->insertOrUpdate = $this->db->fetchRow("SELECT\r\n object_store_" . $this->model->getO_classId() . ".oo_id as store, object_query_" . $this->model->getO_classId() . ".oo_id as query, object.o_id as object\r\n FROM\r\n (SELECT o_id FROM objects WHERE o_id = " . $this->model->getId() . ") as object LEFT JOIN\r\n object_store_" . $this->model->getO_classId() . " ON object.o_id = object_store_" . $this->model->getO_classId() . ".oo_id LEFT JOIN\r\n object_query_" . $this->model->getO_classId() . " ON object.o_id = object_query_" . $this->model->getO_classId() . ".oo_id;"); } catch (Exception $e) { $this->insertOrUpdate = null; } } if (empty($this->insertOrUpdate)) { $this->insertOrUpdate = array("query" => null, "store" => null, "object" => null); } parent::update(); //$this->createDataRows(); // get fields which shouldn't be updated $fd = $this->model->geto_class()->getFieldDefinitions(); $untouchable = array(); foreach ($fd as $key => $value) { if (method_exists($value, "getLazyLoading") && $value->getLazyLoading()) { if (!in_array($key, $this->model->getLazyLoadedFields())) { //this is a relation subject to lazy loading - it has not been loaded $untouchable[] = $key; } } } // empty relation table except the untouchable fields (eg. lazy loading fields) if (count($untouchable) > 0) { $untouchables = "'" . implode("','", $untouchable) . "'"; $this->db->delete("object_relations_" . $this->model->getO_classId(), $this->db->quoteInto("src_id = ? AND fieldname not in (" . $untouchables . ") AND ownertype = 'object'", $this->model->getO_id())); } else { $this->db->delete("object_relations_" . $this->model->getO_classId(), $this->db->quoteInto("src_id = ? AND ownertype = 'object'", $this->model->getO_id())); } $inheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(false); $data = array(); $data["oo_id"] = $this->model->getO_id(); foreach ($fd as $key => $value) { $getter = "get" . ucfirst($key); if (method_exists($value, "save")) { // for fieldtypes which have their own save algorithm eg. fieldcollections, objects, multihref, ... $value->save($this->model); } else { if ($value->getColumnType()) { // pimcore saves the values with getDataForResource if (is_array($value->getColumnType())) { $insertDataArray = $value->getDataForResource($this->model->{$getter}(), $this->model); if (is_array($insertDataArray)) { $data = array_merge($data, $insertDataArray); } } else { $insertData = $value->getDataForResource($this->model->{$getter}(), $this->model); $data[$key] = $insertData; } } } } if ($this->insertOrUpdate["store"]) { $this->db->update("object_store_" . $this->model->getO_classId(), $data, $this->db->quoteInto("oo_id = ?", $this->model->getO_id())); } else { $this->db->insert("object_store_" . $this->model->getO_classId(), $data); } // get data for query table // this is special because we have to call each getter to get the inherited values from a possible parent object Object_Abstract::setGetInheritedValues(true); $object = get_object_vars($this->model); $data = array(); $this->inheritanceHelper->resetFieldsToCheck(); $oldData = $this->db->fetchRow("SELECT * FROM object_query_" . $this->model->getO_classId() . " WHERE oo_id = ?", $this->model->getId()); foreach ($object as $key => $value) { $fd = $this->model->geto_class()->getFieldDefinition($key); if ($fd) { if ($fd->getQueryColumnType()) { //exclude untouchables if value is not an array - this means data has not been loaded if (!(in_array($key, $untouchable) and !is_array($this->model->{$key}))) { $method = "get" . $key; $insertData = $fd->getDataForQueryResource($this->model->{$method}(), $this->model); if (is_array($insertData)) { $data = array_merge($data, $insertData); } else { $data[$key] = $insertData; } //get changed fields for inheritance if ($fd->isRelationType()) { if (is_array($insertData)) { $doInsert = false; foreach ($insertData as $insertDataKey => $insertDataValue) { if ($oldData[$insertDataKey] != $insertDataValue) { $doInsert = true; } } if ($doInsert) { $this->inheritanceHelper->addRelationToCheck($key, array_keys($insertData)); } } else { if ($oldData[$key] != $insertData) { $this->inheritanceHelper->addRelationToCheck($key); } } } else { if (is_array($insertData)) { foreach ($insertData as $insertDataKey => $insertDataValue) { if ($oldData[$insertDataKey] != $insertDataValue) { $this->inheritanceHelper->addFieldToCheck($insertDataKey); } } } else { if ($oldData[$key] != $insertData) { $this->inheritanceHelper->addFieldToCheck($key); } } } } else { Logger::debug("Excluding untouchable query value for object [ " . $this->model->getId() . " ] key [ {$key} ] because it has not been loaded"); } } } } $data["oo_id"] = $this->model->getO_id(); if ($this->insertOrUpdate["query"]) { $this->db->update("object_query_" . $this->model->getO_classId(), $data, $this->db->quoteInto("oo_id = ?", $this->model->getO_id())); } else { $this->db->insert("object_query_" . $this->model->getO_classId(), $data); } Object_Abstract::setGetInheritedValues($inheritedValues); unset($this->insertOrUpdate); }
/** * @param Element_Interface $element * @return void */ public function setDataFromElement($element) { $this->data = null; $this->id = new Search_Backend_Data_Id($element); $this->fullPath = $element->getFullPath(); $this->creationDate = $element->getCreationDate(); $this->modificationDate = $element->getModificationDate(); $this->userModification = $element->getUserModification(); $this->userOwner = $element->getUserOwner(); $this->type = $element->getType(); if ($element instanceof Object_Concrete) { $this->subtype = $element->getO_className(); } else { $this->subtype = $this->type; } $this->properties = ""; $properties = $element->getProperties(); if (is_array($properties)) { foreach ($properties as $nextProperty) { if ($nextProperty->getType() == 'text') { $this->properties .= $nextProperty->getData() . " "; } } } $this->data = ""; if ($element instanceof Document) { if ($element instanceof Document_Folder) { $this->data = $element->getKey(); $this->published = true; } else { if ($element instanceof Document_Link) { $this->published = $element->isPublished(); $this->data = $element->getName() . " " . $element->getTitle() . " " . $element->getHref(); } else { if ($element instanceof Document_PageSnippet) { $this->published = $element->isPublished(); $elements = $element->getElements(); if (is_array($elements) && !empty($elements)) { foreach ($elements as $tag) { if ($tag instanceof Document_Tag_Interface) { ob_start(); $this->data .= strip_tags($tag->frontend()) . " "; $this->data .= ob_get_clean(); } } } if ($element instanceof Document_Page) { $this->published = $element->isPublished(); $this->data .= " " . $element->getName() . " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords(); } } } } } else { if ($element instanceof Asset) { $this->data = $element->getFilename(); $this->published = true; } else { if ($element instanceof Object_Abstract) { if ($element instanceof Object_Concrete) { $getInheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); $this->published = $element->isPublished(); foreach ($element->getClass()->getFieldDefinitions() as $key => $value) { // Object_Class_Data_Fieldcollections, Object_Class_Data_Localizedfields and Object_Class_Data_Objectbricks is special because it doesn't support the csv export if ($value instanceof Object_Class_Data_Fieldcollections) { $getter = "get" . $value->getName(); $fcData = $element->{$getter}(); if ($fcData instanceof Object_Fieldcollection) { foreach ($fcData as $item) { if (!$item instanceof Object_Fieldcollection_Data_Abstract) { continue; } try { $collectionDef = Object_Fieldcollection_Definition::getByKey($item->getType()); } catch (Exception $e) { continue; } foreach ($collectionDef->getFieldDefinitions() as $fd) { $this->data .= $fd->getForCsvExport($item) . " "; } } } //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." "; } else { if ($value instanceof Object_Class_Data_Localizedfields) { // only for text-values at the moment, because the CSV doesn't work for localized fields (getter-problem) $getter = "get" . $value->getName(); $lfData = $element->{$getter}(); if ($lfData instanceof Object_Localizedfield) { foreach ($lfData->getItems() as $language => $values) { foreach ($values as $lData) { if (is_string($lData)) { $this->data .= $lData . " "; } } } } //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." "; } else { if ($value instanceof Object_Class_Data_Objectbricks) { $getter = "get" . $value->getName(); $obData = $element->{$getter}(); if ($obData instanceof Object_Objectbrick) { $items = $obData->getItems(); foreach ($items as $item) { if (!$item instanceof Object_Objectbrick_Data_Abstract) { continue; } try { $collectionDef = Object_Objectbrick_Definition::getByKey($item->getType()); } catch (Exception $e) { continue; } foreach ($collectionDef->getFieldDefinitions() as $fd) { $this->data .= $fd->getForCsvExport($item) . " "; } } } //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." "; } else { $this->data .= $value->getForCsvExport($element) . " "; } } } } Object_Abstract::setGetInheritedValues($getInheritedValues); } else { if ($element instanceof Object_Folder) { $this->data = $element->getKey(); $this->published = true; } } } else { Logger::crit("Search_Backend_Data received an unknown element!"); } } } if ($element instanceof Element_Interface) { $this->data = "ID: " . $element->getId() . " \nPath: " . $this->getFullPath() . " \n" . $this->cleanupData($this->data); } }