コード例 #1
0
 /**
  * Prepare facets for each pushed node
  *
  * @param $node
  */
 public function prepareFacet($node)
 {
     $facet = new Facet();
     $agencyId = $node->getAuthor()->getAgencyId();
     $agency = $this->dm->getRepository('BpiApiBundle:Aggregate\\Agency')->findOneBy(array('public_id' => $agencyId->id()));
     $categoryId = $node->getCategory()->getId();
     $category = $this->dm->getRepository('BpiApiBundle:Entity\\Category')->findOneBy(array('_id' => $categoryId))->getCategory();
     $audienceId = $node->getAudience()->getId();
     $audience = $this->dm->getRepository('BpiApiBundle:Entity\\Audience')->findOneBy(array('_id' => $audienceId))->getAudience();
     $author = $node->getAuthor()->getFullName();
     $facets = array('author' => array($author), 'agency_id' => array($agencyId->id()), 'agency_internal' => array($agency->getInternal()), 'category' => array($category), 'audience' => array($audience));
     $setFacets = new \stdClass();
     array_walk($facets, function ($facet, $key) use(&$setFacets) {
         if (!empty($facet)) {
             $setFacets->{$key} = $facet[0];
         }
     });
     $facet->setNodeId($node->getId());
     $facet->setFacetData($setFacets);
     $this->dm->persist($facet);
     $this->dm->flush();
 }
コード例 #2
0
 public function up(Database $db)
 {
     $batchSize = 50;
     $i = 0;
     $dm = $this->container->get('doctrine.odm.mongodb.document_manager');
     $nodeRepository = $dm->getRepository('BpiApiBundle:Aggregate\\Node');
     $nodes = $nodeRepository->findAll();
     foreach ($nodes as $node) {
         $facet = new Facet();
         $agencyId = $node->getAuthor()->getAgencyId();
         $agency = $dm->getRepository('BpiApiBundle:Aggregate\\Agency')->findOneBy(array('public_id' => $agencyId->id(), 'deleted' => false));
         $categoryId = $node->getCategory()->getId();
         $category = $dm->getRepository('BpiApiBundle:Entity\\Category')->findOneBy(array('_id' => $categoryId))->getCategory();
         $audienceId = $node->getAudience()->getId();
         $audience = $dm->getRepository('BpiApiBundle:Entity\\Audience')->findOneBy(array('_id' => $audienceId))->getAudience();
         $author = $node->getAuthor()->getFullName();
         if (null === $agency || null === $category || null === $audience) {
             continue;
         }
         $facets = array('author' => array($author), 'agency_id' => array($agencyId->id()), 'agency_internal' => array($agency->getInternal()), 'category' => array($category), 'audience' => array($audience));
         $setFacets = new \stdClass();
         array_walk($facets, function ($facet, $key) use(&$setFacets) {
             if (!empty($facet)) {
                 $setFacets->{$key} = $facet[0];
             }
         });
         $facet->setNodeId($node->getId());
         $facet->setFacetData($setFacets);
         $dm->persist($facet);
         if ($i % $batchSize === 0) {
             $dm->flush();
             $dm->clear();
         }
         ++$i;
     }
     $dm->flush();
 }