Returns the storage controller, which directly accesses the actual object.
public getStorageController ( string $objectKey ) : |
||
$objectKey | string | |
return |
/** * Get a condition object for item listings. * * @param string $objectKey * * @return Condition */ public function getListingCondition($objectKey) { $objectKey = Objects::normalizeObjectKey($objectKey); $obj = $this->objects->getStorageController($objectKey); $rules = self::getRules($objectKey, static::MODE_LISTING); if (count($rules) === 0) { return null; } if ($this->getCaching()) { $cacheKey = md5($objectKey); $cached = $this->cacher->getDistributedCache('core/acl/listing/' . $cacheKey); if (null !== $cached) { return $cached; } } $condition = ''; $primaryList = $this->objects->getPrimaryList($objectKey); $primaryKey = current($primaryList); $denyList = array(); $conditionObject = new Condition(null, $this->jarves); foreach ($rules as $rule) { if ($rule['constraint_type'] === ACL::CONSTRAINT_EXACT) { //todo $rule['constraint_code'] can be a (urlencoded) composite pk //todo constraint_code is always urlencoded; $condition = Condition::create(array($primaryKey, '=', Tools::urlDecode($rule['constraint_code'])), $this->jarves); } if ($rule['constraint_type'] === ACL::CONSTRAINT_CONDITION) { $condition = Condition::create($rule['constraint_code'], $this->jarves); } if ($rule['constraint_type'] === ACL::CONSTRAINT_ALL) { $condition = array('1', '=', '1'); } elseif ($rule['sub']) { $subCondition = $obj->getNestedSubCondition($condition); if ($subCondition) { $condition = array($condition, 'OR', $subCondition); } } if ($rule['access'] === 1) { if ($denyList) { $condition = array($condition, 'AND NOT', $denyList); $conditionObject->addOr($condition); // $conditionObject->add('AND NOT', $denyList); } else { $conditionObject->addOr($condition); } } if ($rule['access'] !== 1) { if ($denyList) { $denyList[] = 'AND NOT'; } $denyList[] = $condition; } } if (!$conditionObject->hasRules()) { $conditionObject->addAnd(array('1', '!=', '1')); } if ($this->getCaching()) { $cacheKey = md5($objectKey); $this->cacher->setDistributedCache('core/acl/listing/' . $cacheKey, $conditionObject); } return $conditionObject; }
/** * Patches a object entry. This means, only defined fields will be saved. Fields which are not defined will * not be overwritten. * * @param array $pk * * @param Request|array $requestOrData * @return bool * * @throws AccessDeniedException * @throws ObjectNotFoundException * @throws \Exception */ public function patch($pk, $requestOrData) { $storageController = $this->objects->getStorageController($this->getObject()); $pk = $storageController->normalizePrimaryKey($pk); $this->primaryKey = $pk; $values = $this->collectData($requestOrData); $args = ['pk' => $pk, 'values' => &$values, 'controller' => $this, 'mode' => 'update']; $eventPre = new GenericEvent($this->getObject(), $args); $this->eventDispatcher->dispatch('core/object/modify-pre', $eventPre); $this->eventDispatcher->dispatch('core/object/patch-pre', $eventPre); $item = $this->getItem($pk); if ($this->getPermissionCheck()) { if (!$item) { return null; } if (!$this->acl->check(ACLRequest::create($this->getObject(), $pk)->onlyUpdateMode())) { return null; } foreach ($values as $fieldName => $value) { $aclRequest = ACLRequest::create($this->getObject(), $pk)->setField([$fieldName => $value])->onlyUpdateMode(); if (!$this->acl->check($aclRequest)) { throw new AccessDeniedException(sprintf('Not allowed to change `%s`', $fieldName)); } } } if (($condition = $this->getCondition()) && $condition->hasRules()) { if (!$this->conditionOperator->satisfy($condition, $item, $this->getObject())) { return null; } } $incomingFields = $requestOrData instanceof Request ? array_keys($requestOrData->request->all()) : array_keys($requestOrData); if (!$incomingFields) { return false; } $changedData = $this->mapData($values, $incomingFields, $item); if ($this->getWithNewsFeed()) { $this->utils->newNewsFeed($this->objects, $this->getObject(), array_merge($values, $pk), 'updated'); } $result = $storageController->patch($pk, $changedData); $args['result'] = $result; $event = new GenericEvent($this->getObject(), $args); $this->eventDispatcher->dispatch('core/object/modify', $event); $this->eventDispatcher->dispatch('core/object/patch', $event); return $result; }