/** * @param AbstractQueryDesigner $abstractQueryDesigner * @param object $entity * @param string $type * * @return string[] */ public function getQueryContactInformationFields(AbstractQueryDesigner $abstractQueryDesigner, $entity, $type) { $contactInformationFields = $this->contactInformationFieldHelper->getEntityContactInformationColumns(ClassUtils::getRealClass($entity)); if (empty($contactInformationFields)) { return []; } $definitionColumns = []; $definition = $abstractQueryDesigner->getDefinition(); if ($definition) { $definition = json_decode($definition, JSON_OBJECT_AS_ARRAY); if (!empty($definition['columns'])) { $definitionColumns = array_map(function (array $columnDefinition) { return $columnDefinition['name']; }, $definition['columns']); } } $typedFields = array_keys(array_filter($contactInformationFields, function ($contactInformationField) use($type) { return $contactInformationField === $type; })); if (!empty($definitionColumns)) { $typedFields = array_intersect($typedFields, $definitionColumns); } $propertyAccessor = PropertyAccess::createPropertyAccessor(); return array_map(function ($typedField) use($propertyAccessor, $entity) { return (string) $propertyAccessor->getValue($entity, $typedField); }, $typedFields); }
/** * {@inheritdoc} */ public function merge(FieldData $fieldData) { $entityData = $fieldData->getEntityData(); $masterEntity = $entityData->getMasterEntity(); $sourceEntity = $fieldData->getSourceEntity(); if ($masterEntity->getId() !== $sourceEntity->getId()) { $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId()); $notes = $queryBuilder->getQuery()->getResult(); if (!empty($notes)) { $entityManager = $this->doctrineHelper->getEntityManager(current($notes)); foreach ($notes as $note) { $entityManager->remove($note); } } $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId()); $notes = $queryBuilder->getQuery()->getResult(); if (!empty($notes)) { foreach ($notes as $note) { $note->setTarget($masterEntity); } } $fieldMetadata = $fieldData->getMetadata(); $activityClass = $fieldMetadata->get('type'); $entityClass = ClassUtils::getRealClass($sourceEntity); $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass); $activityListItems = $queryBuilder->getQuery()->getResult(); $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id'); $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId()); } }
public function testMerge() { $account1 = new User(); $account2 = new User(); $this->setId($account1, 1); $this->setId($account2, 2); $entityMetadata = new EntityMetadata(['type' => ClassUtils::getRealClass($account1)]); $entityData = new EntityData($entityMetadata, [$account1, $account2]); $entityData->setMasterEntity($account1); $fieldData = new FieldData($entityData, new FieldMetadata()); $fieldData->setMode(MergeModes::NOTES_REPLACE); $fieldData->setSourceEntity($account2); $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock(); $queryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf()); $queryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([new ExtendNote()])); $repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->setMethods(['getBaseAssociatedNotesQB', 'getActivityListQueryBuilderByActivityClass'])->getMock(); $repository->expects($this->any())->method('getBaseAssociatedNotesQB')->willReturn($queryBuilder); $activityQueryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock(); $activityQueryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf()); $activityQueryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([['id' => 1, 'relatedActivityId' => 11], ['id' => 3, 'relatedActivityId' => 2]])); $repository->expects($this->any())->method('getActivityListQueryBuilderByActivityClass')->willReturn($activityQueryBuilder); $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['remove'])->getMock(); $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($repository); $this->doctrineHelper->expects($this->any())->method('getEntityManager')->willReturn($entityManager); $this->activityListManager->expects($this->once())->method('replaceActivityTargetWithPlainQuery'); $this->strategy->merge($fieldData); }
public function onKernelController(FilterControllerEvent $event) { if (!$this->securityContext->getToken()) { return true; } $controller = $event->getController(); list($object, $method) = $controller; $className = ClassUtils::getRealClass($object); $reflectionClass = new \ReflectionClass($className); $reflectionMethod = $reflectionClass->getMethod($method); $classAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass); $methodsAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod); $allAnnotations = array_merge($classAnnotations, $methodsAnnotations); $ruleAnnotations = array_filter($allAnnotations, function ($annotation) { return $annotation instanceof Rule; }); foreach ($ruleAnnotations as $ruleAnnotation) { if (is_array($ruleAnnotation->rules)) { $rules = $ruleAnnotation->rules; } else { $rules = explode(',', $ruleAnnotation->rules); } foreach ($rules as $rule) { $rule = trim($rule); if (empty($rule)) { continue; } if ($this->securityContext->isGranted($rule)) { return true; } } } throw new AccessDeniedException('The current user has no permissions on this action.'); }
/** * Get class alias of specified entity * * @param object $object * @param bool $isPlural * * @return null|string */ public function getClassAlias($object, $isPlural = false) { if (!is_object($object)) { return null; } $className = ClassUtils::getRealClass($object); return $isPlural ? $this->entityAliasResolver->getPluralAlias($className) : $this->entityAliasResolver->getAlias($className); }
/** * Creates a user security identity from a TokenInterface * * @param TokenInterface $token * @return UserSecurityIdentity */ public static function fromToken(TokenInterface $token) { $user = $token->getUser(); if ($user instanceof UserInterface) { return self::fromAccount($user); } return new self((string) $user, is_object($user) ? ClassUtils::getRealClass($user) : ClassUtils::getRealClass($token)); }
/** * @param AbstractUser $user * @return string */ public function getAuditEntryFieldClass(AbstractUser $user) { $userClass = ClassUtils::getRealClass($user); if (!$this->entryFieldMap->containsKey($userClass)) { throw new \InvalidArgumentException(sprintf('Audit entry field not found for "%s"', $userClass)); } return $this->entryFieldMap->get($userClass); }
/** * Get FQCN of specified entity * * @param object $object * @param bool $escape Set TRUE to escape the class name for insertion into a route, * replacing \ with _ characters * * @return string */ public function getClassName($object, $escape = false) { if (!is_object($object)) { return null; } $className = ClassUtils::getRealClass($object); return $escape ? $this->entityRoutingHelper->getUrlSafeClassName($className) : $className; }
/** * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $object = $args->getEntity(); if ($object instanceof AclAwareInterface) { $rules = $this->aclRulesManager->getEntityRule(ClassUtils::getRealClass($object)); $this->aclManager->setAcl($object, $rules); } }
/** * @param array $entities * @return bool */ protected function checkEntities(array $entities) { foreach ($entities as $entity) { if (in_array(ClassUtils::getRealClass($entity), $this->securityClasses, true)) { return true; } } return false; }
/** * @param object $entity * @return string */ public function getOwnerType($entity) { $ownerClassName = ClassUtils::getRealClass($entity); if (!$this->configProvider->hasConfig($ownerClassName)) { return null; } $config = $this->configProvider->getConfig($ownerClassName); return $config->get('owner_type'); }
/** * @Route("/create/{entityClass}/{entityId}", name="oro_note_create") * * @Template("OroNoteBundle:Note:update.html.twig") * @AclAncestor("oro_note_create") */ public function createAction($entityClass, $entityId) { $entityRoutingHelper = $this->getEntityRoutingHelper(); $entity = $entityRoutingHelper->getEntity($entityClass, $entityId); $entityClass = ClassUtils::getRealClass($entity); $noteEntity = new Note(); $noteEntity->setTarget($entity); $formAction = $entityRoutingHelper->generateUrlByRequest('oro_note_create', $this->getRequest(), $entityRoutingHelper->getRouteParameters($entityClass, $entityId)); return $this->update($noteEntity, $formAction); }
/** * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $className = ClassUtils::getRealClass($entity); $classRules = $this->aclRulesManager->getEntityRule($className); if ($classRules !== false) { $this->aclRulesManager->clearCreateEntityPermissions($classRules); $this->aclManager->setAcl($entity, $classRules); } }
/** * Retrieves the available security identities for the given token. * * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token * * @return array An array of SecurityIdentityInterface implementations */ public function getSecurityIdentities(TokenInterface $token) { $sids = parent::getSecurityIdentities($token); if ($token->getUser() instanceof \BackBee\CoreDomain\Security\User) { foreach ($token->getUser()->getGroups() as $group) { $securityIdentity = new UserSecurityIdentity($group->getObjectIdentifier(), ClassUtils::getRealClass($group)); array_unshift($sids, $securityIdentity); } } return $sids; }
/** * @param DiamanteUser|null $user * * @return string */ public function getAuditEntryFieldClass(DiamanteUser $user = null) { if ($user === null) { return $this->entryFieldMap->first(); } $userClass = ClassUtils::getRealClass($user); if (!$this->entryFieldMap->containsKey($userClass)) { throw new \InvalidArgumentException(sprintf('Audit entry field not found for "%s"', $userClass)); } return $this->entryFieldMap->get($userClass); }
/** * Gets organization of the given entity * * @param mixed $object * @return mixed * @throws InvalidEntityException If entity is not an object * @throws \InvalidArgumentException If owner property path is not defined */ public function getOrganization($object) { if (!is_object($object)) { throw new InvalidEntityException('$object must be an object.'); } $metadata = $this->metadataProvider->getMetadata(ClassUtils::getRealClass($object)); if ($metadata->getGlobalOwnerFieldName()) { return $this->getValue($object, $metadata->getGlobalOwnerFieldName()); } return null; }
public function getAccessSetList($object) { $list = array(); foreach ($this->voterList as $voter) { if ($voter->supportsClass(ClassUtils::getRealClass($object))) { $attributes = $voter->getAccessSets(); $list = array_merge_recursive($list, $attributes); } } return $list; }
/** * {@inheritdoc} */ public function getValue(ResultRecordInterface $record) { $entity = $record->getValue('entity'); $entityClass = ClassUtils::getRealClass($entity); if ($this->mappingProvider->isClassSupported($entityClass)) { return parent::getValue($record); } else { $this->params[self::TEMPLATE_KEY] = $this->defaultTemplate; return $this->getTemplate()->render(['entityType' => $this->entityConfigProvider->getConfig($entityClass)->get('label'), 'entity' => $entity, 'indexer_item' => $record->getValue('indexer_item')]); } }
/** * Check if the entity is a Translatable entity * * @param $entity * * @return bool */ protected function isTranslatable($entity) { if (!is_object($entity)) { return false; } // Support Doctrine Proxies $realClass = ClassUtils::getRealClass($entity); $reflClass = new \ReflectionClass($realClass); $traitNames = $reflClass->getTraitNames(); return in_array('Unifik\\DoctrineBehaviorsBundle\\Model\\Translatable\\Translatable', $traitNames) && $reflClass->hasProperty('translations'); }
/** * @param string|object $entityOrClass * @param string|null $type * @return array */ public function getEntityTypedFields($entityOrClass, $type = null) { $entityOrClass = ClassUtils::getRealClass($entityOrClass); $contactInformationFields = $this->contactInformationFieldHelper->getEntityContactInformationColumns($entityOrClass); if (empty($contactInformationFields)) { return []; } if ($type) { $contactInformationFields = $this->filterByType($contactInformationFields, $type); } return $contactInformationFields; }
/** * Checks if the entity can have comments * * @param object|null $entity * * @return bool */ public function isApplicable($entity = null) { if (!is_object($entity) || !$this->securityFacade->isGranted('oro_comment_view')) { return false; } $className = ClassUtils::getRealClass($entity); if (!$this->isExtendEntity($className)) { return false; } $config = $this->configManager->getProvider('comment')->getConfig($className); return $config->is('enabled'); }
/** * Create new * * @param mixed $_ [optional] Arguments will be passed to createEntity method * @return Response */ public function handleCreateRequest() { $entity = call_user_func_array(array($this, 'createEntity'), func_get_args()); $isProcessed = $this->processForm($entity); if ($isProcessed) { $entityClass = ClassUtils::getRealClass($entity); $classMetadata = $this->getManager()->getObjectManager()->getClassMetadata($entityClass); $view = $this->view($classMetadata->getIdentifierValues($entity), Codes::HTTP_CREATED); } else { $view = $this->view($this->getForm(), Codes::HTTP_BAD_REQUEST); } return $this->handleView($view); }
/** * Gets organization of the given entity * * @param $object * @return object|null * @throws InvalidEntityException */ public function getOrganization($object) { if (!is_object($object)) { throw new InvalidEntityException('$object must be an object.'); } $result = null; $metadata = $this->metadataProvider->getMetadata(ClassUtils::getRealClass($object)); if ($metadata->getGlobalOwnerFieldName()) { $accessor = PropertyAccess::createPropertyAccessor(); $result = $accessor->getValue($object, $metadata->getGlobalOwnerFieldName()); } return $result; }
/** * {@inheritdoc} */ public function getValue(ResultRecordInterface $record) { $entity = $record->getValue('entity'); $entityClass = ClassUtils::getRealClass($entity); if (empty($this->entitiesConfig[$entityClass])) { throw new InvalidConfigurationException(sprintf('Unknown entity type %s, unable to find search configuration', $entityClass)); } else { $searchTemplate = $this->entitiesConfig[$entityClass]['search_template']; } if (!$this->params->offsetGetOr('template', false)) { $this->params->offsetSet('template', $searchTemplate); } return $this->getTemplate()->render(array('indexer_item' => $record->getValue('indexer_item'), 'entity' => $record->getValue('entity'))); }
/** * {@inheritdoc} */ public function getObjectIdentity($domainObject) { try { if ($domainObject instanceof ObjectIdentityInterface) { return $domainObject; } if (method_exists($domainObject, 'getId') && is_null($domainObject->getId())) { return new ObjectIdentity('CLASS', ClassUtils::getRealClass($domainObject)); } return ObjectIdentity::fromDomainObject($domainObject); } catch (InvalidDomainObjectException $failed) { return; } }
public function preUpdate(PreUpdateEventArgs $args) { $entity = $args->getEntity(); $entityManager = $args->getEntityManager(); if (!$entity instanceof User) { return; } if ($args->hasChangedField('username')) { $class = ClassUtils::getRealClass($entity); $old_username = $args->getOldValue('username'); $new_username = $args->getNewValue('username'); $entityManager->getConnection()->update('acl_security_identities', array('identifier' => sprintf('%s-%s', $class, $new_username)), array('identifier' => sprintf('%s-%s', $class, $old_username))); } }
/** * Constructs an ObjectIdentity for the given domain object. * * @param object $domainObject * * @throws InvalidDomainObjectException * * @return ObjectIdentity */ public static function fromDomainObject($domainObject) { if (!is_object($domainObject)) { throw new InvalidDomainObjectException('$domainObject must be an object.'); } try { if ($domainObject instanceof DomainObjectInterface) { return new self($domainObject->getObjectIdentifier(), ClassUtils::getRealClass($domainObject)); } elseif (method_exists($domainObject, 'getId')) { return new self((string) $domainObject->getId(), ClassUtils::getRealClass($domainObject)); } } catch (\InvalidArgumentException $invalid) { throw new InvalidDomainObjectException($invalid->getMessage(), 0, $invalid); } throw new InvalidDomainObjectException('$domainObject must either implement the DomainObjectInterface, or have a method named "getId".'); }
/** * @param array $items * @return string */ protected function getClassName(array $items) { if (!$this->className) { $config = $this->getConfig(); if (array_key_exists('entityName', $config)) { $this->className = $config['entityName']; return $this->className; } } if (!$this->className && array_key_exists(0, $items)) { $this->className = ClassUtils::getRealClass($items[0]); return $this->className; } if (!$this->className) { throw new \RuntimeException('entityName not resolved'); } return $this->className; }
/** * @param object $entity * @return object|null */ protected function refreshEntity($entity) { $entityClass = ClassUtils::getRealClass($entity); $entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity); /** @var EntityManager $entityManager */ $entityManager = $this->registry->getManagerForClass($entityClass); if (!$entityId) { return null; } if ($entity instanceof Proxy && !$entity->__isInitialized()) { // We cannot use $entity->__load(); because of bug BAP-7851 return $entityManager->find($entityClass, $entityId); } try { return $entityManager->merge($entity); } catch (EntityNotFoundException $e) { return null; } }
/** * {@inheritdoc} */ public function merge(FieldData $fieldData) { $entityData = $fieldData->getEntityData(); $masterEntity = $entityData->getMasterEntity(); $fieldMetadata = $fieldData->getMetadata(); $entities = $fieldData->getEntityData()->getEntities(); foreach ($entities as $sourceEntity) { if ($sourceEntity->getId() !== $masterEntity->getId()) { $entityClass = ClassUtils::getRealClass($masterEntity); $activityClass = $fieldMetadata->get('type'); $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass); $activityListItems = $queryBuilder->getQuery()->getResult(); $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id'); $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId()); $activityIds = ArrayUtils::arrayColumn($activityListItems, 'relatedActivityId'); $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass); } } }