Пример #1
0
 public function getTableName(Object_Class $class, $query = false)
 {
     if ($query) {
         return "object_brick_query_" . $this->model->getKey() . "_" . $class->getId();
     } else {
         return "object_brick_store_" . $this->model->getKey() . "_" . $class->getId();
     }
 }
Пример #2
0
 /**
  * makes sure, that the creation of objects with duplicate paths is not possible
  * @expectedException Zend_Db_Statement_Exception
  * @depends testClassCreate
  */
 public function testDuplicateClassName()
 {
     $class = Object_Class::create();
     $class->setName("unittest");
     $class->setUserOwner(1);
     $class->save();
 }
 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;
 }
Пример #4
0
 public function removeClass($name)
 {
     $class = Object_Class::getByName($name);
     if ($class) {
         $class->delete();
     }
 }
Пример #5
0
 /**
  * Loads a list of object-classes for the specicifies parameters, returns an array of Object_Class elements
  *
  * @return array
  */
 public function load()
 {
     $classes = array();
     $classesRaw = $this->db->fetchCol("SELECT id FROM classes" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($classesRaw as $classRaw) {
         $classes[] = Object_Class::getById($classRaw);
     }
     $this->model->setClasses($classes);
     return $classes;
 }
Пример #6
0
 /**
  * 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) {
     }
 }
 public function saveAction()
 {
     $class = Object_Class::getById(intval($this->getParam("id")));
     $class_config = Zend_Json::decode($this->getParam("configuration"));
     $class_name = strtolower($class->getName());
     $classes = $this->config->getClasses();
     unset($classes->{$class_name});
     $classes->addChild($class_name);
     $this->setSphinxValues($class_config, $class_name, $classes);
     if ($classes->{$class_name}->count() == 0) {
         unset($classes->{$class_name});
     }
     // remove empty classes
     $this->config->writeXml();
     $this->config->writeSphinxConfig();
     $this->_helper->json(array("success" => true));
 }
Пример #8
0
 public function __destruct()
 {
     // write sql change log for deploying to production system
     if (!empty($this->_sqlChangeLog)) {
         $log = implode("\n\n\n", $this->_sqlChangeLog);
         $filename = "db-change-log_" . time() . "_class-" . $this->model->getName() . ".sql";
         $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $filename;
         if (defined("PIMCORE_DB_CHANGELOG_DIRECTORY")) {
             $file = PIMCORE_DB_CHANGELOG_DIRECTORY . "/" . $filename;
         }
         $logContent = '';
         if (file_exists($filename) && is_readable($filename)) {
             $logContent = file_get_contents($filename) . "\n\n\n";
         }
         file_put_contents($logContent . $file, $log);
         chmod($file, 0766);
         $this->_sqlChangeLog = array();
     }
 }
Пример #9
0
 public function getClassDefinitionForColumnConfigAction()
 {
     $class = Object_Class::getById(intval($this->_getParam("id")));
     $class->setFieldDefinitions(null);
     $result = array();
     $result['objectColumns']['childs'] = $class->getLayoutDefinitions()->getChilds();
     $result['objectColumns']['nodeLabel'] = "object_columns";
     $result['objectColumns']['nodeType'] = "object";
     $systemColumnNames = Object_Concrete::$systemColumnNames;
     // array("id", "fullpath", "published", "creationDate", "modificationDate", "filename", "classname");
     $systemColumns = array();
     foreach ($systemColumnNames as $systemColumn) {
         $systemColumns[] = array("title" => $systemColumn, "name" => $systemColumn, "datatype" => "data", "fieldtype" => "system");
     }
     $result['systemColumns']['nodeLabel'] = "system_columns";
     $result['systemColumns']['nodeType'] = "system";
     $result['systemColumns']['childs'] = $systemColumns;
     $list = new Object_Objectbrick_Definition_List();
     $list = $list->load();
     foreach ($list as $brickDefinition) {
         $classDefs = $brickDefinition->getClassDefinitions();
         if (!empty($classDefs)) {
             foreach ($classDefs as $classDef) {
                 if ($classDef['classname'] == $class->getId()) {
                     $key = $brickDefinition->getKey();
                     $result[$key]['nodeLabel'] = $key;
                     $result[$key]['nodeType'] = "objectbricks";
                     $result[$key]['childs'] = $brickDefinition->getLayoutdefinitions()->getChilds();
                     break;
                 }
             }
         }
     }
     $this->_helper->json($result);
 }
Пример #10
0
 public function getTableName(Object_Class $class)
 {
     return "object_collection_" . $this->model->getKey() . "_" . $class->getId();
 }
Пример #11
0
    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
Пример #12
0
 /**
  *
  * @param string $filterJson
  * @param Object_Class $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = array("o_path", "o_key", "o_id", "o_published", "o_creationDate", "o_modificationDate");
     // create filter condition
     $conditionPartsFilters = array();
     if ($filterJson) {
         $filters = Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } else {
                 if ($filter["type"] == "numeric") {
                     if ($filter["comparison"] == "lt") {
                         $operator = "<";
                     } else {
                         if ($filter["comparison"] == "gt") {
                             $operator = ">";
                         } else {
                             if ($filter["comparison"] == "eq") {
                                 $operator = "=";
                             }
                         }
                     }
                 } else {
                     if ($filter["type"] == "date") {
                         if ($filter["comparison"] == "lt") {
                             $operator = "<";
                         } else {
                             if ($filter["comparison"] == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filter["comparison"] == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                         $filter["value"] = strtotime($filter["value"]);
                     } else {
                         if ($filter["type"] == "list") {
                             $operator = "=";
                         } else {
                             if ($filter["type"] == "boolean") {
                                 $operator = "=";
                                 $filter["value"] = (int) $filter["value"];
                             }
                         }
                     }
                 }
             }
             $field = $class->getFieldDefinition($filter["field"]);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof Object_Class_Data_Localizedfields) {
                     $field = $localized->getFieldDefinition($filter["field"]);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filter["field"]);
                 if (count($keyParts) > 1) {
                     $brickType = $keyParts[0];
                     $brickKey = $keyParts[1];
                     $key = self::getFieldForBrickType($class, $brickType);
                     $field = $class->getFieldDefinition($key);
                     $brickClass = Object_Objectbrick_Definition::getByKey($brickType);
                     $brickField = $brickClass->getFieldDefinition($brickKey);
                 }
             }
             if ($field instanceof Object_Class_Data_Objectbricks) {
                 // custom field
                 $db = Pimcore_Resource::get();
                 if (is_array($filter["value"])) {
                     $fieldConditions = array();
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filter["value"], $operator);
                 }
             } else {
                 if ($field instanceof Object_Class_Data) {
                     // custom field
                     if (is_array($filter["value"])) {
                         $fieldConditions = array();
                         foreach ($filter["value"] as $filterValue) {
                             $fieldConditions[] = $field->getFilterCondition($filterValue, $operator);
                         }
                         $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                     } else {
                         $conditionPartsFilters[] = $field->getFilterCondition($filter["value"], $operator);
                     }
                 } else {
                     if (in_array("o_" . $filter["field"], $systemFields)) {
                         // system field
                         $conditionPartsFilters[] = "`o_" . $filter["field"] . "` " . $operator . " '" . $filter["value"] . "' ";
                     }
                 }
             }
         }
     }
     $conditionFilters = "";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = " AND (" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
 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;
     }
 }
Пример #14
0
 public function gridProxyAction()
 {
     if ($this->_getParam("language")) {
         $this->setLanguage($this->_getParam("language"));
     }
     if ($this->_getParam("data")) {
         if ($this->_getParam("xaction") == "update") {
             $data = Zend_Json::decode($this->_getParam("data"));
             // save
             $object = Object_Abstract::getById($data["id"]);
             $objectData = array();
             foreach ($data as $key => $value) {
                 $parts = explode("~", $key);
                 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);
                     }
                     $brick->{$valueSetter}($value);
                 } else {
                     $objectData[$key] = $value;
                 }
             }
             $object->setValues($objectData);
             try {
                 $object->save();
                 $this->_helper->json(array("data" => Object_Service::gridObjectData($object, $this->_getParam("fields")), "success" => true));
             } catch (Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         }
     } else {
         // get list of objects
         $folder = Object_Abstract::getById($this->_getParam("folderId"));
         $class = Object_Class::getById($this->_getParam("classId"));
         $className = $class->getName();
         $colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate");
         $start = 0;
         $limit = 20;
         $orderKey = "o_id";
         $order = "ASC";
         $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];
                 }
             }
         }
         if ($this->_getParam("limit")) {
             $limit = $this->_getParam("limit");
         }
         if ($this->_getParam("start")) {
             $start = $this->_getParam("start");
         }
         if ($this->_getParam("sort")) {
             if (array_key_exists($this->_getParam("sort"), $colMappings)) {
                 $orderKey = $colMappings[$this->_getParam("sort")];
             } else {
                 $orderKey = $this->_getParam("sort");
             }
         }
         if ($this->_getParam("dir")) {
             $order = $this->_getParam("dir");
         }
         $listClass = "Object_" . ucfirst($className) . "_List";
         // create filter condition
         if ($this->_getParam("filter")) {
             $conditionFilters = Object_Service::getFilterCondition($this->_getParam("filter"), $class);
         }
         if ($this->_getParam("condition")) {
             $conditionFilters = " AND (" . $this->_getParam("condition") . ")";
         }
         $list = new $listClass();
         if (!empty($bricks)) {
             foreach ($bricks as $b) {
                 $list->addObjectbrick($b);
             }
         }
         if ($this->_getParam("only_direct_children") == "true") {
             $pathCondition = "o_parentId = " . $folder->getId();
         } else {
             $pathCondition = "(o_path = '" . $folder->getFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%')";
         }
         $list->setCondition($pathCondition . $conditionFilters);
         $list->setLimit($limit);
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $list->setIgnoreLocale(true);
         $list->load();
         $objects = array();
         foreach ($list->getObjects() as $object) {
             $o = Object_Service::gridObjectData($object, $fields);
             $objects[] = $o;
         }
         $this->_helper->json(array("data" => $objects, "success" => true, "total" => $list->getTotalCount()));
     }
 }
Пример #15
0
 /**
  * @return Object_Class
  */
 public function getClass()
 {
     $class = Object_Class::getById($this->getClassId());
     return $class;
 }
Пример #16
0
 /**
  * @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();
 }
Пример #17
0
 /**
  * Update the class name in all object
  *
  * @return void
  */
 public function updateClassNameInObjects($newName)
 {
     $this->db->update("objects", array("o_className" => $newName), $this->db->quoteInto("o_classId = ?", $this->model->getId()));
     $this->db->update("object_query_" . $this->model->getId(), array("oo_className" => $newName));
 }
 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;
 }
Пример #19
0
<?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>
Пример #20
0
 /**
  * @return Object_Class
  */
 public function getO_class()
 {
     if (!$this->o_class) {
         $this->setO_class(Object_Class::getById($this->getO_classId()));
     }
     return $this->o_class;
 }
Пример #21
0
 /**
  * @return void
  */
 public function delete()
 {
     $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks";
     $fieldFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf";
     @unlink($fieldFile);
     $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data";
     $fieldClass = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
     @unlink($fieldClass);
     $processedClasses = array();
     if (!empty($this->classDefinitions)) {
         foreach ($this->classDefinitions as $cl) {
             unset($this->oldClassDefinitions[$cl['classname']]);
             if (!$processedClasses[$cl['classname']]) {
                 $class = Object_Class::getById($cl['classname']);
                 $this->getResource()->delete($class);
                 $processedClasses[$cl['classname']] = true;
                 foreach ($class->getFieldDefinitions() as $fieldDef) {
                     if ($fieldDef instanceof Object_Class_Data_Objectbricks) {
                         $allowedTypes = $fieldDef->getAllowedTypes();
                         $idx = array_search($this->getKey(), $allowedTypes);
                         if ($idx !== false) {
                             array_splice($allowedTypes, $idx, 1);
                         }
                         $fieldDef->setAllowedTypes($allowedTypes);
                     }
                 }
                 $class->save();
             }
         }
     }
     // update classes
     $classList = new Object_Class_List();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object_Class_Data_Objectbricks) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         //remove objectbrick from class
                         //$this->getResource()->delete($class);
                         break;
                     }
                 }
             }
         }
     }
 }
Пример #22
0
 /**
  * @return boolean $isInstalled
  */
 public static function isInstalled()
 {
     $entry = Object_Class::getByName('BlogEntry');
     $category = Object_Class::getByName('BlogCategory');
     if ($entry && $category) {
         return true;
     }
     return false;
 }
Пример #23
0
 /**
  * @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;
 }
    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);
    }
Пример #25
0
 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));
 }
Пример #26
0
 public function getClasses()
 {
     if ($this->getChildAmount()) {
         $classIds = $this->db->fetchCol("SELECT o_classId FROM objects WHERE o_path LIKE ? AND o_type = 'object' GROUP BY o_classId", $this->model->getFullPath() . "%");
         $classes = array();
         foreach ($classIds as $classId) {
             $classes[] = Object_Class::getById($classId);
         }
         return $classes;
     } else {
         return array();
     }
 }
Пример #27
0
 /**
  * @param $e
  * @return array
  */
 protected function exceptionHandler($e)
 {
     // create view if it doesn't exist already // HACK
     if (preg_match("/Base table or view not found/", $e->getMessage()) && $this->firstException) {
         $this->firstException = false;
         $localizedFields = new Object_Localizedfield();
         $localizedFields->setClass(Object_Class::getById($this->model->getClassId()));
         $localizedFields->createUpdateTable();
         return $this->load();
     }
     throw $e;
 }
Пример #28
0
 /**
  *
  * 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;
     }
 }