public static doHideUnpublished ( ) : boolean | ||
Результат | boolean |
public function preGetData($object, $params = array()) { $data = null; if ($object instanceof Object\Concrete) { $data = $object->{$this->getName()}; if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) { //$data = $this->getDataFromResource($object->getRelationData($this->getName(),true,null)); $data = $this->load($object, array("force" => true)); $setter = "set" . ucfirst($this->getName()); if (method_exists($object, $setter)) { $object->{$setter}($data); } } } else { if ($object instanceof Object\Localizedfield) { $data = $params["data"]; } else { if ($object instanceof Object\Fieldcollection\Data\AbstractData) { $data = $object->{$this->getName()}; } else { if ($object instanceof Object\Objectbrick\Data\AbstractData) { $data = $object->{$this->getName()}; } } } } if (Object\AbstractObject::doHideUnpublished() and is_array($data)) { $publishedList = array(); foreach ($data as $listElement) { if (Element\Service::isPublished($listElement)) { $publishedList[] = $listElement; } } return $publishedList; } return is_array($data) ? $data : array(); }
/** * @param $object * @param array $params * @return null|Object\Fieldcollection\Data\Object\Concrete|Object\Objectbrick\Data\ */ public function preGetData($object, $params = array()) { $data = null; if ($object instanceof Object\Concrete) { $data = $object->{$this->getName()}; if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) { $data = $this->load($object, array("force" => true)); $setter = "set" . ucfirst($this->getName()); if (method_exists($object, $setter)) { $object->{$setter}($data); } } } else { if ($object instanceof Object\Localizedfield) { $data = $params["data"]; } else { if ($object instanceof Object\Fieldcollection\Data\AbstractData) { $data = $object->{$this->getName()}; } else { if ($object instanceof Object\Objectbrick\Data\AbstractData) { $data = $object->{$this->getName()}; } } } } if (Object\AbstractObject::doHideUnpublished() and $data instanceof Element\ElementInterface) { if (!Element\Service::isPublished($data)) { return null; } } return $data; }
/** * @param \Zend_DB_Select $select * * @return $this */ protected function addConditions(\Zend_DB_Select $select) { $condition = $this->model->getCondition(); $objectTypes = $this->model->getObjectTypes(); if (!empty($objectTypes)) { if (!empty($condition)) { $condition .= " AND "; } $condition .= " o_type IN ('" . implode("','", $objectTypes) . "')"; } if ($condition) { if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { $condition = "(" . $condition . ") AND o_published = 1"; } } else { if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { $condition = "o_published = 1"; } } if ($condition) { $select->where($condition); } return $this; }
/** * @return string */ protected function getCondition() { $condition = $this->model->getCondition(); $objectTypes = $this->model->getObjectTypes(); if (!empty($objectTypes)) { if (!empty($condition)) { $condition .= " AND "; } $condition .= " o_type IN ('" . implode("','", $objectTypes) . "')"; } if ($condition) { if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { return " WHERE (" . $condition . ") AND o_published = 1"; } return " WHERE " . $condition . " "; } else { if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { return " WHERE o_published = 1"; } } return ""; }
/** * 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); }
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); }
/** * @param \Zend_DB_Select $select * * @return $this */ protected function addConditions(\Zend_DB_Select $select) { $condition = $this->model->getCondition(); $objectTypes = $this->model->getObjectTypes(); $tableName = method_exists($this, "getTableName") ? $this->getTableName() : "objects"; if (!empty($objectTypes)) { if (!empty($condition)) { $condition .= " AND "; } $condition .= " " . $tableName . ".o_type IN ('" . implode("','", $objectTypes) . "')"; } if ($condition) { if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { $condition = "(" . $condition . ") AND " . $tableName . ".o_published = 1"; } } elseif (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) { $condition = $tableName . ".o_published = 1"; } if ($condition) { $select->where($condition); } return $this; }