/** * Overwrites given keyword. * * @param CategoryInterface $category * @param Keyword $keyword * * @return Keyword */ private function handleOverwrite(KeywordInterface $keyword, CategoryInterface $category) { if (null !== ($synonym = $this->findSynonym($keyword))) { // reset entity and remove it from category if ($this->entityManager->contains($keyword)) { $this->entityManager->refresh($keyword); } $this->delete($keyword, $category); // link this synonym to the category $keyword = $synonym; } $categoryTranslation = $category->findTranslationByLocale($keyword->getLocale()); if (!$categoryTranslation) { $categoryTranslation = $this->createTranslation($category, $keyword->getLocale()); } // if keyword already exists in category if ($categoryTranslation->hasKeyword($keyword)) { return $keyword; } $keyword->addCategoryTranslation($categoryTranslation); $categoryTranslation->addKeyword($keyword); // FIXME category and meta will not be updated if only keyword was changed $category->setChanged(new \DateTime()); $categoryTranslation->setChanged(new \DateTime()); return $keyword; }
public function __invoke() { if (null === ($renderer = $this->_renderer)) { return ''; } if (null === ($page = $renderer->getCurrentPage())) { return ''; } $metadata = $page->getMetadata(); if (null === $metadata || $metadata->count() === 0) { // @todo gvf $metadata = new MetaDataBag($this->metadataConfig, $page); $page->setMetaData($metadata); if ($this->entityManager->contains($page)) { $this->entityManager->flush($page); } } $result = ''; foreach ($metadata as $meta) { if (0 < $meta->count() && 'title' !== $meta->getName()) { $result .= '<meta '; foreach ($meta as $attribute => $value) { if (false !== strpos($meta->getName(), 'keyword') && 'content' === $attribute) { $keywords = explode(',', $value); foreach ($this->getKeywordObjects($keywords) as $object) { $value = trim(str_replace($object->getUid(), $object->getKeyWord(), $value), ','); } } $result .= $attribute . '="' . html_entity_decode($value, ENT_COMPAT, 'UTF-8') . '" '; } $result .= '/>' . PHP_EOL; } } return $result; }
/** * @param $entity * @param $field * @return null|object * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException */ protected function refreshEntityField($entity, $field) { $accessor = PropertyAccess::createPropertyAccessor(); if ($accessor->isReadable($entity, $field)) { $field = $accessor->getValue($entity, $field); if (empty($field) && $this->entityManager->contains($entity)) { $this->entityManager->refresh($entity); } // if } // if return $this; }
/** * Deletes an entity if it is in relation to another entity * * Doctrine is obviously unable to entities detached from the relational entity when merging the relational entity, * so this had to be implemented. * * @param object $relationalEntity * @param string $fieldName * @param ClassMetadata $metadata * @param boolean $recomputeChangeSet */ public function deleteOnRelationalModification($relationalEntity, $fieldName, ClassMetadata $metadata, $recomputeChangeSet = true) { if ($recomputeChangeSet) { $this->unitOfWork->computeChangeSet($metadata, $relationalEntity); } $changeSet = $this->unitOfWork->getEntityChangeSet($relationalEntity); if (!isset($changeSet[$fieldName])) { return; } $orgValue = $changeSet[$fieldName][0]; if (null !== $orgValue && $this->entityManager->contains($orgValue)) { $this->entityManager->remove($orgValue); } }
/** * @return User|null */ protected function getUser() { if (!($token = $this->tokenStorage->getToken())) { return null; } $user = $token->getUser(); /** * Check cases when user is not in the entity manager * (e.g. after clear or if it is in the different entity manager) */ if ($user instanceof User && !$this->entityManager->contains($user)) { $user = $this->entityManager->find('OroUserBundle:User', $user->getId()); } return $user; }