/**
  * 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 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];
 }
 /**
  * {@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;
 }
 /**
  * @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;
 }
 /**
  * @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);
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Syncs email bodies
  *
  * @param int $maxExecTimeInMin
  * @param int $batchSize
  */
 public function sync($maxExecTimeInMin = -1, $batchSize = 10)
 {
     $repo = $this->doctrine->getRepository('OroEmailBundle:Email');
     $maxExecTimeout = $maxExecTimeInMin > 0 ? new \DateInterval('PT' . $maxExecTimeInMin . 'M') : false;
     $startTime = new \DateTime('now', new \DateTimeZone('UTC'));
     while (true) {
         if ($maxExecTimeout !== false) {
             $date = new \DateTime('now', new \DateTimeZone('UTC'));
             if ($date->sub($maxExecTimeout) >= $startTime) {
                 $this->logger->notice('Exit because allocated time frame elapsed.');
                 break;
             }
         }
         $emails = $repo->getEmailsWithoutBody($batchSize);
         if (count($emails) === 0) {
             $this->logger->notice('All emails was processed');
             break;
         }
         $batchStartTime = new \DateTime('now', new \DateTimeZone('UTC'));
         /** @var Email $email */
         foreach ($emails as $email) {
             try {
                 $this->syncOneEmailBody($email);
                 $this->logger->notice(sprintf('The "%s" (ID: %d) email body was synced.', $email->getSubject(), $email->getId()));
             } catch (\Exception $e) {
                 // in case of exception, we should save state that email body was synced.
                 $this->getManager()->persist($email);
                 continue;
             }
         }
         $this->getManager()->flush();
         $this->getManager()->clear();
         $currentTime = new \DateTime('now', new \DateTimeZone('UTC'));
         $diff = $currentTime->diff($batchStartTime);
         $this->logger->info(sprintf('Batch save time: %s.', $diff->format('%i minutes %s seconds')));
     }
 }
Exemple #8
0
 /**
  * @return EntityRepository
  */
 protected function getJobInstanceRepository()
 {
     return $this->managerRegistry->getRepository('AkeneoBatchBundle:JobInstance');
 }
 /**
  * Get the Pages Repository
  *
  * @return PageRepository
  */
 private function getPageRepository()
 {
     return $this->em->getRepository('KRSolutionsKRCMSBundle:Page');
 }
Exemple #10
0
 /**
  * Renvoie le nombre de "j'aime pas"
  * @param  Post   $post
  * @return int
  */
 public function getDislikes(Post $post)
 {
     $repository = $this->doctrine->getRepository('LpdwBundle:PostLike');
     return $repository->getCountLikes($post, -1);
 }