/**
  * @return ObjectRepository
  */
 protected function getLoginPageRepository()
 {
     if (!$this->loginPageRepository) {
         $this->loginPageRepository = $this->doctrine->getManagerForClass('OroB2BCMSBundle:LoginPage')->getRepository('OroB2BCMSBundle:LoginPage');
     }
     return $this->loginPageRepository;
 }
 /**
  * @return \DateTime|null
  */
 public function getLastSyncDate()
 {
     $channel = $this->getChannel();
     $repository = $this->managerRegistry->getRepository('OroIntegrationBundle:Status');
     /**
      * @var Status $status
      */
     $status = $repository->findOneBy(['code' => Status::STATUS_COMPLETED, 'channel' => $channel, 'connector' => $this->getType()], ['date' => 'DESC']);
     $timezone = new \DateTimeZone('UTC');
     $date = new \DateTime('now', $timezone);
     $context = $this->getStepExecution()->getExecutionContext();
     $data = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY) ?: [];
     $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, array_merge($data, [self::LAST_SYNC_DATE_KEY => $date->format(\DateTime::ISO8601)]));
     if (!$status) {
         return null;
     }
     $data = $status->getData();
     if (empty($data)) {
         return null;
     }
     if (!empty($data[self::LAST_SYNC_DATE_KEY])) {
         return new \DateTime($data[self::LAST_SYNC_DATE_KEY], $timezone);
     }
     return null;
 }
 /**
  * Checks the object is an instance of a given class.
  *
  * @param MarketingList $marketingList
  * @return bool
  */
 public function isApplicableOnMarketingList($marketingList)
 {
     if ($marketingList instanceof MarketingList) {
         return (bool) $this->registry->getManager()->getRepository('OroCRMMailChimpBundle:StaticSegment')->findOneBy(['marketingList' => $marketingList]);
     }
     return false;
 }
 /**
  * @param FormEvent $event
  */
 public function postSetData(FormEvent $event)
 {
     $form = $event->getForm();
     if ($form->getParent()) {
         return;
     }
     if (!$form->has($this->fieldName)) {
         return;
     }
     $isEntityExists = false;
     $entity = $event->getData();
     if ($entity) {
         if (!is_object($entity)) {
             return;
         }
         $entityClass = ClassUtils::getClass($entity);
         $entityManager = $this->managerRegistry->getManagerForClass($entityClass);
         if (!$entityManager) {
             return;
         }
         $entityIdentifier = $entityManager->getClassMetadata($entityClass)->getIdentifierValues($entity);
         $isEntityExists = !empty($entityIdentifier);
     }
     // if entity exists and assign is not granted - replace field with disabled text field,
     // otherwise - set default owner value
     if ($isEntityExists) {
         $this->replaceOwnerField($form);
     } else {
         $this->setPredefinedOwner($form);
     }
 }
 /**
  * @param string                                                      $class
  * @param \Doctrine\Common\Persistence\ManagerRegistry                $manager_registry
  * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
  */
 public function __construct($class, ManagerRegistry $manager_registry, EventDispatcherInterface $event_dispatcher = null)
 {
     $this->class = $class;
     $this->event_dispatcher = $event_dispatcher;
     $this->entity_manager = $manager_registry->getManagerForClass($class);
     $this->entity_repository = $this->entity_manager->getRepository($class);
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider  $provider
  * @param ManagerRegistry        $registry
  * @param SqlBuilder             $builder
  * @param MigrationFileGenerator $generator
  */
 public function fire(ConfigurationProvider $provider, ManagerRegistry $registry, SqlBuilder $builder, MigrationFileGenerator $generator)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $em = $registry->getManager($this->option('connection'));
     $connection = $configuration->getConnection();
     // Overrule the filter
     if ($filterExpr = $this->option('filter-expression')) {
         $connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
     }
     $fromSchema = $connection->getSchemaManager()->createSchema();
     $toSchema = $this->getSchemaProvider($em)->createSchema();
     // Drop tables which don't suffice to the filter regex
     if ($filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression()) {
         foreach ($toSchema->getTables() as $table) {
             $tableName = $table->getName();
             if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
                 $toSchema->dropTable($tableName);
             }
         }
     }
     $up = $builder->up($configuration, $fromSchema, $toSchema);
     $down = $builder->down($configuration, $fromSchema, $toSchema);
     if (!$up && !$down) {
         return $this->error('No changes detected in your mapping information.');
     }
     $path = $generator->generate($configuration, false, false, $up, $down);
     $this->line(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
 }
 public function onLexikjwtauthenticationOnjwtcreated(JWTCreatedEvent $event)
 {
     $em = $this->registry->getManager();
     $data = $event->getData();
     $data['wownewfield'] = 'muchcool';
     $event->setData($data);
 }
Example #8
0
 public function __construct(ManagerRegistry $managerRegistry, ContainerInterface $container, ActivityService $activityService, LocationService $locationService)
 {
     $this->em = $managerRegistry->getManager();
     $this->container = $container;
     $this->activityService = $activityService;
     $this->locationService = $locationService;
 }
 private function prepareDatabase()
 {
     /** @var EntityManager $em */
     $em = $this->registry->getManager();
     $tool = new SchemaTool($em);
     $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['em'] === null) {
         $em = $this->registry->getManagerForClass($options['class']);
     } else {
         $em = $this->registry->getManager($options['em']);
     }
     $repository = $em->getRepository($options['class']);
     $entities = $repository->findAll();
     /** @var ClassMetadataInfo $classMetadata */
     $classMetadata = $em->getClassMetadata($options['class']);
     $identifierField = $classMetadata->getSingleIdentifierFieldName();
     $choiceLabels = [];
     /** @var AddressType $entity */
     foreach ($entities as $entity) {
         $pkValue = $classMetadata->getReflectionProperty($identifierField)->getValue($entity);
         if ($options['property']) {
             $value = $classMetadata->getReflectionProperty($options['property'])->getValue($entity);
         } else {
             $value = (string) $entity;
         }
         $choiceLabels[$pkValue] = $this->translator->trans('orob2b.customer.customer_typed_address_with_default_type.choice.default_text', ['%type_name%' => $value]);
     }
     $builder->add('default', 'choice', ['choices' => $choiceLabels, 'multiple' => true, 'expanded' => true, 'label' => false])->addViewTransformer(new AddressTypeDefaultTransformer($em));
 }
 /**
  * @param OrmFilterDatasourceAdapter $ds
  * @param string                     $fieldName
  *
  * @return array [entity, alias, field]
  *
  * @throws \RuntimeException
  */
 protected function getFilterParts(OrmFilterDatasourceAdapter $ds, $fieldName)
 {
     $fieldParts = explode('.', $fieldName);
     if (count($fieldParts) !== 2) {
         throw new \RuntimeException(sprintf('It is expected that $fieldName is in "alias.name" format, but "%s" given.', $fieldName));
     }
     $qb = $ds->getQueryBuilder();
     $entity = $this->getRootEntity($qb, $fieldParts[0]);
     if (empty($entity)) {
         $associations = [];
         $entity = $this->findEntityByAlias($qb, $fieldParts[0]);
         while (!empty($entity) && strpos($entity, ':') === false && strpos($entity, '\\') === false) {
             $parts = explode('.', $entity);
             array_unshift($associations, $parts[1]);
             $entity = $this->findEntityByAlias($qb, $parts[0]);
         }
         if (empty($entity)) {
             throw new \RuntimeException(sprintf('Cannot find root entity for "$s". It seems that a query is not valid.', $fieldName));
         }
         foreach ($associations as $assoc) {
             $entity = $this->doctrine->getManagerForClass($entity)->getClassMetadata($entity)->getAssociationTargetClass($assoc);
         }
     }
     if (empty($entity)) {
         throw new \RuntimeException(sprintf('Cannot find entity for "$s". It seems that a query is not valid.', $fieldName));
     }
     return [$entity, $fieldParts[0], $fieldParts[1]];
 }
Example #12
0
 /**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $this->datagrid = $grid;
     if (isset($config['query'])) {
         $queryConfig = array_intersect_key($config, array_flip(['query']));
         $converter = new YamlConverter();
         $this->qb = $converter->parse($queryConfig, $this->doctrine);
     } elseif (isset($config['entity']) && isset($config['repository_method'])) {
         $entity = $config['entity'];
         $method = $config['repository_method'];
         $repository = $this->doctrine->getRepository($entity);
         if (method_exists($repository, $method)) {
             $qb = $repository->{$method}();
             if ($qb instanceof QueryBuilder) {
                 $this->qb = $qb;
             } else {
                 throw new DatasourceException(sprintf('%s::%s() must return an instance of Doctrine\\ORM\\QueryBuilder, %s given', get_class($repository), $method, is_object($qb) ? get_class($qb) : gettype($qb)));
             }
         } else {
             throw new DatasourceException(sprintf('%s has no method %s', get_class($repository), $method));
         }
     } else {
         throw new DatasourceException(get_class($this) . ' expects to be configured with query or repository method');
     }
     if (isset($config['hints'])) {
         $this->queryHints = $config['hints'];
     }
     $grid->setDatasource(clone $this);
 }
 public function __construct(ManagerRegistry $managerRegistry, Session $session, TwigEngine $templating, EZPlatformClient $restClient)
 {
     $this->em = $managerRegistry->getManager();
     $this->session = $session;
     $this->templating = $templating;
     $this->restClient = $restClient;
 }
Example #14
0
 function it_creates_data_source_via_doctrine_orm_query_builder(ManagerRegistry $managerRegistry, EntityManagerInterface $entityManager, EntityRepository $entityRepository, QueryBuilder $queryBuilder)
 {
     $managerRegistry->getManagerForClass('App:Book')->willReturn($entityManager);
     $entityManager->getRepository('App:Book')->willReturn($entityRepository);
     $entityRepository->createQueryBuilder('o')->willReturn($queryBuilder);
     $this->getDataSource(['class' => 'App:Book'], new Parameters())->shouldHaveType(DataSource::class);
 }
 protected function setUp()
 {
     $encoder = new TokenEncoder($this->secret);
     $this->doctrine = $this->createDoctrineMock();
     $this->doctrine->expects($this->any())->method('getManager')->willReturn($this->getMockForAbstractClass(EntityManagerInterface::class));
     $this->manager = new TokenManager($encoder, $this->doctrine);
 }
 function let(ManagerRegistry $registry, ProductRepositoryInterface $repository, EntityManager $em, AttributeInterface $attribute, AttributeOptionInterface $option, AttributeOptionValueInterface $optionValue)
 {
     $registry->getRepository('product')->willReturn($repository);
     $repository->findAllWithAttributeOption($option)->willReturn([]);
     $option->getAttribute()->willReturn($attribute);
     $optionValue->getOption()->willReturn($option);
 }
Example #17
0
 public function testSubmit()
 {
     $choice = new \stdClass();
     $choice->{$identifierPath = 'id'} = $id = 1;
     $choice->{$labelPath = 'label'} = $label = 'label';
     $this->resource->expects($this->once())->method('getModel')->will($this->returnValue($model = get_class($choice)));
     $this->resource->expects($this->once())->method('getIdPropertyPath')->will($this->returnValue($identifierPath));
     $this->resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPath));
     $this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->identicalTo($model))->will($this->returnValue($entityManager = $this->createEntityManagerMock()));
     $entityManager->expects($this->once())->method('getRepository')->with($this->identicalTo($model))->will($this->returnValue($repository = $this->createRepositoryMock()));
     $entityManager->expects($this->exactly(3))->method('getClassMetadata')->with($this->identicalTo($model))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model));
     $classMetadata->expects($this->once())->method('getIdentifierFieldNames')->will($this->returnValue([$identifier = $identifierPath]));
     $classMetadata->expects($this->exactly(2))->method('getTypeOfField')->with($this->identicalTo($identifier))->will($this->returnValue('integer'));
     $repository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock($entityManager)));
     $queryBuilder->expects($this->exactly(2))->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
     $query->expects($this->once())->method('execute')->will($this->returnValue($choices = [$choice]));
     $queryBuilder->expects($this->once())->method('getRootAliases')->will($this->returnValue([$rootAlias = 'root_alias']));
     $queryBuilder->expects($this->once())->method('expr')->will($this->returnValue($expr = $this->createExprMock()));
     $queryBuilder->expects($this->once())->method('getEntityManager')->will($this->returnValue($entityManager));
     $queryBuilder->expects($this->once())->method('getRootEntities')->will($this->returnValue([$model]));
     $expr->expects($this->once())->method('in')->with($this->identicalTo($rootAlias . '.' . $identifier), $this->identicalTo(':' . ($parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_' . $identifier)))->will($this->returnValue($where = 'where'));
     $queryBuilder->expects($this->once())->method('andWhere')->with($this->identicalTo($where))->will($this->returnSelf());
     $query->expects($this->once())->method('setParameter')->with($this->identicalTo($parameter), $this->identicalTo([(string) $id]), $this->identicalTo(Connection::PARAM_INT_ARRAY))->will($this->returnSelf());
     $query->expects($this->once())->method('getResult')->will($this->returnValue([$choice]));
     $entityManager->expects($this->exactly(2))->method('contains')->with($this->identicalTo($choice))->will($this->returnValue(true));
     $classMetadata->expects($this->exactly(2))->method('getIdentifierValues')->with($this->identicalTo($choice))->will($this->returnValue([$id]));
     $form = $this->factory->create(ResourceChoiceType::class, null, ['resource' => $this->resource])->submit($id);
     $this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
     $this->assertSame($identifierPath, $form->getConfig()->getOption('choice_value'));
     $this->assertSame($labelPath, $form->getConfig()->getOption('choice_label'));
     $this->assertSame('', $form->getConfig()->getOption('placeholder'));
     $this->assertSame($choice, $form->getData());
     $form->createView();
 }
Example #18
0
 public function testSubmit()
 {
     $choice = new \stdClass();
     $choice->{$identifierPath = 'id'} = $id = 1;
     $choice->{$labelPath = 'label'} = $label = 'label';
     $this->resource->expects($this->once())->method('getModel')->will($this->returnValue($model = get_class($choice)));
     $this->resource->expects($this->once())->method('getIdPropertyPath')->will($this->returnValue($identifierPath));
     $this->resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPath));
     $this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->identicalTo($model))->will($this->returnValue($documentManager = $this->createDocumentManagerMock()));
     $documentManager->expects($this->once())->method('getRepository')->with($this->identicalTo($model))->will($this->returnValue($repository = $this->createRepositoryMock()));
     $documentManager->expects($this->exactly(2))->method('getClassMetadata')->with($this->identicalTo($model))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model));
     $classMetadata->expects($this->once())->method('getIdentifierFieldNames')->will($this->returnValue([$identifier = $identifierPath]));
     $classMetadata->expects($this->once())->method('getTypeOfField')->with($this->identicalTo($identifier))->will($this->returnValue('integer'));
     $repository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock($documentManager)));
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
     $query->expects($this->once())->method('execute')->will($this->returnValue($iterator = $this->createIteratorMock()));
     $iterator->expects($this->once())->method('toArray')->will($this->returnValue([$choice]));
     $form = $this->factory->create(ResourceChoiceType::class, null, ['resource' => $this->resource])->submit($id);
     $this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
     $this->assertSame($identifierPath, $form->getConfig()->getOption('choice_value'));
     $this->assertSame($labelPath, $form->getConfig()->getOption('choice_label'));
     $this->assertSame('', $form->getConfig()->getOption('placeholder'));
     $this->assertSame($choice, $form->getData());
     $form->createView();
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $repository = $this->manager->getRepository($options['class']);
     $transformer = new EntityToIdentifierTransformer($repository, $options['identifier']);
     $builder->addModelTransformer($transformer);
     $builder->setAttribute('repository', $repository);
 }
Example #20
0
 /**
  * @param Factory         $factory
  * @param SettingsManager $settings
  * @param Manager         $notification
  * @param ManagerRegistry $doctrine
  */
 public function __construct(Factory $factory, SettingsManager $settings, Manager $notification, ManagerRegistry $doctrine)
 {
     $this->factory = $factory;
     $this->notification = $notification;
     $this->settings = $settings;
     $this->entityManager = $doctrine->getManager();
 }
Example #21
0
 public function __construct(ManagerRegistry $managerRegistry, ContainerInterface $container, ActivityService $activityService)
 {
     $this->em = $managerRegistry->getManager();
     $this->container = $container;
     $this->activityService = $activityService;
     $this->twigExt = $this->container->get('campaignchain.core.twig.campaignchain_core_extension');
 }
 function it_should_throw_when_applicant_does_not_exist(ManagerRegistry $managerRegistry, ObjectManager $objectManager)
 {
     $id = 456;
     $managerRegistry->getManagerForClass(ApplicantsRepository::ENTITY_CLASS)->shouldBeCalled()->willReturn($objectManager);
     $objectManager->find(ApplicantsRepository::ENTITY_CLASS, $id)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(new EntityNotFoundException("Applicant does not exist."))->duringFetchApplicant($id);
 }
 function let(ManagerRegistry $managerRegistry, TranslatableListener $translatableListener, ObjectManager $manager, ClassMetadata $translatableMetadata)
 {
     $managerRegistry->getManagerForClass(Argument::type('string'))->willReturn($manager);
     $translatableListener->getExtendedMetadata($manager, Argument::type('string'))->willReturn($translatableMetadata);
     $translatableListener->getLocale()->willReturn('en');
     $this->beConstructedWith($managerRegistry, $translatableListener, new PropertyAccessor());
 }
Example #24
0
 /**
  * @return PaymentMethodRepository
  */
 public function getRepository()
 {
     if (null === $this->repository) {
         $this->repository = $this->registry->getRepository('CSBillPaymentBundle:PaymentMethod');
     }
     return $this->repository;
 }
Example #25
0
 /**
  * @param ManagerRegistry          $doctrine
  * @param EventDispatcherInterface $dispatcher
  * @param FactoryInterface         $stateMachine
  * @param NotificationManager      $notification
  */
 public function __construct(ManagerRegistry $doctrine, EventDispatcherInterface $dispatcher, FactoryInterface $stateMachine, NotificationManager $notification)
 {
     $this->entityManager = $doctrine->getManager();
     $this->dispatcher = $dispatcher;
     $this->stateMachine = $stateMachine;
     $this->notification = $notification;
 }
Example #26
0
 /**
  * @param string $type
  *
  * @return FilterIn|null
  */
 private function create($type)
 {
     $manager = $this->managerRegistry->getManagerForClass($type);
     if ($manager) {
         return new FilterIn($manager->getRepository($type));
     }
 }
Example #27
0
 /**
  * Execute the console command.
  *
  * @param ManagerRegistry $registry
  */
 public function fire(ManagerRegistry $registry)
 {
     $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();
     foreach ($names as $name) {
         $em = $registry->getManager($name);
         $cache = $em->getConfiguration()->getQueryCacheImpl();
         if (!$cache) {
             throw new InvalidArgumentException('No Result cache driver is configured on given EntityManager.');
         }
         if ($cache instanceof ApcCache) {
             throw new LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
         }
         if ($cache instanceof XcacheCache) {
             throw new LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
         }
         $this->message('Clearing result cache entries for <info>' . $name . '</info> entity manager');
         $result = $cache->deleteAll();
         $message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
         if ($this->option('flush')) {
             $result = $cache->flushAll();
             $message = $result ? 'Successfully flushed cache entries.' : $message;
         }
         $this->info($message);
     }
 }
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ($event->getCommand() instanceof UpdateSchemaDoctrineCommand) {
         $output = $event->getOutput();
         $input = $event->getInput();
         if ($input->getOption('force')) {
             $result = $this->fulltextIndexManager->createIndexes();
             $output->writeln('Schema update and create index completed.');
             if ($result) {
                 $output->writeln('Indexes were created.');
             }
         }
     }
     if ($event->getCommand() instanceof UpdateSchemaCommand) {
         $entities = $this->registry->getRepository('OroSearchBundle:UpdateEntity')->findAll();
         if (count($entities)) {
             $em = $this->registry->getManager();
             foreach ($entities as $entity) {
                 $job = new Job(ReindexCommand::COMMAND_NAME, ['class' => $entity->getEntity()]);
                 $em->persist($job);
                 $em->remove($entity);
             }
             $em->flush($job);
         }
     }
 }
 /**
  * @param EmailCampaign $emailCampaign
  * @param Campaign $campaign
  * @param bool $expected
  * @dataProvider staticCampaignProvider
  */
 public function testIsApplicableOnEmailCampaign($emailCampaign, $campaign, $expected)
 {
     $this->entityRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($campaign));
     $this->managerRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager));
     $this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->entityRepository));
     $this->assertEquals($expected, $this->placeholderFilter->isApplicableOnEmailCampaign($emailCampaign));
 }
Example #30
0
 /**
  * @param int $segmentId
  *
  * @return MarketingList
  */
 public function getMarketingListBySegment($segmentId)
 {
     if (empty($this->marketingListsBySegment[$segmentId])) {
         $this->marketingListsBySegment[$segmentId] = $this->managerRegistry->getManagerForClass(self::MARKETING_LIST)->getRepository(self::MARKETING_LIST)->findOneBy(['segment' => $segmentId]);
     }
     return $this->marketingListsBySegment[$segmentId];
 }