예제 #1
0
 /**
  * DiffManager constructor.
  * @param ManagerRegistry $managerRegistry
  * @param string          $recolnatAlias
  * @param string          $recolnatBufferAlias
  */
 public function __construct(ManagerRegistry $managerRegistry, $recolnatAlias, $recolnatBufferAlias)
 {
     $this->managerRegistry = $managerRegistry;
     $this->em = $managerRegistry->getManager('default');
     $this->recolnatAlias = $recolnatAlias;
     $this->recolnatBufferAlias = $recolnatBufferAlias;
 }
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     /** @var ShoppingListRepository $shoppingListRepository */
     $shoppingListRepository = $currentShoppingList = $this->registry->getManagerForClass($this->shoppingListClass)->getRepository($this->shoppingListClass);
     $currentShoppingList = $shoppingListRepository->findCurrentForAccountUser($this->getAccountUser());
     $view->children['shoppingList']->vars['currentShoppingList'] = $currentShoppingList;
 }
예제 #3
0
 /**
  */
 protected function setUpDoctrine()
 {
     static::bootKernel();
     $this->container = static::$kernel->getContainer();
     $this->doctrine = $this->createDoctrineRegistry();
     $this->em = $this->doctrine->getManager();
     $this->loader = new Loader();
 }
 /**
  * Returns a metadata for the given entity
  *
  * @param string $className
  * @return ClassMetadata
  */
 protected function getClassMetadata($className)
 {
     if (isset($this->classMetadataLocalCache[$className])) {
         return $this->classMetadataLocalCache[$className];
     }
     $classMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
     $this->classMetadataLocalCache[$className] = $classMetadata;
     return $classMetadata;
 }
 /**
  * Executes a job with given payload
  *
  * @param  array $payload
  * @return mixed
  */
 public function execute(array $payload)
 {
     list($entityClass, $entityId) = $payload;
     $entity = $this->doctrine->getRepository($entityClass)->find($entityId);
     if (null === $entity) {
         return false;
     }
     return $this->exporter->cacheItem($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function getQueryBuilder(Segment $segment)
 {
     $converter = new SegmentQueryConverter($this->manager, $this->virtualFieldProvider, $this->doctrine, $this->restrictionBuilder);
     if ($this->virtualRelationProvider) {
         $converter->setVirtualRelationProvider($this->virtualRelationProvider);
     }
     /** @var EntityManager  $em */
     $em = $this->doctrine->getManagerForClass($segment->getEntity());
     $qb = $converter->convert(new RestrictionSegmentProxy($segment, $em));
     return $qb;
 }
예제 #7
0
 /**
  * @param \Symfony\Bridge\Doctrine\ManagerRegistry $registry
  * @param \Doctrine\Common\Persistence\ObjectManager $om
  * @param \Doctrine\Common\Persistence\ObjectRepository $repository
  * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
  */
 public function it_should_have_doctrine_data_indexer($registry, $om, $repository, $metadata)
 {
     $registry->getManagerForClass('FSi/Bundle/DemoBundle/Entity/Entity')->willReturn($om);
     $om->getRepository('FSiDemoBundle:Entity')->willReturn($repository);
     $metadata->isMappedSuperclass = false;
     $metadata->rootEntityName = 'FSi/Bundle/DemoBundle/Entity/Entity';
     $om->getClassMetadata('FSi/Bundle/DemoBundle/Entity/Entity')->willReturn($metadata);
     $repository->getClassName()->willReturn('FSi/Bundle/DemoBundle/Entity/Entity');
     $this->setManagerRegistry($registry);
     $this->getDataIndexer()->shouldReturnAnInstanceOf('FSi\\Component\\DataIndexer\\DoctrineDataIndexer');
 }
예제 #8
0
 /**
  * @param JsonDeserializationVisitor $visitor
  * @param $data
  * @param array $type
  * @return ArrayCollection
  */
 public function deserializeIdCollectionFromJson(JsonDeserializationVisitor $visitor, $data, array $type)
 {
     $collection = new ArrayCollection();
     $class = $type['params'][0]['name'];
     /** @var \Doctrine\Common\Persistence\ObjectRepository $repository */
     $repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
     foreach ($data as $key => $value) {
         $collection->add($repository->findOneBy(array('id' => $value)));
     }
     return $collection;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function getConfiguration($gridName)
 {
     if (empty($this->configuration[$gridName])) {
         $id = intval(substr($gridName, strlen(Segment::GRID_PREFIX)));
         $segmentRepository = $this->doctrine->getRepository('OroSegmentBundle:Segment');
         $segment = $segmentRepository->find($id);
         $this->builder->setGridName($gridName);
         $this->builder->setSource($segment);
         $this->configuration[$gridName] = $this->builder->getConfiguration();
     }
     return $this->configuration[$gridName];
 }
예제 #10
0
 /**
  * @param MarketingList $marketingList
  * @param int $entityId
  * @return MarketingListItem
  */
 public function getMarketingListItem(MarketingList $marketingList, $entityId)
 {
     $marketingListItemRepository = $this->registry->getRepository(self::MARKETING_LIST_ITEM_ENTITY);
     $marketingListItem = $marketingListItemRepository->findOneBy(['marketingList' => $marketingList, 'entityId' => $entityId]);
     if (!$marketingListItem) {
         $marketingListItem = new MarketingListItem();
         $marketingListItem->setMarketingList($marketingList)->setEntityId($entityId);
         $manager = $this->registry->getManagerForClass(self::MARKETING_LIST_ITEM_ENTITY);
         $manager->persist($marketingListItem);
     }
     return $marketingListItem;
 }
 /**
  * {@inheritdoc}
  */
 public function getConfiguration($gridName)
 {
     if ($this->configuration === null) {
         $id = intval(substr($gridName, strlen(Report::GRID_PREFIX)));
         $repo = $this->doctrine->getRepository('OroReportBundle:Report');
         $report = $repo->find($id);
         $this->builder->setGridName($gridName);
         $this->builder->setSource($report);
         $this->configuration = $this->builder->getConfiguration();
     }
     return $this->configuration;
 }
 public function testGetDeleteMessageTextForDataGrid()
 {
     $paymentTermId = 1;
     $paymentTermRepository = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Entity\\Repository\\PaymentTermRepository')->disableOriginalConstructor()->getMock();
     $paymentTermRepository->expects($this->once())->method('find')->with($paymentTermId)->willReturnCallback(function ($id) {
         return new PaymentTermStub($id);
     });
     $om = $this->getMock('\\Doctrine\\Common\\Persistence\\ObjectManager');
     $om->expects($this->once())->method('getRepository')->with($this->equalTo('OroB2BPaymentBundle:PaymentTerm'))->willReturn($paymentTermRepository);
     $this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->equalTo('OroB2BPaymentBundle:PaymentTerm'))->willReturn($om);
     $message = $this->extension->getDeleteMessageTextForDataGrid($paymentTermId);
     $this->assertDeleteMessage($message, $paymentTermId, 0, 0);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $em = $this->registry->getManagerForClass($this->integrationEntityFQCN);
     $formFactory = $builder->getFormFactory();
     $data = $builder->create('data', 'hidden');
     $data->addViewTransformer(new ArrayToJsonTransformer());
     $identifier = $builder->create('identifier', 'hidden');
     $identifier->addViewTransformer(new EntityToIdTransformer($em, $this->integrationEntityFQCN));
     $builder->addViewTransformer(new DatasourceDataTransformer($formFactory));
     $builder->add($data);
     $builder->add($identifier);
     $builder->add('type', 'hidden', ['data' => $options['type']]);
     $builder->add('name', 'hidden');
 }
예제 #14
0
 /**
  * @param FormEvent $event
  */
 public function preSubmitData(FormEvent $event)
 {
     $data = $event->getData();
     if (!isset($data['product'], $data['unit'], $data['quantity'])) {
         return;
     }
     /** @var Product $product */
     $product = $this->registry->getRepository($this->productClass)->find($data['product']);
     if ($product) {
         $unitPrecision = $product->getUnitPrecision($data['unit']);
         if ($unitPrecision) {
             $data['quantity'] = $this->roundingService->round($data['quantity'], $unitPrecision->getPrecision());
             $event->setData($data);
         }
     }
 }
예제 #15
0
 public function send()
 {
     $this->assertTransport();
     $marketingList = $this->emailCampaign->getMarketingList();
     /** @var EntityManager $manager */
     $manager = $this->registry->getManager();
     foreach ($this->getIterator() as $entity) {
         $to = $this->contactInformationFieldsProvider->getQueryContactInformationFields($marketingList->getSegment(), $entity, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL);
         try {
             $manager->beginTransaction();
             // Do actual send
             $this->transport->send($this->emailCampaign, $entity, [$this->getSenderEmail() => $this->getSenderName()], $to);
             // Mark marketing list item as contacted
             $marketingListItem = $this->marketingListItemConnector->contact($marketingList, $entity->getId());
             // Record email campaign contact statistic
             $statisticsRecord = new EmailCampaignStatistics();
             $statisticsRecord->setEmailCampaign($this->emailCampaign)->setMarketingListItem($marketingListItem);
             $manager->persist($statisticsRecord);
             $manager->flush();
             $manager->commit();
         } catch (\Exception $e) {
             $manager->rollback();
             if ($this->logger) {
                 $this->logger->error(sprintf('Email sending to "%s" failed.', implode(', ', $to)), array('exception' => $e));
             }
         }
     }
     $this->emailCampaign->setSent(true);
     $manager->persist($this->emailCampaign);
     $manager->flush();
 }
예제 #16
0
 /**
  * @return ObjectManager
  */
 protected function getManager()
 {
     if (!$this->manager) {
         $this->manager = $this->doctrine->getManager();
     }
     return $this->manager;
 }
예제 #17
0
 /**
  * @dataProvider createTreeDataProvider
  * @param Page[] $pages
  * @param array $expected
  */
 public function testCreateTree($pages, array $expected)
 {
     $this->managerRegistry->expects($this->any())->method('getRepository')->with('OroB2BCMSBundle:Page')->willReturn($this->repository);
     $this->repository->expects($this->any())->method('getChildren')->with(null, false, 'left', 'ASC')->willReturn($pages);
     $result = $this->pageTreeHandler->createTree();
     $this->assertEquals($expected, $result);
 }
예제 #18
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException|RootNodeNotFoundException|RootMayNotBeMovedException|MissingParentCategoryException
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $entity = $this->getItem($this->dataProvider, $resourceType, $id);
     $parentId = $request->request->get("parent");
     $parentEntity = $this->iriConverter->getItemFromIri($parentId);
     if ($parentEntity === null) {
         throw new MissingParentCategoryException($parentId);
     }
     if ($entity->getLevel() === 0) {
         throw new RootMayNotBeMovedException();
     }
     $entity->setParent($parentEntity);
     $this->registry->getManager()->flush();
     return new Response($request->request->get("parent"));
 }
예제 #19
0
 /**
  * @param object $object
  * @param object|null $entity
  */
 protected function processExclusions($object, $entity)
 {
     $class = get_class($object);
     if (!$entity) {
         return;
     }
     $reflection = new \ReflectionClass($class);
     /** Backfill data that is ignored or read only from the serializer */
     $metadata = $this->metadataFactory->getMetadataForClass($class);
     foreach ($reflection->getProperties() as $property) {
         $name = $property->getName();
         if (!isset($metadata->propertyMetadata[$name]) || $metadata->propertyMetadata[$name]->readOnly) {
             $property->setAccessible(true);
             $property->setValue($object, $property->getValue($entity));
         }
     }
     $em = $this->doctrine->getManagerForClass($class);
     /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */
     $metadata = $em->getMetadataFactory()->getMetadataFor($class);
     // Look for relationships, compare against preloaded entity
     foreach ($metadata->getAssociationNames() as $fieldName) {
         if ($metadata->isCollectionValuedAssociation($fieldName)) {
             $property = $reflection->getProperty($fieldName);
             $property->setAccessible(true);
             if ($property->getValue($object)) {
                 foreach ($property->getValue($object) as $i => $value) {
                     $v = $property->getValue($entity);
                     $this->processExclusions($value, $v[$i]);
                 }
             }
         }
     }
 }
예제 #20
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request)
 {
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var ResourceInterface $resourceType
      */
     $repository = $this->manager->getRepository($resourceType->getEntityClass());
     /**
      * @var $repository AbstractTreeRepository
      */
     $rootNodes = $repository->getRootNodes();
     if (count($rootNodes) == 0) {
         throw new RootNodeNotFoundException();
     }
     $rootNode = reset($rootNodes);
     return $rootNode;
 }
예제 #21
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request The request
  * @param int $id The ID of the part
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $part = $this->getItem($this->dataProvider, $resourceType, $id);
     /**
      * @var $part Part
      */
     $quantity = $request->request->get("quantity");
     $user = $this->userService->getUser();
     $stock = new StockEntry(0 - intval($quantity), $user);
     if ($request->request->has("comment") && $request->request->get("comment") !== null) {
         $stock->setComment($request->request->get("comment"));
     }
     $part->addStockEntry($stock);
     $this->registry->getManager()->persist($stock);
     $this->registry->getManager()->flush();
     return $part;
 }
 /**
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     /** @var LineItem $lineItem */
     $lineItem = $event->getForm()->getData();
     $data = $event->getData();
     $product = $lineItem->getProduct();
     if (!$product instanceof Product && !empty($data['product'])) {
         /** @var ProductRepository $repository */
         $repository = $this->registry->getManagerForClass($this->productClass)->getRepository($this->productClass);
         /** @var Product $product */
         $product = $repository->find((int) $data['product']);
     }
     if (!$product || empty($data['unit']) || empty($data['quantity'])) {
         return;
     }
     $roundedQuantity = $this->lineItemManager->roundProductQuantity($product, $data['unit'], $data['quantity']);
     $data['quantity'] = $roundedQuantity;
     $event->setData($data);
 }
예제 #23
0
 /**
  * Gets doctrine entity manager for the given class
  *
  * @param string $className
  *
  * @return EntityManager
  * @throws InvalidEntityException
  */
 protected function getManagerForClass($className)
 {
     $manager = null;
     try {
         $manager = $this->doctrine->getManagerForClass($className);
     } catch (\ReflectionException $ex) {
         throw new InvalidEntityException(sprintf('The "%s" entity was not found.', $className));
     }
     return $manager;
 }
 /**
  * @param mixed $object
  *
  * @return bool
  */
 private function isEntity($object)
 {
     $isEntity = false;
     if (is_object($object)) {
         $class = $object instanceof Proxy ? get_parent_class($object) : get_class($object);
         if (null !== ($manager = $this->registry->getManagerForClass($class))) {
             $isEntity = !$this->registry->getManager()->getMetadataFactory()->isTransient($class);
         }
     }
     return $isEntity;
 }
 function it_does_nothing_when_form_data_has_no_translatable_properties(ManagerRegistry $managerRegistry, ObjectManager $objectManager, TranslatableListener $translatableListener, FormEvent $event, FormInterface $form, FormConfigInterface $formConfig, ClassMetadata $translatableClassMetadata)
 {
     $translatableListener->getLocale()->willReturn('en');
     $event->getForm()->willReturn($form);
     $form->getConfig()->willReturn($formConfig);
     $formConfig->getOption('data_class')->willReturn('TranslatableEntity');
     $managerRegistry->getManagerForClass('TranslatableEntity')->willReturn($objectManager);
     $translatableListener->getExtendedMetadata($objectManager, 'TranslatableEntity')->willReturn($translatableClassMetadata);
     $translatableClassMetadata->hasTranslatableProperties()->willReturn(false);
     $event->getData()->shouldNotBeCalled();
     $this->setTranslatableLocale($event);
 }
예제 #26
0
 /**
  * @param string $jobType
  * @param string $jobName
  * @param array $configuration
  * @return JobResult
  */
 public function executeJob($jobType, $jobName, array $configuration = array())
 {
     // create and persist job instance and job execution
     $jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName);
     $jobInstance->setCode($this->generateJobCode($jobName));
     $jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName));
     $jobInstance->setRawConfiguration($configuration);
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     // persist batch entities
     $this->batchJobManager->persist($jobInstance);
     $this->batchJobManager->persist($jobExecution);
     // do job
     $jobResult = $this->doJob($jobInstance, $jobExecution);
     // EntityManager can be closed when there was an exception in flush method called inside some jobs execution
     // Can't be implemented right now due to OroEntityManager external dependencies
     // on ExtendManager and FilterCollection
     if (!$this->entityManager->isOpen()) {
         $this->managerRegistry->resetManager();
         $this->entityManager = $this->managerRegistry->getManager();
     }
     // flush batch entities
     $this->batchJobManager->flush($jobInstance);
     $this->batchJobManager->flush($jobExecution);
     // set data to JobResult
     $jobResult->setJobId($jobInstance->getId());
     $jobResult->setJobCode($jobInstance->getCode());
     // TODO: Find a way to work with multiple amount of job and step executions
     // TODO: https://magecore.atlassian.net/browse/BAP-2600
     /** @var JobExecution $jobExecution */
     $jobExecution = $jobInstance->getJobExecutions()->first();
     if ($jobExecution) {
         $stepExecution = $jobExecution->getStepExecutions()->first();
         if ($stepExecution) {
             $context = $this->contextRegistry->getByStepExecution($stepExecution);
             $jobResult->setContext($context);
         }
     }
     return $jobResult;
 }
예제 #27
0
 protected function prepareEmMock()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $entity = new Integration();
     $entity->setName(self::TEST_NAME);
     $entity->setType(self::TEST_TYPE);
     $this->registry->expects($this->once())->method('getManagerForClass')->with($this->equalTo($this->testEntityName))->will($this->returnValue($em));
     $em->expects($this->once())->method('getClassMetadata')->with($this->equalTo($this->testEntityName))->will($this->returnValue($metadata));
     $metadata->expects($this->once())->method('getSingleIdentifierFieldName')->will($this->returnValue(self::TEST_ID_FIELD_NAME));
     $em->expects($this->once())->method('getRepository')->with($this->equalTo($this->testEntityName))->will($this->returnValue($repo));
     $repo->expects($this->once())->method('find')->with($this->equalTo(self::TEST_ID))->will($this->returnValue($entity));
 }
 /**
  * @param string|object $class
  * @return ClassMetadata
  */
 protected function getClassMetadata($class)
 {
     if (is_object($class)) {
         $class = get_class($class);
     }
     if (!is_string($class)) {
         throw new \InvalidArgumentException("Argument must be either string or object, got " . gettype($class));
     }
     $objectManager = $this->managerRegistry->getManagerForClass($class);
     if (null === $objectManager) {
         throw new \RuntimeException("Could not find object manager for class '{$class}'");
     }
     return $objectManager->getClassMetadata($class);
 }
예제 #29
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request The request
  * @param int     $id      The ID of the part
  *
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $part = $this->getItem($this->dataProvider, $resourceType, $id);
     /*
      * @var $part Part
      */
     $quantity = $request->request->get('quantity');
     $user = $this->userService->getUser();
     $oldQuantity = $part->getStockLevel();
     $correctionQuantity = $quantity - $oldQuantity;
     if ($correctionQuantity != 0) {
         $stock = new StockEntry();
         $stock->setStockLevel($correctionQuantity);
         $stock->setUser($user);
         if ($request->request->has('comment') && $request->request->get('comment') !== null) {
             $stock->setComment($request->request->get('comment'));
         }
         $part->addStockLevel($stock);
         $this->registry->getManager()->persist($stock);
         $this->registry->getManager()->flush();
     }
     return $part;
 }
예제 #30
0
 /**
  * Loads table name <-> entity class name maps
  */
 protected function loadNameMaps()
 {
     $this->tableToClassMap = [];
     $this->classToTableMap = [];
     $names = array_keys($this->doctrine->getManagers());
     foreach ($names as $name) {
         $manager = $this->doctrine->getManager($name);
         if ($manager instanceof EntityManager) {
             $allMetadata = $this->getAllMetadata($manager);
             foreach ($allMetadata as $metadata) {
                 $tableName = $metadata->getTableName();
                 if (!empty($tableName)) {
                     $className = $metadata->getName();
                     $this->tableToClassMap[$tableName] = $className;
                     $this->classToTableMap[$className] = $tableName;
                 }
             }
         }
     }
 }