/**
  */
 public function step2Action(Request $request)
 {
     $adData = $request->getSession()->get('ad');
     $em = $this->getDoctrine()->getManager();
     $vertical = $em->getRepository('Entity:Vertical')->find($adData['vertical_id']);
     $category1 = $em->getRepository('Entity:Category1')->find($adData['category1_id']);
     $category2 = $em->getRepository('Entity:Category2')->find($adData['category2_id']);
     $category3 = $em->getRepository('Entity:Category3')->find($adData['category3_id']);
     $className = '\\Entity\\' . $vertical->getAdClass();
     $formName = 'Rmc\\' . $vertical->getAdClass() . '\\PostBundle\\Form\\' . $vertical->getAdClass() . 'PostType';
     $obj = new $className();
     $formType = new $formName();
     if ($vertical->getAdClass() != 'Ad') {
         $adObj = new Ad();
         $adObj->setVertical($vertical);
         $adObj->setCategory1($category1);
         $adObj->setCategory2($category2);
         $adObj->setCategory3($category3);
         $adObj->setStatus('A');
         $obj->setAd($adObj);
     } else {
         $obj->setVertical($vertical);
         $obj->setCategory1($category1);
         $obj->setCategory2($category2);
         $obj->setCategory3($category3);
     }
     // Electronics
     //$obj      = new Ad();
     //$formType = new AdPostType();
     // Car
     //$obj      = new Car();
     //$formType = new CarPostType();
     $form = $this->createForm($formType, $obj);
     $form->add('save', SubmitType::class, array('label' => 'Save'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em->persist($obj);
         $em->flush();
         $solrIndexService = AdSolrIndexServiceFactory::getIndexManager($this->container, $obj->getAd()->getVertical()->getCode());
         $solrIndexService->updateSolrIndex($obj);
         $request->getSession()->getFlashBag()->set('success', 'Your advert has been successfully placed');
         return $this->redirectToRoute('rmc_core_base_homepage');
     }
     return $this->render('RmcCoreAdPostBundle:Default:step2.html.twig', array('form' => $form->createView()));
 }
 /**
  * update solr index by criteria
  *
  * @param array  $searchParam search params
  * @param object $output      output object
  *
  * @return void
  */
 public function updateSolrIndexByCriteria($searchParam, $output)
 {
     $sqlSearchService = $this->getContainer()->get('rmc_core.ad_search_manager')->getSqlSearchService();
     $query = $sqlSearchService->getQueryByCriteria($searchParam, NULL, false);
     $ads = $query->getResult();
     foreach ($ads as $ad) {
         $obj = $ad->getVerticalObject();
         if (isset($obj)) {
             $solrIndexService = AdSolrIndexServiceFactory::getIndexManager($this->getContainer(), $ad->getVertical()->getCode());
             $documents[] = $solrIndexService->updateSolrIndex($ad->getVerticalObject(), true);
         }
         $output->writeln('<fg=green>Solr index generated for ad Id: ' . $ad->getId() . '</fg=green>');
     }
     /* Batch commit for fater index */
     $solrRegistry = $this->getContainer()->get('solarium.client_registry');
     $masterClient = $solrRegistry->getClient('rmcmaster');
     $update = $masterClient->createUpdate();
     $update->addDocuments($documents);
     $update->addCommit();
     $result = $masterClient->update($update);
     echo "\n";
     echo 'Memory Allocated: ' . memory_get_peak_usage(true) / 1024 / 1024 . ' MB';
     echo "\n";
 }