getById() публичный статический Метод

public static getById ( integer $id ) : static
$id integer
Результат static
Пример #1
0
 /**
  * @return OnlineShop_Framework_ProductInterfaces_ICheckoutable
  */
 public function getProduct()
 {
     if ($this->product) {
         return $this->product;
     }
     $this->product = \Pimcore\Model\Object\AbstractObject::getById($this->productId);
     return $this->product;
 }
Пример #2
0
 /**
  * @static
  * @param int $id
  * @return null|\Pimcore\Model\Object\AbstractObject
  */
 public static function getById($id)
 {
     $object = \Pimcore\Model\Object\AbstractObject::getById($id);
     if ($object instanceof OnlineShop_Framework_AbstractFilterDefinition) {
         return $object;
     }
     return null;
 }
Пример #3
0
 /**
  * returns all possible group by values for given column group, product list and field combination
  *
  * @param $columnGroup
  * @param OnlineShop_Framework_IProductList $productList
  * @param string $field
  * @return array
  */
 public static function getGroupByValuesForFilterGroup($columnGroup, OnlineShop_Framework_IProductList $productList, $field)
 {
     $columnType = self::getColumnTypeForColumnGroup($columnGroup);
     $data = array();
     if ($columnType == "relation") {
         $productList->prepareGroupByRelationValues($field);
         $values = $productList->getGroupByRelationValues($field);
         foreach ($values as $v) {
             $obj = \Pimcore\Model\Object\AbstractObject::getById($v);
             if ($obj) {
                 $name = $obj->getKey();
                 if (method_exists($obj, "getName")) {
                     $name = $obj->getName();
                 }
                 $data[$v] = array("key" => $v, "value" => $name . " (" . $obj->getId() . ")");
             }
         }
     } else {
         if ($columnType == "multiselect") {
             $values = $productList->getGroupByValues($field);
             sort($values);
             foreach ($values as $v) {
                 $helper = explode(OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER, $v);
                 foreach ($helper as $h) {
                     $data[$h] = array("key" => $h, "value" => $h);
                 }
             }
         } else {
             if ($columnType == "category") {
                 $values = $productList->getGroupByValues($field);
                 foreach ($values as $v) {
                     $helper = explode(",", $v);
                     foreach ($helper as $h) {
                         $obj = \Pimcore\Model\Object\AbstractObject::getById($h);
                         if ($obj) {
                             $name = $obj->getKey();
                             if (method_exists($obj, "getName")) {
                                 $name = $obj->getName();
                             }
                             $data[$h] = array("key" => $h, "value" => $name . " (" . $obj->getId() . ")");
                         }
                     }
                 }
             } else {
                 $values = $productList->getGroupByValues($field);
                 sort($values);
                 foreach ($values as $v) {
                     $data[] = array("key" => $v, "value" => $v);
                 }
             }
         }
     }
     return $data;
 }
Пример #4
0
 public function loadObjectDataAction()
 {
     $object = Object\AbstractObject::getById($this->getParam("id"));
     $result = [];
     if ($object) {
         $result['success'] = true;
         $fields = $this->getParam("fields");
         $result['fields'] = Object\Service::gridObjectData($object, $fields);
     } else {
         $result['success'] = false;
     }
     $this->_helper->json($result);
 }
Пример #5
0
 /**
  * @param $method
  * @param $args
  *
  * @return mixed
  * @throws \Exception
  */
 public function __call($method, $args)
 {
     $field = substr($method, 3);
     if (substr($method, 0, 3) == 'get' && array_key_exists($field, $this->resultRow)) {
         return $this->resultRow[$field];
     }
     $object = \Pimcore\Model\Object\AbstractObject::getById($this->getId());
     if ($object) {
         return call_user_func_array(array($object, $method), $args);
     } else {
         throw new \Exception("Object with {$this->getId()} not found.");
     }
 }
Пример #6
0
 /**
  * @param $id
  * @throws \Exception
  */
 public function getById($id)
 {
     $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id);
     if (!$data["id"]) {
         throw new \Exception("Note item with id " . $id . " not found");
     }
     $this->assignVariablesToModel($data);
     // get key-value data
     $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id);
     $preparedData = array();
     foreach ($keyValues as $keyValue) {
         $data = $keyValue["data"];
         $type = $keyValue["type"];
         $name = $keyValue["name"];
         if ($type == "document") {
             if ($data) {
                 $data = Document::getById($data);
             }
         } else {
             if ($type == "asset") {
                 if ($data) {
                     $data = Asset::getById($data);
                 }
             } else {
                 if ($type == "object") {
                     if ($data) {
                         $data = Object\AbstractObject::getById($data);
                     }
                 } else {
                     if ($type == "date") {
                         if ($data > 0) {
                             $data = new \Zend_Date($data);
                         }
                     } else {
                         if ($type == "bool") {
                             $data = (bool) $data;
                         }
                     }
                 }
             }
         }
         $preparedData[$name] = array("data" => $data, "type" => $type);
     }
     $this->model->setData($preparedData);
 }
Пример #7
0
 public function getFilterFrontend(OnlineShop_Framework_AbstractFilterDefinitionType $filterDefinition, OnlineShop_Framework_IProductList $productList, $currentFilter)
 {
     $field = $this->getField($filterDefinition);
     $values = $productList->getGroupByRelationValues($field, true);
     $objects = array();
     Logger::log("Load Objects...", Zend_Log::INFO);
     $availableRelations = array();
     if ($filterDefinition->getAvailableRelations()) {
         $availableRelations = $this->loadAllAvailableRelations($filterDefinition->getAvailableRelations());
     }
     foreach ($values as $v) {
         if (empty($availableRelations) || $availableRelations[$v['value']] === true) {
             $objects[$v['value']] = \Pimcore\Model\Object\AbstractObject::getById($v['value']);
         }
     }
     Logger::log("done.", Zend_Log::INFO);
     if ($filterDefinition->getScriptPath()) {
         $script = $filterDefinition->getScriptPath();
     } else {
         $script = $this->script;
     }
     return $this->view->partial($script, array("hideFilter" => $filterDefinition->getRequiredFilterField() && empty($currentFilter[$filterDefinition->getRequiredFilterField()]), "label" => $filterDefinition->getLabel(), "currentValue" => $currentFilter[$field], "values" => $values, "objects" => $objects, "fieldname" => $field, "metaData" => $filterDefinition->getMetaData()));
 }
Пример #8
0
 public static function getCustomGridFieldDefinitions($classId, $objectId)
 {
     $object = AbstractObject::getById($objectId);
     $class = ClassDefinition::getById($classId);
     $masterFieldDefinition = $class->getFieldDefinitions();
     if (!$object) {
         return null;
     }
     $user = AdminTool::getCurrentUser();
     if ($user->isAdmin()) {
         return null;
     }
     $permissionList = array();
     $parentPermissionSet = $object->getPermissions(null, $user, true);
     if ($parentPermissionSet) {
         $permissionList[] = $parentPermissionSet;
     }
     $childPermissions = $object->getChildPermissions(null, $user);
     $permissionList = array_merge($permissionList, $childPermissions);
     $layoutDefinitions = array();
     foreach ($permissionList as $permissionSet) {
         $allowedLayoutIds = self::getLayoutPermissions($classId, $permissionSet);
         if (is_array($allowedLayoutIds)) {
             foreach ($allowedLayoutIds as $allowedLayoutId) {
                 if ($allowedLayoutId) {
                     if (!$layoutDefinitions[$allowedLayoutId]) {
                         $customLayout = ClassDefinition\CustomLayout::getById($allowedLayoutId);
                         if (!$customLayout) {
                             continue;
                         }
                         $layoutDefinitions[$allowedLayoutId] = $customLayout;
                     }
                 }
             }
         }
     }
     $mergedFieldDefinition = unserialize(serialize($masterFieldDefinition));
     if (count($layoutDefinitions)) {
         foreach ($mergedFieldDefinition as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     $mergedLocalizedFieldDefinitions[$locKey]->setInvisible(false);
                     $mergedLocalizedFieldDefinitions[$locKey]->setNotEditable(false);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 $mergedFieldDefinition[$key]->setInvisible(false);
                 $mergedFieldDefinition[$key]->setNotEditable(false);
             }
         }
     }
     foreach ($layoutDefinitions as $customLayoutDefinition) {
         $layoutName = $customLayoutDefinition->getName();
         $layoutDefinitions = $customLayoutDefinition->getLayoutDefinitions();
         $dummyClass = new ClassDefinition();
         $dummyClass->setLayoutDefinitions($layoutDefinitions);
         $customFieldDefinitions = $dummyClass->getFieldDefinitions();
         foreach ($mergedFieldDefinition as $key => $value) {
             if (!$customFieldDefinitions[$key]) {
                 unset($mergedFieldDefinition[$key]);
             }
         }
         foreach ($customFieldDefinitions as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 if (!$mergedFieldDefinition[$key]) {
                     continue;
                 }
                 $customLocalizedFieldDefinitions = $def->getFieldDefinitions();
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     self::mergeFieldDefinition($mergedLocalizedFieldDefinitions, $customLocalizedFieldDefinitions, $locKey);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 self::mergeFieldDefinition($mergedFieldDefinition, $customFieldDefinitions, $key);
             }
         }
     }
     return $mergedFieldDefinition;
 }
Пример #9
0
 /**
  *
  */
 public function __wakeup()
 {
     if (isset($this->_fulldump) && !self::$doNotRestoreKeyAndPath) {
         // set current key and path this is necessary because the serialized data can have a different path than the original element ( element was renamed or moved )
         $originalElement = AbstractObject::getById($this->getId());
         if ($originalElement) {
             $this->setKey($originalElement->getKey());
             $this->setPath($originalElement->getPath());
         }
     }
     if (isset($this->_fulldump) && $this->o_properties !== null) {
         $this->renewInheritedProperties();
     }
     if (isset($this->_fulldump)) {
         unset($this->_fulldump);
     }
 }
Пример #10
0
 public function getBatchAssignmentJobsAction()
 {
     $elementId = intval($this->getParam("elementId"));
     $elementType = strip_tags($this->getParam("elementType"));
     $idList = [];
     switch ($elementType) {
         case "object":
             $object = \Pimcore\Model\Object\AbstractObject::getById($elementId);
             if ($object) {
                 $idList = $this->getSubObjectIds($object);
             }
             break;
         case "asset":
             $asset = \Pimcore\Model\Asset::getById($elementId);
             if ($asset) {
                 $idList = $this->getSubAssetIds($asset);
             }
             break;
         case "document":
             $document = \Pimcore\Model\Document::getById($elementId);
             if ($document) {
                 $idList = $this->getSubDocumentIds($document);
             }
             break;
     }
     $size = 2;
     $offset = 0;
     $idListParts = [];
     while ($offset < count($idList)) {
         $idListParts[] = array_slice($idList, $offset, $size);
         $offset += $size;
     }
     $this->_helper->json(['success' => true, 'idLists' => $idListParts, 'totalCount' => count($idList)]);
 }
Пример #11
0
 /**
  * @param Document\Webservice\Data\Document\Element $wsElement
  * @param null $idMapper
  * @throws \Exception
  */
 public function getFromWebserviceImport($wsElement, $idMapper = null)
 {
     $data = $wsElement->value;
     if ($data->id !== null) {
         $this->type = $data->type;
         $this->subtype = $data->subtype;
         $this->id = $data->id;
         if (!is_numeric($this->id)) {
             throw new \Exception("cannot get values from web service import - id is not valid");
         }
         if ($idMapper) {
             $this->id = $idMapper->getMappedId($this->type, $data->id);
         }
         if ($this->type == "asset") {
             $this->element = Asset::getById($this->id);
             if (!$this->element instanceof Asset) {
                 if ($idMapper && $idMapper->ignoreMappingFailures()) {
                     $idMapper->recordMappingFailure("document", $this->getDocumentId(), $data->type, $data->id);
                 } else {
                     throw new \Exception("cannot get values from web service import - referenced asset with id [ " . $data->id . " ] is unknown");
                 }
             }
         } else {
             if ($this->type == "document") {
                 $this->element = Document::getById($this->id);
                 if (!$this->element instanceof Document) {
                     if ($idMapper && $idMapper->ignoreMappingFailures()) {
                         $idMapper->recordMappingFailure("document", $this->getDocumentId(), $data->type, $data->id);
                     } else {
                         throw new \Exception("cannot get values from web service import - referenced document with id [ " . $data->id . " ] is unknown");
                     }
                 }
             } else {
                 if ($this->type == "object") {
                     $this->element = Object\AbstractObject::getById($this->id);
                     if (!$this->element instanceof Object\AbstractObject) {
                         if ($idMapper && $idMapper->ignoreMappingFailures()) {
                             $idMapper->recordMappingFailure("document", $this->getDocumentId(), $data->type, $data->id);
                         } else {
                             throw new \Exception("cannot get values from web service import - referenced object with id [ " . $data->id . " ] is unknown");
                         }
                     }
                 } else {
                     if ($idMapper && $idMapper->ignoreMappingFailures()) {
                         $idMapper->recordMappingFailure("document", $this->getDocumentId(), $data->type, $data->id);
                     } else {
                         throw new \Exception("cannot get values from web service import - type is not valid");
                     }
                 }
             }
         }
     }
 }
Пример #12
0
 /**
  * @static
  * @param int $id
  * @return null|\Pimcore\Model\Object\AbstractObject
  */
 public static function getById($id)
 {
     $object = \Pimcore\Model\Object\AbstractObject::getById($id);
     if ($object instanceof OnlineShop_OfferTool_AbstractOfferToolProduct) {
         return $object;
     }
     return null;
 }
Пример #13
0
 public function treeGetChildsByIdAction()
 {
     $object = Object\AbstractObject::getById($this->getParam("node"));
     $objectTypes = null;
     $objects = [];
     $cv = false;
     $offset = 0;
     $total = 0;
     if ($object instanceof Object\Concrete) {
         $class = $object->getClass();
         if ($class->getShowVariants()) {
             $objectTypes = [Object\AbstractObject::OBJECT_TYPE_FOLDER, Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT];
         }
     }
     if (!$objectTypes) {
         $objectTypes = [Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER];
     }
     if ($object->hasChilds($objectTypes)) {
         $limit = intval($this->getParam("limit"));
         if (!$this->getParam("limit")) {
             $limit = 100000000;
         }
         $offset = intval($this->getParam("start"));
         $childsList = new Object\Listing();
         $condition = "objects.o_parentId = '" . $object->getId() . "'";
         // custom views start
         if ($this->getParam("view")) {
             $cv = \Pimcore\Model\Element\Service::getCustomViewById($this->getParam("view"));
             if ($cv["classes"]) {
                 $cvConditions = [];
                 $cvClasses = explode(",", $cv["classes"]);
                 foreach ($cvClasses as $cvClass) {
                     $cvConditions[] = "objects.o_classId = '" . $cvClass . "'";
                 }
                 $cvConditions[] = "objects.o_type = 'folder'";
                 if (count($cvConditions) > 0) {
                     $condition .= " AND (" . implode(" OR ", $cvConditions) . ")";
                 }
             }
         }
         // custom views end
         if (!$this->getUser()->isAdmin()) {
             $userIds = $this->getUser()->getRoles();
             $userIds[] = $this->getUser()->getId();
             $condition .= " AND (\n                                                    (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(o_path,o_key),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                                                    OR\n                                                    (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(o_path,o_key))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                                                 )";
         }
         $childsList->setCondition($condition);
         $childsList->setLimit($limit);
         $childsList->setOffset($offset);
         $childsList->setOrderKey("FIELD(objects.o_type, 'folder') DESC, objects.o_key ASC", false);
         $childsList->setObjectTypes($objectTypes);
         Element\Service::addTreeFilterJoins($cv, $childsList);
         $childs = $childsList->load();
         foreach ($childs as $child) {
             $tmpObject = $this->getTreeNodeConfig($child);
             if ($child->isAllowed("list")) {
                 $objects[] = $tmpObject;
             }
         }
         //pagination for custom view
         $total = $cv ? $childsList->count() : $object->getChildAmount([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER, Object\AbstractObject::OBJECT_TYPE_VARIANT], $this->getUser());
     }
     //Hook for modifying return value - e.g. for changing permissions based on object data
     //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values
     $returnValueContainer = new Model\Tool\Admin\EventDataContainer($objects);
     \Pimcore::getEventManager()->trigger("admin.object.treeGetChildsById.preSendData", $this, ["returnValueContainer" => $returnValueContainer]);
     if ($this->getParam("limit")) {
         $this->_helper->json(["offset" => $offset, "limit" => $limit, "total" => $total, "nodes" => $returnValueContainer->getData(), "fromPaging" => intval($this->getParam("fromPaging"))]);
     } else {
         $this->_helper->json($returnValueContainer->getData());
     }
 }
Пример #14
0
 /**
  * prepare data for index creation and store is in store table
  *
  * @param OnlineShop_Framework_ProductInterfaces_IIndexable $object
  */
 public function prepareDataForIndex(OnlineShop_Framework_ProductInterfaces_IIndexable $object)
 {
     $subObjectIds = $this->tenantConfig->createSubIdsForObject($object);
     foreach ($subObjectIds as $subObjectId => $object) {
         /**
          * @var OnlineShop_Framework_ProductInterfaces_IIndexable $object
          */
         if ($object->getOSDoIndexProduct() && $this->tenantConfig->inIndex($object)) {
             $a = Pimcore::inAdmin();
             $b = \Pimcore\Model\Object\AbstractObject::doGetInheritedValues();
             Pimcore::unsetAdminMode();
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues(true);
             $hidePublishedMemory = \Pimcore\Model\Object\AbstractObject::doHideUnpublished();
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished(false);
             $categories = $object->getCategories();
             $categoryIds = array();
             $parentCategoryIds = array();
             if ($categories) {
                 foreach ($categories as $c) {
                     $parent = $c;
                     if ($parent != null) {
                         if ($parent->getOSProductsInParentCategoryVisible()) {
                             while ($parent && $parent instanceof OnlineShop_Framework_AbstractCategory) {
                                 $parentCategoryIds[$parent->getId()] = $parent->getId();
                                 $parent = $parent->getParent();
                             }
                         } else {
                             $parentCategoryIds[$parent->getId()] = $parent->getId();
                         }
                         $categoryIds[$c->getId()] = $c->getId();
                     }
                 }
             }
             ksort($categoryIds);
             $virtualProductId = $subObjectId;
             $virtualProductActive = $object->isActive();
             if ($object->getOSIndexType() == "variant") {
                 $virtualProductId = $this->tenantConfig->createVirtualParentIdForSubId($object, $subObjectId);
             }
             $virtualProduct = \Pimcore\Model\Object\AbstractObject::getById($virtualProductId);
             if ($virtualProduct && method_exists($virtualProduct, "isActive")) {
                 $virtualProductActive = $virtualProduct->isActive();
             }
             $data = array("o_id" => $subObjectId, "o_classId" => $object->getClassId(), "o_virtualProductId" => $virtualProductId, "o_virtualProductActive" => $virtualProductActive, "o_parentId" => $object->getOSParentId(), "o_type" => $object->getOSIndexType(), "categoryIds" => ',' . implode(",", $categoryIds) . ",", "parentCategoryIds" => ',' . implode(",", $parentCategoryIds) . ",", "priceSystemName" => $object->getPriceSystemName(), "active" => $object->isActive(), "inProductList" => $object->isActive(true));
             $relationData = array();
             $columnConfig = $this->columnConfig->column;
             if (!empty($columnConfig->name)) {
                 $columnConfig = array($columnConfig);
             } else {
                 if (empty($columnConfig)) {
                     $columnConfig = array();
                 }
             }
             foreach ($columnConfig as $column) {
                 try {
                     //$data[$column->name] = null;
                     $value = null;
                     if (!empty($column->getter)) {
                         $getter = $column->getter;
                         $value = $getter::get($object, $column->config, $subObjectId, $this->tenantConfig);
                     } else {
                         if (!empty($column->fieldname)) {
                             $getter = "get" . ucfirst($column->fieldname);
                         } else {
                             $getter = "get" . ucfirst($column->name);
                         }
                         if (method_exists($object, $getter)) {
                             $value = $object->{$getter}($column->locale);
                         }
                     }
                     if (!empty($column->interpreter)) {
                         $interpreter = $column->interpreter;
                         $value = $interpreter::interpret($value, $column->config);
                         $interpreterObject = new $interpreter();
                         if ($interpreterObject instanceof OnlineShop_Framework_IndexService_RelationInterpreter) {
                             foreach ($value as $v) {
                                 $relData = array();
                                 $relData['src'] = $subObjectId;
                                 $relData['src_virtualProductId'] = $virtualProductId;
                                 $relData['dest'] = $v['dest'];
                                 $relData['fieldname'] = $column->name;
                                 $relData['type'] = $v['type'];
                                 $relationData[] = $relData;
                             }
                         } else {
                             $data[$column->name] = $value;
                         }
                     } else {
                         $data[$column->name] = $value;
                     }
                     if (is_array($data[$column->name])) {
                         $data[$column->name] = OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER . implode($data[$column->name], OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER) . OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER;
                     }
                 } catch (Exception $e) {
                     Logger::err("Exception in IndexService: " . $e->getMessage(), $e);
                 }
             }
             if ($a) {
                 Pimcore::setAdminMode();
             }
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues($b);
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished($hidePublishedMemory);
             $subTenantData = $this->tenantConfig->prepareSubTenantEntries($object, $subObjectId);
             $jsonData = json_encode(array("data" => $data, "relations" => $relationData ? $relationData : [], "subtenants" => $subTenantData ? $subTenantData : []));
             $crc = crc32($jsonData);
             $insertData = array("id" => $subObjectId, "tenant" => $this->name, "data" => $jsonData, "crc_current" => $crc, "preparation_worker_timestamp" => 0, "preparation_worker_id" => $this->db->quote(null), "in_preparation_queue" => 0);
             $currentEntry = $this->db->fetchRow("SELECT crc_current, in_preparation_queue FROM " . $this->getStoreTableName() . " WHERE id = ? AND tenant = ?", array($subObjectId, $this->name));
             if (!$currentEntry) {
                 $this->db->insert($this->getStoreTableName(), $insertData);
             } else {
                 if ($currentEntry['crc_current'] != $crc) {
                     $this->db->update($this->getStoreTableName(), $insertData, "id = " . $this->db->quote((string) $subObjectId) . " AND tenant = " . $this->db->quote($this->name));
                 } else {
                     if ($currentEntry['in_preparation_queue']) {
                         $this->db->query("UPDATE " . $this->getStoreTableName() . " SET in_preparation_queue = 0, preparation_worker_timestamp = 0, preparation_worker_id = null WHERE id = ? AND tenant = ?", array($subObjectId, $this->name));
                     }
                 }
             }
         } else {
             Logger::info("Don't adding product " . $subObjectId . " to index " . $this->name . ".");
             $this->doDeleteFromIndex($subObjectId);
         }
     }
     //cleans up all old zombie data
     $this->doCleanupOldZombieData($object, $subObjectIds);
 }
Пример #15
0
 /**
  * Removes token reservations due to given duration.
  *
  * @throws OnlineShop_Framework_Exception_InvalidConfigException
  */
 public function cleanupReservationsAction()
 {
     $duration = $this->getParam('duration');
     $id = $this->getParam('id');
     if (isset($duration)) {
         $onlineShopVoucherSeries = \Pimcore\Model\Object\AbstractObject::getById($this->getParam('id'));
         if ($onlineShopVoucherSeries instanceof \Pimcore\Model\Object\OnlineShopVoucherSeries) {
             if ($tokenManager = $onlineShopVoucherSeries->getTokenManager()) {
                 if ($tokenManager->cleanUpReservations($duration)) {
                     $this->forward('voucher-Code-Tab', 'Voucher', null, ['success' => $this->view->ts('plugin_onlineshop_voucherservice_msg-success-cleanup-reservations'), 'id' => $id]);
                 }
             }
         } else {
             $this->forward('voucher-Code-Tab', 'Voucher', null, ['error' => $this->view->ts('plugin_onlineshop_voucherservice_msg-error-cleanup-reservations'), 'id' => $id]);
         }
     } else {
         $this->forward('voucher-Code-Tab', 'Voucher', null, ['error' => $this->view->ts('plugin_onlineshop_voucherservice_msg-error-cleanup-reservations-duration-missing'), 'id' => $id]);
     }
 }
Пример #16
0
 public function updateIndex(OnlineShop_Framework_ProductInterfaces_IIndexable $object)
 {
     if (!$this->tenantConfig->isActive($object)) {
         Logger::info("Tenant {$this->name} is not active.");
         return;
     }
     $subObjectIds = $this->tenantConfig->createSubIdsForObject($object);
     foreach ($subObjectIds as $subObjectId => $object) {
         if ($object->getOSDoIndexProduct() && $this->tenantConfig->inIndex($object)) {
             $a = Pimcore::inAdmin();
             $b = \Pimcore\Model\Object\AbstractObject::doGetInheritedValues();
             Pimcore::unsetAdminMode();
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues(true);
             $hidePublishedMemory = \Pimcore\Model\Object\AbstractObject::doHideUnpublished();
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished(false);
             $categories = $object->getCategories();
             $themes = $object->getTheme();
             $categoryIds = array();
             $parentCategoryIds = array();
             if ($categories) {
                 foreach ($categories as $c) {
                     $parent = $c;
                     if ($parent != null) {
                         if ($parent->getOSProductsInParentCategoryVisible()) {
                             while ($parent && $parent instanceof OnlineShop_Framework_AbstractCategory) {
                                 $parentCategoryIds[$parent->getId()] = $parent->getId();
                                 $parent = $parent->getParent();
                             }
                         } else {
                             $parentCategoryIds[$parent->getId()] = $parent->getId();
                         }
                         $categoryIds[$c->getId()] = $c->getId();
                     }
                 }
             }
             $themeIds = array();
             if ($themes) {
                 foreach ($themes as $theme) {
                     $parent = $theme;
                     if ($parent != null) {
                         $themeIds[$theme->getId()] = $theme->getId();
                     }
                 }
             }
             ksort($categoryIds);
             $virtualProductId = $subObjectId;
             $virtualProductActive = $object->isActive();
             if ($object->getOSIndexType() == "variant") {
                 $virtualProductId = $this->tenantConfig->createVirtualParentIdForSubId($object, $subObjectId);
             }
             $virtualProduct = \Pimcore\Model\Object\AbstractObject::getById($virtualProductId);
             if ($virtualProduct && method_exists($virtualProduct, "isActive")) {
                 $virtualProductActive = $virtualProduct->isActive();
             }
             $data = array("o_id" => $subObjectId, "o_classId" => $object->getClassId(), "o_virtualProductId" => $virtualProductId, "o_virtualProductActive" => $virtualProductActive, "o_parentId" => $object->getOSParentId(), "o_type" => $object->getOSIndexType(), "categoryIds" => ',' . implode(",", $categoryIds) . ",", "parentCategoryIds" => ',' . implode(",", $parentCategoryIds) . ",", "priceSystemName" => $object->getPriceSystemName(), "active" => $object->isActive(), "inProductList" => $object->isActive(true), "theme" => ',' . implode(",", $themeIds) . ",");
             $relationData = array();
             $columnConfig = $this->columnConfig->column;
             if (!empty($columnConfig->name)) {
                 $columnConfig = array($columnConfig);
             } else {
                 if (empty($columnConfig)) {
                     $columnConfig = array();
                 }
             }
             foreach ($columnConfig as $column) {
                 try {
                     $value = null;
                     if (!empty($column->getter)) {
                         $getter = $column->getter;
                         $value = $getter::get($object, $column->config, $subObjectId, $this->tenantConfig);
                     } else {
                         if (!empty($column->fieldname)) {
                             $getter = "get" . ucfirst($column->fieldname);
                         } else {
                             $getter = "get" . ucfirst($column->name);
                         }
                         if (method_exists($object, $getter)) {
                             $value = $object->{$getter}($column->locale);
                         }
                     }
                     if (!empty($column->interpreter)) {
                         $interpreter = $column->interpreter;
                         $value = $interpreter::interpret($value, $column->config);
                         $interpreterObject = new $interpreter();
                         if ($interpreterObject instanceof OnlineShop_Framework_IndexService_RelationInterpreter) {
                             foreach ($value as $v) {
                                 $relData = array();
                                 $relData['src'] = $subObjectId;
                                 $relData['src_virtualProductId'] = $virtualProductId;
                                 $relData['dest'] = $v['dest'];
                                 $relData['fieldname'] = $column->name;
                                 $relData['type'] = $v['type'];
                                 $relationData[] = $relData;
                             }
                         } else {
                             $data[$column->name] = $value;
                         }
                     } else {
                         $data[$column->name] = $value;
                     }
                     if (is_array($data[$column->name])) {
                         $data[$column->name] = OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER . implode($data[$column->name], OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER) . OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER;
                     }
                 } catch (Exception $e) {
                     Logger::err("Exception in IndexService: " . $e->getMessage(), $e);
                 }
             }
             if ($a) {
                 Pimcore::setAdminMode();
             }
             \Pimcore\Model\Object\AbstractObject::setGetInheritedValues($b);
             \Pimcore\Model\Object\AbstractObject::setHideUnpublished($hidePublishedMemory);
             try {
                 $this->doInsertData($data);
             } catch (Exception $e) {
                 Logger::warn("Error during updating index table: " . $e);
             }
             try {
                 $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId));
                 foreach ($relationData as $rd) {
                     $this->db->insert($this->tenantConfig->getRelationTablename(), $rd);
                 }
             } catch (Exception $e) {
                 Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e);
             }
         } else {
             Logger::info("Don't adding product " . $subObjectId . " to index.");
             try {
                 $this->db->delete($this->tenantConfig->getTablename(), "o_id = " . $this->db->quote($subObjectId));
             } catch (Exception $e) {
                 Logger::warn("Error during updating index table: " . $e->getMessage(), $e);
             }
             try {
                 $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId));
             } catch (Exception $e) {
                 Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e);
             }
             try {
                 if ($this->tenantConfig->getTenantRelationTablename()) {
                     $this->db->delete($this->tenantConfig->getTenantRelationTablename(), "o_id = " . $this->db->quote($subObjectId));
                 }
             } catch (Exception $e) {
                 Logger::warn("Error during updating index tenant relation table: " . $e->getMessage(), $e);
             }
         }
         $this->tenantConfig->updateSubTenantEntries($object, $subObjectId);
     }
     //cleans up all old zombie data
     $this->doCleanupOldZombieData($object, $subObjectIds);
 }
Пример #17
0
 public function getOriginalObject()
 {
     Logger::notice("Getting original object {$this->id}.");
     return \Pimcore\Model\Object\AbstractObject::getById($this->id);
 }
Пример #18
0
 /**
  * @param $wsDocument
  * @throws \Exception
  */
 protected function updateObject($wsDocument)
 {
     $object = Object\AbstractObject::getById($wsDocument->id);
     if ($object === NULL) {
         throw new \Exception("Object with given ID (" . $wsDocument->id . ") does not exist.");
     }
     $this->setModificationParams($object, false);
     if ($object instanceof Object\Concrete and $object->getClassName() == $wsDocument->className) {
         $wsDocument->reverseMap($object);
         $object->save();
         return true;
     } else {
         if ($object instanceof Object\Folder and $object->getType() == strtolower($wsDocument->type)) {
             $wsDocument->reverseMap($object);
             $object->save();
             return true;
         } else {
             throw new \Exception("Type/Class mismatch for given object with ID [" . $wsDocument->id . "] and existing object with id [" . $object->getId() . "]");
         }
     }
 }
Пример #19
0
 /**
  * Gets object by id, can consider subIds and therefore return e.g. an array of values
  * always returns object itself - see also getObjectMockupById
  *
  * @param $objectId
  * @param $onlyMainObject - only returns main object
  * @return mixed
  */
 public function getObjectById($objectId, $onlyMainObject = false)
 {
     return \Pimcore\Model\Object\AbstractObject::getById($objectId);
 }