public static getElementType ( Pimcore\Model\Element\ElementInterface $element ) : string | ||
$element | Pimcore\Model\Element\ElementInterface | $element |
리턴 | string |
public function extractRelations($element, $apiElementKeys, $recursive, $includeRelations) { $foundRelations = array(); if ($includeRelations) { $dependency = $element->getDependencies(); if ($dependency) { foreach ($dependency->getRequires() as $r) { if ($e = Element\Service::getDependedElement($r)) { if ($element->getId() != $e->getId() and !in_array(Element\Service::getElementType($e) . "_" . $e->getId(), $apiElementKeys)) { $foundRelations[Element\Service::getElementType($e) . "_" . $e->getId()] = array("elementType" => Element\Service::getType($e), "element" => $e->getId(), "recursive" => false); } } } } } $childs = $element->getChilds(); if ($recursive and $childs) { foreach ($childs as $child) { if (!in_array(Element\Service::getType($child) . "_" . $child->getId(), $apiElementKeys)) { $foundRelations[Element\Service::getType($child) . "_" . $child->getId()] = array("elementType" => Element\Service::getType($child), "element" => $child->getId(), "recursive" => $recursive); } } } return $foundRelations; }
/** * gets workflow config for element. always returns first valid workflow config * * @param Asset|Document|ConcreteObject $element * @return array */ public static function getElementWorkflowConfig(AbstractElement $element) { $config = self::getWorkflowManagementConfig(); if (!is_array($config)) { return null; } $elementType = Service::getElementType($element); $elementSubType = $element->getType(); foreach ($config['workflows'] as $workflow) { //workflow is not enabled, continue with next if (isset($workflow['enabled']) && !$workflow['enabled']) { continue; } if (isset($workflow['workflowSubject']) && in_array($elementType, $workflow['workflowSubject']['types'])) { switch ($elementType) { case 'asset': if (isset($workflow['workflowSubject']['assetTypes']) && is_array($workflow['workflowSubject']['assetTypes'])) { if (in_array($elementSubType, $workflow['workflowSubject']['assetTypes'])) { return $workflow; } } else { \Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available asset types'); } break; case 'document': if (isset($workflow['workflowSubject']['documentTypes']) && is_array($workflow['workflowSubject']['documentTypes'])) { if (in_array($elementSubType, $workflow['workflowSubject']['documentTypes'])) { return $workflow; } } else { \Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available document types'); } break; case 'object': if ($element instanceof ConcreteObject) { if (isset($workflow['workflowSubject']['classes']) && is_array($workflow['workflowSubject']['classes'])) { $classId = $element->getClassId(); if (in_array($classId, $workflow['workflowSubject']['classes'])) { return $workflow; } } else { \Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available class ID\'s'); } } break; default: //unknown element type, return null return null; } } } return null; }
public static function interpret($value, $config = null) { $result = array(); if (is_array($value)) { foreach ($value as $v) { $result[] = array("dest" => $v->getId(), "type" => \Pimcore\Model\Element\Service::getElementType($v)); } } else { if ($value instanceof \Pimcore\Model\Element\AbstractElement) { $result[] = array("dest" => $value->getId(), "type" => \Pimcore\Model\Element\Service::getElementType($value)); } } return $result; }
/** * Clear all relations in the database * @param Element\ElementInterface $element */ public function cleanAllForElement($element) { try { $id = $element->getId(); $type = Element\Service::getElementType($element); //schedule for sanity check $data = $this->db->fetchAll("SELECT * FROM dependencies WHERE targetid = ? AND targettype = ?", array($id, $type)); if (is_array($data)) { foreach ($data as $row) { $sanityCheck = new Element\Sanitycheck(); $sanityCheck->setId($row['sourceid']); $sanityCheck->setType($row['sourcetype']); $sanityCheck->save(); } } $this->db->delete("dependencies", $this->db->quoteInto("sourceid = ?", $id) . " AND " . $this->db->quoteInto("sourcetype = ?", $type)); $this->db->delete("dependencies", $this->db->quoteInto("targetid = ?", $id) . " AND " . $this->db->quoteInto("targettype = ?", $type)); } catch (\Exception $e) { \Logger::error($e); } }
/** * @param $data * @return array */ public function resolveDependencies($data) { $dependencies = []; if (is_array($data) && count($data) > 0) { foreach ($data as $e) { if ($e instanceof Element\ElementInterface) { $elementType = Element\Service::getElementType($e); $dependencies[$elementType . "_" . $e->getId()] = ["id" => $e->getId(), "type" => $elementType]; } } } return $dependencies; }
/** * @param $element * @return string */ public function getStorageFileBinary($element) { return PIMCORE_RECYCLEBIN_DIRECTORY . "/" . $this->getId() . "_" . Element\Service::getElementType($element) . "-" . $element->getId() . ".bin"; }
/** * @return array */ public function resolveDependencies() { $dependencies = []; if ($this->getData() instanceof ElementInterface) { $elementType = Element\Service::getElementType($this->getData()); $key = $elementType . "_" . $this->getData()->getId(); $dependencies[$key] = ["id" => $this->getData()->getId(), "type" => $elementType]; } return $dependencies; }
/** * @param $object * @param string $ownertype * @param $ownername * @param $position */ public function save($object, $ownertype = "object", $ownername, $position) { $element = $this->getElement(); $type = Model\Element\Service::getElementType($element); $this->getDao()->save($object, $ownertype, $ownername, $position, $type); }
/** * Rewrites id from source to target, $idMapping contains * array( * "document" => array( * SOURCE_ID => TARGET_ID, * SOURCE_ID => TARGET_ID * ), * "object" => array(...), * "asset" => array(...) * ) * @param mixed $object * @param array $idMapping * @param array $params * @return Element\ElementInterface */ public function rewriteIds($object, $idMapping, $params = array()) { $data = $this->getDataFromObjectParam($object, $params); if (is_array($data)) { foreach ($data as &$metaObject) { $eo = $metaObject->getObject(); if ($eo instanceof Element\ElementInterface) { $id = $eo->getId(); $type = Element\Service::getElementType($eo); if (array_key_exists($type, $idMapping) && array_key_exists($id, $idMapping[$type])) { $newElement = Element\Service::getElementById($type, $idMapping[$type][$id]); $metaObject->setObject($newElement); } } } } return $data; }
/** * @param $item * @return $this */ public function setItem($item) { $this->setItemId($item->getId()); $this->setType(Model\Element\Service::getElementType($item)); $this->item = $item; return $this; }
public function addAction() { $element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id")); if ($element) { $type = Element\Service::getElementType($element); $listClass = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing"; $list = new $listClass(); $list->setCondition(($type == "object" ? "o_" : "") . "path LIKE '" . $element->getFullPath() . "/%'"); $children = $list->getTotalCount(); if ($children <= 100) { Recyclebin\Item::create($element, $this->getUser()); } $this->_helper->json(array("success" => true)); } else { $this->_helper->json(array("success" => false)); } }
/** * @param mixed $data * @return static */ public function setData($data) { if ($data instanceof ElementInterface) { $this->setType(Service::getElementType($data)); $data = $data->getId(); } $this->data = $data; return $this; }
/** * @return array */ public function resolveDependencies() { $this->setElements(); $dependencies = []; if (is_array($this->elements) && count($this->elements) > 0) { foreach ($this->elements as $element) { if ($element instanceof Element\ElementInterface) { $elementType = Element\Service::getElementType($element); $key = $elementType . "_" . $element->getId(); $dependencies[$key] = ["id" => $element->getId(), "type" => $elementType]; } } } return $dependencies; }
/** * @return null|WorkflowState */ public function getWorkflowStateForElement() { $elementType = Service::getElementType($this->element); $workflowState = WorkflowState::getByPrimary($this->element->getId(), $elementType, $this->workflow->getId()); if (empty($workflowState)) { $workflowState = new WorkflowState(); $workflowState->setCid($this->element->getId()); $workflowState->setCtype($elementType); $workflowState->setWorkflowId($this->workflow->getId()); } return $workflowState; }
/** * */ public function maintenanceCleanUp() { $conf["document"] = Config::getSystemConfig()->documents->versions; $conf["asset"] = Config::getSystemConfig()->assets->versions; $conf["object"] = Config::getSystemConfig()->objects->versions; $elementTypes = array(); foreach ($conf as $elementType => $tConf) { if (intval($tConf->days) > 0) { $versioningType = "days"; $value = intval($tConf->days); } else { $versioningType = "steps"; $value = intval($tConf->steps); } if ($versioningType) { $elementTypes[] = array("elementType" => $elementType, $versioningType => $value); } } $ignoredIds = array(); while (true) { $versions = $this->getDao()->maintenanceGetOutdatedVersions($elementTypes, $ignoredIds); if (count($versions) == 0) { break; } $counter = 0; \Logger::debug("versions to check: " . count($versions)); if (is_array($versions) && !empty($versions)) { $totalCount = count($versions); foreach ($versions as $index => $id) { try { $version = Version::getById($id); } catch (\Exception $e) { $ignoredIds[] = $id; \Logger::debug("Version with " . $id . " not found\n"); continue; } $counter++; // do not delete public versions if ($version->getPublic()) { $ignoredIds[] = $version->getId(); continue; } if ($version->getCtype() == "document") { $element = Document::getById($version->getCid()); } elseif ($version->getCtype() == "asset") { $element = Asset::getById($version->getCid()); } elseif ($version->getCtype() == "object") { $element = Object::getById($version->getCid()); } if ($element instanceof ElementInterface) { \Logger::debug("currently checking Element-ID: " . $element->getId() . " Element-Type: " . Element\Service::getElementType($element) . " in cycle: " . $counter . "/" . $totalCount); if ($element->getModificationDate() >= $version->getDate()) { // delete version if it is outdated \Logger::debug("delete version: " . $version->getId() . " because it is outdated"); $version->delete(); } else { $ignoredIds[] = $version->getId(); \Logger::debug("do not delete version (" . $version->getId() . ") because version's date is newer than the actual modification date of the element. Element-ID: " . $element->getId() . " Element-Type: " . Element\Service::getElementType($element)); } } else { // delete version if the corresponding element doesn't exist anymore \Logger::debug("delete version (" . $version->getId() . ") because the corresponding element doesn't exist anymore"); $version->delete(); } // call the garbage collector if memory consumption is > 100MB if (memory_get_usage() > 100000000) { \Pimcore::collectGarbage(); } } } } }
/** * @return array */ public function resolveDependencies() { $this->load(); $dependencies = array(); if ($this->o instanceof Element\ElementInterface) { $elementType = Element\Service::getElementType($this->o); $key = $elementType . "_" . $this->o->getId(); $dependencies[$key] = array("id" => $this->o->getId(), "type" => $elementType); } return $dependencies; }
/** * Rewrites id from source to target, $idMapping contains * array( * "document" => array( * SOURCE_ID => TARGET_ID, * SOURCE_ID => TARGET_ID * ), * "object" => array(...), * "asset" => array(...) * ) * @param mixed $data * @param array $idMapping * @return array */ public function rewriteIdsService($data, $idMapping) { if (is_array($data)) { foreach ($data as &$element) { $id = $element->getId(); $type = Element\Service::getElementType($element); if (array_key_exists($type, $idMapping) && array_key_exists($id, $idMapping[$type])) { $element = Element\Service::getElementById($type, $idMapping[$type][$id]); } } } return $data; }
/** * @param $item * @return $this */ public function setItem($item) { $this->setItemId($item->getId()); if ($item instanceof Model\Element\ElementInterface) { $this->setType(Model\Element\Service::getElementType($item)); } elseif ($item instanceof Model\Object\ClassDefinition) { $this->setType("class"); } $this->item = $item; return $this; }
/** * Adds a Pimcore Object/Asset/Document to the cache * * @param $element */ public static function loadElementToCache($element) { $cacheKey = Element\Service::getElementType($element) . "_" . $element->getId(); Cache::storeToCache($element, $cacheKey, [], null, null, true); }
/** * @return array */ public function getUserPermissions() { $elementType = Service::getElementType($this); $vars = get_class_vars("\\Pimcore\\Model\\User\\Workspace\\" . ucfirst($elementType)); $ignored = array("userId", "cid", "cpath", "dao"); $permissions = array(); foreach ($vars as $name => $defaultValue) { if (!in_array($name, $ignored)) { $permissions[$name] = $this->isAllowed($name); } } return $permissions; }
/** * @param AbstractListing $list */ protected static function loadToCache(AbstractListing $list) { $totalCount = $list->getTotalCount(); $iterations = ceil($totalCount / self::getPerIteration()); \Logger::info("New list of elements queued for storing into the cache with " . $iterations . " iterations and " . $totalCount . " total items"); for ($i = 0; $i < $iterations; $i++) { \Logger::info("Starting iteration " . $i . " with offset: " . self::getPerIteration() * $i); $list->setLimit(self::getPerIteration()); $list->setOffset(self::getPerIteration() * $i); $elements = $list->load(); foreach ($elements as $element) { $cacheKey = Element\Service::getElementType($element) . "_" . $element->getId(); Cache::storeToCache($element, $cacheKey, [], null, null, true); } \Pimcore::collectGarbage(); sleep(self::getTimoutBetweenIteration()); } }
/** * @param $data * @return array */ public function resolveDependencies($data) { $dependencies = array(); if ($data instanceof Element\ElementInterface) { $elementType = Element\Service::getElementType($data); $dependencies[$elementType . "_" . $data->getId()] = array("id" => $data->getId(), "type" => $elementType); } return $dependencies; }
public function xliffImportElementAction() { include_once "simple_html_dom.php"; $id = $this->getParam("id"); $step = $this->getParam("step"); $importFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $id . ".xliff"; $xliff = simplexml_load_file($importFile, null, LIBXML_NOCDATA); $file = $xliff->file[(int) $step]; $target = $file["target-language"]; if (!Tool::isValidLanguage($target)) { $locale = new \Zend_Locale($target); $target = $locale->getLanguage(); if (!Tool::isValidLanguage($target)) { $this->_helper->json(array("success" => false)); } } list($type, $id) = explode("-", $file["original"]); $element = Element\Service::getElementById($type, $id); if (true || $element) { foreach ($file->body->{"trans-unit"} as $transUnit) { list($fieldType, $name) = explode("~-~", $transUnit["id"]); $content = $transUnit->target->asXml(); $content = $this->unescapeXliff($content); if ($element instanceof Document) { if ($fieldType == "tag" && method_exists($element, "getElement")) { $tag = $element->getElement($name); if ($tag) { $tag->setDataFromEditmode($content); $tag->setInherited(false); $element->setElement($tag->getName(), $tag); } } if ($fieldType == "settings" && $element instanceof Document\Page) { $setter = "set" . ucfirst($name); if (method_exists($element, $setter)) { $element->{$setter}($content); } } } else { if ($element instanceof Object\Concrete) { if ($fieldType == "localizedfield") { $setter = "set" . ucfirst($name); if (method_exists($element, $setter)) { $element->{$setter}($content, $target); } } } } if ($fieldType == "property") { $property = $element->getProperty($name, true); if ($property) { $property->setData($content); } else { $element->setProperty($name, "text", $content); } } } try { // allow to save objects although there are mandatory fields if ($element instanceof Object\AbstractObject) { $element->setOmitMandatoryCheck(true); } $element->save(); } catch (\Exception $e) { throw new \Exception("Unable to save " . Element\Service::getElementType($element) . " with id " . $element->getId() . " because of the following reason: " . $e->getMessage()); } } $this->_helper->json(array("success" => true)); }