Returns Doctrine manager
public getEntityManager ( ) : Doctrine\Common\Persistence\ObjectManager | object | ||
return | Doctrine\Common\Persistence\ObjectManager | object |
private function duplicateTranslatableEntity(LocaleAwareInterface $entity, array $properties, LocaleInterface $targetLocale) { $duplicate = clone $entity; foreach ($properties as $propertyName) { $value = sprintf('%s-%s', $this->propertyAccessor->getValue($entity, $propertyName), $targetLocale->getCode()); $this->propertyAccessor->setValue($duplicate, $propertyName, $value); $duplicate->setLocale($targetLocale->getCode()); $this->doctrineHelper->getEntityManager()->persist($duplicate); } }
/** * Adds new rate or updates existing one * * @param string $currencyFrom * @param string $currencyTo * @param float $rate */ protected function addUpdateExchangeRate($currencyFrom, $currencyTo, $rate) { if (!in_array($currencyTo, $this->managedCurrencies)) { return false; } $exchangeRate = $this->ratesRepository->findOneBy(['currencyFrom' => $currencyFrom, 'currencyTo' => $currencyTo]); if (null === $exchangeRate) { $exchangeRate = new CurrencyRate(); $exchangeRate->setCurrencyFrom($currencyFrom); $exchangeRate->setCurrencyTo($currencyTo); $exchangeRate->setExchangeRate($rate); $this->helper->getEntityManager()->persist($exchangeRate); } else { $exchangeRate->setExchangeRate($rate); } return true; }
/** * Creates new admin menu item * * @param \SimpleXMLElement $item */ protected function addMenuItem(\SimpleXMLElement $item) { $em = $this->doctrineHelper->getEntityManager(); $adminMenuItem = $this->adminMenuRepository->findOneBy(['identifier' => (string) $item->identifier]); $parent = $this->adminMenuRepository->findOneBy(['identifier' => (string) $item->parent]); if (null === $adminMenuItem) { $adminMenuItem = $this->adminMenuFactory->create(); $adminMenuItem->setCssClass((string) $item->css_class); $adminMenuItem->setIdentifier((string) $item->identifier); $adminMenuItem->setName((string) $item->name); $adminMenuItem->setRouteName((string) $item->route_name); $adminMenuItem->setHierarchy((int) $item->hierarchy); $adminMenuItem->setParent($parent); $em->persist($adminMenuItem); $em->flush(); } }
/** * Deletes the translatable entities for locale * * @param EntityRepository $repository * @param LocaleInterface $locale * @param OutputInterface $output */ protected function deleteTranslatableEntities(EntityRepository $repository, LocaleInterface $locale, OutputInterface $output) { $entityManager = $this->doctrineHelper->getEntityManager(); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('locale', $locale->getCode())); $collection = $repository->matching($criteria); $collection->map(function (LocaleAwareInterface $entity) use($entityManager) { $entityManager->remove($entity); }); $output->write(sprintf('Deleted <info>%s</info> entities <info>%s</info>', $collection->count(), $repository->getClassName()), true); }
/** * LocaleCopier constructor. * * @param DoctrineHelperInterface $doctrineHelper */ public function __construct(DoctrineHelperInterface $doctrineHelper) { $this->doctrineHelper = $doctrineHelper; $this->entityManager = $doctrineHelper->getEntityManager(); $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); }
public function getEntityManager() : ObjectManager { return $this->helper->getEntityManager(); }