/** * Executes the actions * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $force = true === $input->getOption('force'); foreach ($this->mapping as $className => $options) { $metadata = $this->doctrineHelper->getClassMetadata($className); $this->dumpSerializationFile($metadata, $options, $output, $force); } }
/** * Executes the actions * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $metadataCollection = $this->doctrineHelper->getMetadataFactory()->getAllMetadata(); $force = true === $input->getOption('force'); foreach ($metadataCollection as $entityMetadata) { $this->dumpSerializationFile($entityMetadata, $output, $force); } }
/** * @return array */ protected function getConfiguration() { $configuration = []; $metadataCollection = $this->doctrineHelper->getMetadataFactory()->getAllMetadata(); foreach ($metadataCollection as $entityMetadata) { $this->appendConfigurationFromMetadata($entityMetadata, $configuration); } return $configuration; }
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); } }
protected function getTranslatableRespositories() : Collection { $collection = new ArrayCollection(); $metadata = $this->doctrineHelper->getAllMetadata(); foreach ($metadata as $classMetadata) { $reflectionClass = $classMetadata->getReflectionClass(); if ($reflectionClass->implementsInterface(LocaleAwareInterface::class)) { $repository = $this->entityManager->getRepository($reflectionClass->getName()); $collection->add($repository); } } return $collection; }
/** * 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); }
public function getEntityManager() : ObjectManager { return $this->helper->getEntityManager(); }
/** * Returns the metadata for entity * * @param object $entity * * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata */ protected function getEntityMetadata($entity) { return $this->doctrineHelper->getClassMetadataForEntity($entity); }