private function getObjectIds() { if ($this->search_result_ids === null) { $index = "idx_" . $this->class_name; $object_class = Object_Class::getByName($this->class_name); if ($object_class->getFieldDefinition("localizedfields")) { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); $index .= "_" . $language; } $query = $this->query; if (!$this->getUnpublished()) { $query = $query . " @o_published 1"; } $query .= " @o_type " . $this->object_type; $search_result = $this->SphinxClient->Query($query, $index); if ($search_result === false) { throw new Exception($this->SphinxClient->GetLastError() . "\n query:" . $this->query); } if ($search_result["total_found"] > 0) { $this->search_result_ids = array_keys($search_result["matches"]); } else { $this->search_result_ids = array(); } } return $this->search_result_ids; }
public function removeClass($name) { $class = Object_Class::getByName($name); if ($class) { $class->delete(); } }
/** * legacy - not required anymore * * * @return void */ protected function cleanUp() { try { $class = Object_Class::getByName("unittest"); if ($class instanceof Object_Class) { $class->delete(); } } catch (Exception $e) { } try { $objectRoot = Object_Abstract::getById(1); if ($objectRoot and $objectRoot->hasChilds()) { $childs = $objectRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $assetRoot = Asset::getById(1); if ($assetRoot and $assetRoot->hasChilds()) { $childs = $assetRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $documentRoot = Asset::getById(1); if ($documentRoot and $documentRoot->hasChilds()) { $childs = $documentRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $userList = new User_List(); $userList->setCondition("id > 1"); $users = $userList->load(); if (is_array($users) and count($users) > 0) { foreach ($users as $user) { $user->delete(); } } } catch (Exception $e) { } }
/** * gets recursively attribute data from parent and fills objectData and metaData * * @param $object * @param $key * @param $fielddefinition * @return void */ private function getDataForField($object, $key, $fielddefinition, $objectFromVersion, $level = 0) { $parent = Object_Service::hasInheritableParentObject($object); $getter = "get" . ucfirst($key); // relations but not for objectsMetadata, because they have additional data which cannot be loaded directly from the DB if (!$objectFromVersion && $fielddefinition instanceof Object_Class_Data_Relations_Abstract and $fielddefinition->getLazyLoading() and !$fielddefinition instanceof Object_Class_Data_ObjectsMetadata) { //lazy loading data is fetched from DB differently, so that not every relation object is instantiated if ($fielddefinition->isRemoteOwner()) { $refKey = $fielddefinition->getOwnerFieldName(); $refClass = Object_Class::getByName($fielddefinition->getOwnerClassName()); $refId = $refClass->getId(); } else { $refKey = $key; } $relations = $object->getRelationData($refKey, !$fielddefinition->isRemoteOwner(), $refId); if (empty($relations) && !empty($parent)) { $this->getDataForField($parent, $key, $fielddefinition, $objectFromVersion, $level + 1); } else { $data = array(); if ($fielddefinition instanceof Object_Class_Data_Href) { $data = $relations[0]; } else { foreach ($relations as $rel) { if ($fielddefinition instanceof Object_Class_Data_Objects) { $data[] = array($rel["id"], $rel["path"], $rel["subtype"]); } else { $data[] = array($rel["id"], $rel["path"], $rel["type"], $rel["subtype"]); } } } $this->objectData[$key] = $data; $this->metaData[$key]['objectid'] = $object->getId(); $this->metaData[$key]['inherited'] = $level != 0; } } else { $value = $fielddefinition->getDataForEditmode($object->{$getter}(), $object, $objectFromVersion); if (empty($value) && !empty($parent)) { $this->getDataForField($parent, $key, $fielddefinition, $objectFromVersion, $level + 1); } else { $isInheritedValue = $level != 0; $this->metaData[$key]['objectid'] = $object->getId(); $this->objectData[$key] = $value; $this->metaData[$key]['inherited'] = $isInheritedValue; if ($isInheritedValue && !empty($value) && !$this->isInheritableField($fielddefinition)) { $this->objectData[$key] = null; $this->metaData[$key]['inherited'] = false; $this->metaData[$key]['hasParentValue'] = true; } else { $parentValue = $this->getParentValue($object, $key); $this->metaData[$key]['hasParentValue'] = !empty($parentValue->value); if (!empty($parentValue->value)) { $this->metaData[$key]['objectid'] = $parentValue->id; } } } } }
/** * @throws Exception * @param $rootElement * @param $apiKey * @param $path * @param $apiElement * @param bool $overwrite * @param $elementCounter * @return Element_Interface */ public function create($rootElement, $apiKey, $path, $apiElement, $overwrite, $elementCounter) { //correct relative path if (strpos($path, "/") !== 0) { $path = $rootElement->getFullPath() . "/" . $path; } $type = $apiElement->type; if ($apiElement instanceof Webservice_Data_Asset) { $className = "Asset_" . ucfirst($type); $parentClassName = "Asset"; $maintype = "asset"; $fullPath = $path . $apiElement->filename; } else { if ($apiElement instanceof Webservice_Data_Object) { $maintype = "object"; if ($type == "object") { $className = "Object_" . ucfirst($apiElement->className); if (!class_exists($className)) { throw new Exception("Unknown class [ " . $className . " ]"); } } else { $className = "Object_" . ucfirst($type); } $parentClassName = "Object_Abstract"; $fullPath = $path . $apiElement->key; } else { if ($apiElement instanceof Webservice_Data_Document) { $maintype = "document"; $className = "Document_" . ucfirst($type); $parentClassName = "Document"; $fullPath = $path . $apiElement->key; } else { throw new Exception("Unknown import element"); } } } $existingElement = $className::getByPath($fullPath); if ($overwrite && $existingElement) { $apiElement->parentId = $existingElement->getParentId(); return $existingElement; } $element = new $className(); $element->setId(null); $element->setCreationDate(time()); if ($element instanceof Asset) { $element->setFilename($apiElement->filename); $element->setData(base64_decode($apiElement->data)); } else { if ($element instanceof Object_Concrete) { $element->setKey($apiElement->key); $element->setO_className($apiElement->className); $class = Object_Class::getByName($apiElement->className); if (!$class instanceof Object_Class) { throw new Exception("Unknown object class [ " . $apiElement->className . " ] "); } $element->setO_classId($class->getId()); } else { $element->setKey($apiElement->key); } } $this->setModificationParams($element, true); $key = $element->getKey(); if (empty($key) and $apiElement->id == 1) { if ($element instanceof Asset) { $element->setFilename("home_" . uniqid()); } else { $element->setKey("home_" . uniqid()); } } else { if (empty($key)) { throw new Exception("Cannot create element without key "); } } $parent = $parentClassName::getByPath($path); if (Element_Service::getType($rootElement) == $maintype and $parent) { $element->setParentId($parent->getId()); $apiElement->parentId = $parent->getId(); $existingElement = $parentClassName::getByPath($parent->getFullPath() . "/" . $element->getKey()); if ($existingElement) { //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } } } else { if (Element_Service::getType($rootElement) != $maintype) { //this is a related element - try to import it to it's original path or set the parent to home folder $potentialParent = $parentClassName::getByPath($path); //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } if ($potentialParent) { $element->setParentId($potentialParent->getId()); //set actual id and path for second run $apiElements[$apiKey]["path"] = $potentialParent->getFullPath(); $apiElement->parentId = $potentialParent->getId(); } else { $element->setParentId(1); //set actual id and path for second run $apiElements[$apiKey]["path"] = "/"; $apiElement->parentId = 1; } } else { $element->setParentId($rootElement->getId()); //set actual id and path for second run $apiElements[$apiKey]["path"] = $rootElement->getFullPath(); $apiElement->parentId = $rootElement->getId(); //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } } } //if element exists, make temp key permanent by setting it in apiElement if ($parentClassName::getByPath($fullPath)) { if ($element instanceof Asset) { $apiElement->filename = $element->getFilename(); } else { $apiElement->key = $element->getKey(); } } $element->save(); //todo save type and id for later rollback $this->importInfo[Element_Service::getType($element) . "_" . $element->getId()] = array("id" => $element->getId(), "type" => Element_Service::getType($element), "fullpath" => $element->getFullPath()); return $element; }
if (is_file($file)) { $string = file_get_contents($file); $classname = basename($file, ".json"); $class = Object_Class::getByName($classname); unset($classes_array[$classname]); if ($class) { Object_Class_Service::importClassDefinitionFromJson($class, $string); } else { $newClass = Object_Class::create(array("name" => $classname)); Object_Class_Service::importClassDefinitionFromJson($newClass, $string); } } } // usuwanie klas foreach ($classes_array as $classname => $tmp) { $class = Object_Class::getByName($classname); $class->delete(); echo "Delete class: " . $classname . "\n"; } // Objectbricks migration $classesList = new Object_Objectbrick_Definition_List(); $classes = $classesList->load(); $classes_array = array(); // array of existing collections /** @var Object_Objectbrick_Definition $class */ foreach ($classes as $class) { $classes_array[$class->getKey()] = true; } $files = glob(PIMCORE_DOCUMENT_ROOT . '/data/objectbricks/*'); // get all file names // tworzenie kolekcji na podstawie plików
public function batchAction() { $success = true; try { $object = Object_Abstract::getById($this->_getParam("job")); if ($object) { $className = $object->getO_className(); $class = Object_Class::getByName($className); $value = $this->_getParam("value"); if ($this->_getParam("valueType") == "object") { $value = Zend_Json::decode($value); } $name = $this->_getParam("name"); $parts = explode("~", $name); // check for bricks if (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object_Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "Object_Objectbrick_Data_" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brickClass = Object_Objectbrick_Definition::getByKey($brickType); $field = $brickClass->getFieldDefinition($brickKey); $brick->{$valueSetter}($field->getDataFromEditmode($value, $object)); } else { // everything else $field = $class->getFieldDefinition($name); if ($field) { $object->setValue($name, $field->getDataFromEditmode($value, $object)); } else { // seems to be a system field, this is actually only possible for the "published" field yet if ($name == "published") { if ($value == "false" || empty($value)) { $object->setPublished(false); } else { $object->setPublished(true); } } } } try { // don't check for mandatory fields here $object->setOmitMandatoryCheck(true); $object->save(); $success = true; } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { Logger::debug("ObjectController::batchAction => There is no object left to update."); $this->_helper->json(array("success" => false, "message" => "ObjectController::batchAction => There is no object left to update.")); } } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } $this->_helper->json(array("success" => $success)); }
/** * @return void */ public function findAction() { $user = $this->getUser(); $query = $this->_getParam("query"); if ($query == "*") { $query = ""; } $query = str_replace("%", "*", $query); $types = explode(",", $this->_getParam("type")); $subtypes = explode(",", $this->_getParam("subtype")); $classnames = explode(",", $this->_getParam("class")); $offset = intval($this->_getParam("start")); $limit = intval($this->_getParam("limit")); $offset = $offset ? $offset : 0; $limit = $limit ? $limit : 50; $searcherList = new Search_Backend_Data_List(); $conditionParts = array(); $db = Pimcore_Resource::get(); //exclude forbidden assets if (in_array("asset", $types)) { if (!$user->isAllowed("assets")) { $forbiddenConditions[] = " `type` != 'asset' "; } else { $forbiddenAssetPaths = Element_Service::findForbiddenPaths("asset", $user); if (count($forbiddenAssetPaths) > 0) { for ($i = 0; $i < count($forbiddenAssetPaths); $i++) { $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths); } } } //exclude forbidden documents if (in_array("document", $types)) { if (!$user->isAllowed("documents")) { $forbiddenConditions[] = " `type` != 'document' "; } else { $forbiddenDocumentPaths = Element_Service::findForbiddenPaths("document", $user); if (count($forbiddenDocumentPaths) > 0) { for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) { $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths); } } } //exclude forbidden objects if (in_array("object", $types)) { if (!$user->isAllowed("objects")) { $forbiddenConditions[] = " `type` != 'object' "; } else { $forbiddenObjectPaths = Element_Service::findForbiddenPaths("object", $user); if (count($forbiddenObjectPaths) > 0) { for ($i = 0; $i < count($forbiddenObjectPaths); $i++) { $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths); } } } if ($forbiddenConditions) { $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")"; } if (!empty($query)) { $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )"; // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index // if the query is numeric the user might want to search by id //if(is_numeric($query)) { //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )"; //} $conditionParts[] = $queryCondition; } //For objects - handling of bricks $fields = array(); $bricks = array(); if ($this->_getParam("fields")) { $fields = $this->_getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); if (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } // filtering for objects if ($this->_getParam("filter")) { $class = Object_Class::getByName($this->_getParam("class")); $conditionFilters = Object_Service::getFilterCondition($this->_getParam("filter"), $class); $join = ""; foreach ($bricks as $ob) { $join .= " LEFT JOIN object_brick_query_" . $ob . "_" . $class->getId(); $join .= " `" . $ob . "`"; $join .= " ON `" . $ob . "`.o_id = `object_" . $class->getId() . "`.o_id"; } $conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE 1=1 " . $conditionFilters . ") )"; } if (is_array($types) and !empty($types[0])) { foreach ($types as $type) { $conditionTypeParts[] = $db->quote($type); } $conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )"; } if (is_array($subtypes) and !empty($subtypes[0])) { foreach ($subtypes as $subtype) { $conditionSubtypeParts[] = $db->quote($subtype); } $conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )"; } if (is_array($classnames) and !empty($classnames[0])) { if (in_array("folder", $subtypes)) { $classnames[] = "folder"; } foreach ($classnames as $classname) { $conditionClassnameParts[] = $db->quote($classname); } $conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )"; } if (count($conditionParts) > 0) { $condition = implode(" AND ", $conditionParts); //echo $condition; die(); $searcherList->setCondition($condition); } $searcherList->setOffset($offset); $searcherList->setLimit($limit); // do not sort per default, it is VERY SLOW //$searcherList->setOrder("desc"); //$searcherList->setOrderKey("modificationdate"); if ($this->_getParam("sort")) { $searcherList->setOrderKey($this->_getParam("sort")); } if ($this->_getParam("dir")) { $searcherList->setOrder($this->_getParam("dir")); } $hits = $searcherList->load(); $elements = array(); foreach ($hits as $hit) { $element = Element_Service::getElementById($hit->getId()->getType(), $hit->getId()->getId()); if ($element->isAllowed("list")) { if ($element instanceof Object_Abstract) { $data = Object_Service::gridObjectData($element, $fields); } else { if ($element instanceof Document) { $data = Document_Service::gridDocumentData($element); } else { if ($element instanceof Asset) { $data = Asset_Service::gridAssetData($element); } } } $elements[] = $data; } else { //TODO: any message that view is blocked? //$data = Element_Service::gridElementData($element); } } // only get the real total-count when the limit parameter is given otherwise use the default limit if ($this->_getParam("limit")) { $totalMatches = $searcherList->getTotalCount(); } else { $totalMatches = count($elements); } $this->_helper->json(array("data" => $elements, "success" => true, "total" => $totalMatches)); $this->removeViewRenderer(); }
private static function searchObjects($query, $class_name, $params = array()) { if (trim($query) == "") { return array(); } $class_name = strtolower($class_name); $sphinx_config = SphinxSearch_Config::getInstance(); $SphinxClient = new SphinxClient(); $SphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2); $SphinxClient->setServer("localhost", intval(SphinxSearch_Config_Plugin::getValue("searchd", "port"))); if (array_key_exists("language", $params)) { $language = $params["language"]; } else { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); } if (array_key_exists("orderKey", $params)) { $order = "ASC"; if (array_key_exists("order", $params)) { $order = $params["order"] == "DESC" ? "DESC" : "ASC"; } $SphinxClient->SetSortMode(SPH_SORT_EXPR, $params["orderKey"] . " " . $order); } $max_results = 1000; // TODO intval(SphinxSearch_Config_Plugin::getValue($config->maxresults); if (array_key_exists("max_results", $params)) { $max_results = intval($params["max_results"]); if ($max_results < 1) { $max_results = 20; } // Sphinx default actually } $offset = 0; if (array_key_exists("offset", $params)) { $offset = intval($params["offset"]); } $SphinxClient->setLimits($offset, $max_results, $max_results); $class_config = $sphinx_config->getClassesAsArray(); // The configuration $field_weights = array(); foreach ($class_config[$class_name] as $field_name => $field_config) { if (array_key_exists("weight", $field_config)) { $field_weights[$field_name] = $field_config["weight"]; } } if (sizeof($field_weights) > 0) { $SphinxClient->setFieldWeights($field_weights); } $index = "idx_" . $class_name; $object_class = Object_Class::getByName($class_name); if (!$object_class) { throw new SphinxSearch_Exception("Class \"" . $class_name . "\" not found."); } if ($object_class->getFieldDefinition("localizedfields")) { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); $index .= "_" . $language; } $search_result = $SphinxClient->Query($query, $index); if ($search_result === false) { throw new Exception($SphinxClient->GetLastError()); } return $search_result; }
<?php //TODO: finish View $class = Object_Class::getByName("CoreShopUser"); $postValue = function ($name) { if (isset($_POST[$name])) { return $_POST[$name]; } return; }; ?> <div id="main-container" class="container"> <!-- Breadcrumb Starts --> <ol class="breadcrumb"> <li><a href="<?php echo $this->url(array("lang" => $this->language), "coreshop_index", true); ?> "><?php echo $this->translate("Home"); ?> </a></li> <li class="active"><a href="<?php echo $this->url(array("lang" => $this->language, "action" => "register"), "coreshop_checkout"); ?> "><?php echo $this->translate("Register"); ?> </a></li> </ol>
public static function reindex_objects($object) { $config = SphinxSearch_Config::getInstance(); switch (SphinxSearch_Config_Plugin::getValue("indexer", "onchange")) { case "immediately": $indexes = array(); foreach ($config->getClasses()->children() as $class) { /** * @var $class SimpleXMLElement */ if ($object instanceof Object_Abstract) { $class_name = $class->getName(); } else { $class_name = $object; } if (strtolower("Object_" . $class_name) == strtolower(get_class($object))) { $object_class = Object_Class::getByName($class_name); // Do we have localized fields? if ($object_class->getFieldDefinition("localizedfields")) { $pimcore_languages = Pimcore_Tool::getValidLanguages(); foreach ($pimcore_languages as $lang) { $source_class_name = $class_name . "_" . $lang; $indexes[] = "idx_" . $source_class_name; } } else { $indexes[] = "idx_" . $class_name; } } } if (sizeof($indexes) > 0) { $indexes = implode(" ", $indexes); self::runIndexer($indexes); } break; case "reschedule": SphinxSearch_Config_Plugin::setValue("indexer", "lastrun", 0); break; default: // Do nothing break; } }
/** * @return boolean $isInstalled */ public static function isInstalled() { $entry = Object_Class::getByName('BlogEntry'); $category = Object_Class::getByName('BlogCategory'); if ($entry && $category) { return true; } return false; }
public function writeSphinxConfig() { $pimcore_config = Pimcore_Config::getSystemConfig(); $params = $pimcore_config->database->params; $db_host = $params->host; $db_user = $params->username; $db_password = $params->password; $db_name = $params->dbname; $db_port = $params->port; $index_path = SPHINX_VAR . DIRECTORY_SEPARATOR . "index"; $cli_path = PIMCORE_PLUGINS_PATH . DIRECTORY_SEPARATOR . "SphinxSearch" . DIRECTORY_SEPARATOR . "cli"; $pid_path = SphinxSearch_Config_Plugin::getValue("path", "pid"); $logfile_path = SphinxSearch_Config_Plugin::getValue("path", "log"); $querylog_path = SphinxSearch_Config_Plugin::getValue("path", "querylog"); $port = SphinxSearch_Config_Plugin::getValue("searchd", "port"); if (substr($pid_path, 0, 1) != DIRECTORY_SEPARATOR) { $pid_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $pid_path; } if (substr($logfile_path, 0, 1) != DIRECTORY_SEPARATOR) { $logfile_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $logfile_path; } if (substr($querylog_path, 0, 1) != DIRECTORY_SEPARATOR) { $querylog_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $querylog_path; } $config = <<<EOL indexer { mem_limit = 32M } searchd { port = {$port} log = {$logfile_path} query_log = {$querylog_path} read_timeout = 5 max_children = 30 pid_file = {$pid_path} max_matches = 1000 seamless_rotate = 1 preopen_indexes = 0 unlink_old = 1 } EOL; $indexer = SphinxSearch_Config_Plugin::getValue("path", "phpcli") . " " . $cli_path . DIRECTORY_SEPARATOR . "index_documents.php"; $documents_config = $this->getDocumentsAsArray(); $languages = array("all"); if (SphinxSearch_Config_Plugin::getValue("documents", "use_i18n") == "true") { $languages = Pimcore_Tool::getValidLanguages(); } foreach ($languages as $lang) { foreach ($documents_config as $document_name => $document_properties) { $source_name = "document_" . $document_name . "_" . $lang; $index_name = "idx_document_" . $document_name . "_" . $lang; $document_index_path = $index_path . DIRECTORY_SEPARATOR . "document_" . $document_name . "_" . $lang; $config .= <<<EOL source {$source_name} { type = xmlpipe2 xmlpipe_command = {$indexer} -d {$document_name} -l {$lang} } index {$index_name} { source = {$source_name} path = {$document_index_path} charset_type = utf-8 } EOL; } } foreach ($this->getClasses()->children() as $class) { /** * @var $class SimpleXMLElement */ $class_name = $class->getName(); $object_class = Object_Class::getByName($class_name); $fields = array("oo_id", "o_creationDate", "o_modificationDate", "o_published", "o_type"); $attributes = array("o_creationDate" => "sql_attr_timestamp", "o_modificationDate" => "sql_attr_timestamp", "o_published" => "sql_field_string", "o_type" => "sql_field_string"); foreach ($class->children() as $field) { $fields[] = $field->attributes()->name; if ($field->attributes()->field_type) { $attributes[$field->attributes()->name->__toString()] = $field->attributes()->field_type; } } $fields = "`" . implode("`,`", $fields) . "`"; $attributes_definition = ""; foreach ($attributes as $key => $value) { $attributes_definition .= " {$value} = {$key}\n"; // Yes, really $value first } // Do we have localized fields? if ($object_class->getFieldDefinition("localizedfields")) { $pimcore_languages = Pimcore_Tool::getValidLanguages(); foreach ($pimcore_languages as $lang) { $source_class_name = $class_name . "_" . $lang; $table = "object_localized_" . $object_class->getId() . "_" . $lang; $config .= <<<EOL source {$source_class_name} { type = mysql sql_host = {$db_host} sql_user = {$db_user} sql_pass = {$db_password} sql_db = {$db_name} sql_port = {$db_port} # optional, default is 3306 sql_query = SELECT {$fields} FROM {$table} sql_query_info = SELECT oo_id FROM {$table} WHERE oo_id=\$id {$attributes_definition} } index idx_{$source_class_name} { source = {$source_class_name} path = {$index_path}/{$source_class_name} docinfo = extern charset_type = utf-8 min_word_len = 1 min_prefix_len = 0 min_infix_len = 1 } EOL; } } else { $table = "object_" . $object_class->getId(); $document_index_path = $index_path . DIRECTORY_SEPARATOR . $class_name; $config .= <<<EOL source {$class_name} { type = mysql sql_host = {$db_host} sql_user = {$db_user} sql_pass = {$db_password} sql_db = {$db_name} sql_port = {$db_port} # optional, default is 3306 sql_query = SELECT {$fields} FROM {$table} sql_query_info = SELECT oo_id FROM {$table} WHERE oo_id=\$id {$attributes_definition} } index idx_{$class_name} { source = {$class_name} path = {$document_index_path} docinfo = extern charset_type = utf-8 min_word_len = 1 min_prefix_len = 0 min_infix_len = 1 } EOL; } } if (is_dir(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf.d")) { foreach (glob(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf.d/*.conf") as $filename) { $config .= file_get_contents($filename); } } file_put_contents(SPHINX_VAR . DIRECTORY_SEPARATOR . "sphinx.conf", $config); }
/** * * Checks if an object is an allowed relation * @param Object_Abstract $object * @return boolean */ protected function allowObjectRelation($object) { //only relations of owner type are allowed $ownerClass = Object_Class::getByName($this->getOwnerClassName()); if ($ownerClass->getId() > 0 and $ownerClass->getId() == $object->getO_classId()) { $fd = $ownerClass->getFieldDefinition($this->getOwnerFieldName()); if ($fd instanceof Object_Class_Data_Objects) { return $fd->allowObjectRelation($object); } } else { return false; } }