/**
  */
 protected function setUpDoctrine()
 {
     static::bootKernel();
     $this->container = static::$kernel->getContainer();
     $this->doctrine = $this->createDoctrineRegistry();
     $this->em = $this->doctrine->getManager();
     $this->loader = new Loader();
 }
 /**
  * Checks whether the given namespace is registered in the Doctrine
  *
  * @param string $namespace
  * @return bool
  */
 public function isKnownEntityClassNamespace($namespace)
 {
     foreach (array_keys($this->doctrine->getManagers()) as $name) {
         $namespaces = $this->doctrine->getManager($name)->getConfiguration()->getEntityNamespaces();
         if (in_array($namespace, $namespaces, true)) {
             return true;
         }
     }
     return false;
 }
Exemple #3
0
 public function createLike(Post $post, $score)
 {
     // Récupère l'utilisateur courant
     $user = $this->tokenStorage->getToken()->getUser();
     // Création du postlike
     $postLike = new PostLike();
     $postLike->setScore($score);
     $postLike->setTarget($post);
     $postLike->setUser($user);
     // Sauvegarde
     $em = $this->doctrine->getManager();
     $em->persist($postLike);
     $em->flush($postLike);
 }
Exemple #4
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();
 }
 /**
  * @return ObjectManager
  */
 protected function getManager()
 {
     if (!$this->manager) {
         $this->manager = $this->doctrine->getManager();
     }
     return $this->manager;
 }
 /**
  * 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;
 }
Exemple #7
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"));
 }
 /**
  * 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 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;
 }
Exemple #10
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;
 }
 /**
  * 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;
 }
 /**
  * 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;
                 }
             }
         }
     }
 }
Exemple #13
0
 public function send()
 {
     if (!$this->assertTransport()) {
         return;
     }
     $marketingList = $this->emailCampaign->getMarketingList();
     if (is_null($marketingList)) {
         return;
     }
     $iterator = $this->getIterator();
     if (is_null($iterator)) {
         return;
     }
     /** @var EntityManager $manager */
     $manager = $this->registry->getManager();
     $emailFields = $this->contactInformationFieldsProvider->getMarketingListTypedFields($marketingList, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL);
     foreach ($iterator as $entity) {
         $to = $this->contactInformationFieldsProvider->getTypedFieldsValues($emailFields, $entity);
         $to = array_unique($to);
         try {
             $manager->beginTransaction();
             // Do actual send
             $this->transport->send($this->emailCampaign, $entity, [$this->getSenderEmail() => $this->getSenderName()], $to);
             $statisticsRecord = $this->statisticsConnector->getStatisticsRecord($this->emailCampaign, $entity);
             // Mark marketing list item as contacted
             $statisticsRecord->getMarketingListItem()->contact();
             $manager->flush($statisticsRecord);
             $manager->commit();
         } catch (\Exception $e) {
             $manager->rollback();
             if ($this->logger) {
                 $this->logger->error(sprintf('Email sending to "%s" failed.', implode(', ', $to)), ['exception' => $e]);
             }
         }
     }
     $this->emailCampaign->setSent(true);
     $manager->persist($this->emailCampaign);
     $manager->flush();
 }
 public function __construct(ManagerRegistry $doctrine, TwigEngine $twig, $template_class)
 {
     $this->dm = $doctrine->getManager();
     $this->twig = $twig;
     $this->template_class = $template_class;
 }
Exemple #15
0
 /**
  * Initialize environment
  */
 protected function initialize()
 {
     $this->entityManager = $this->managerRegistry->getManager();
 }
Exemple #16
0
 /**
  * @return ChannelObjectBuilder
  */
 public function createBuilder()
 {
     return new ChannelObjectBuilder($this->registry->getManager(), $this->settingsProvider, new Channel());
 }
 /**
  * {@inheritdoc}
  */
 public function collect(RequestObject $requestObject, array $parameters = [])
 {
     $manager = $this->doctrine->getManager();
     $manager->persist($requestObject);
     $manager->flush();
 }
 /**
  * Returns the File repository.
  *
  * @return \Doctrine\Common\Persistence\ObjectManager
  */
 protected function getManager()
 {
     return $this->registry->getManager($this->managerName);
 }