protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('--- vidal:parser started');
        $emDrug = $this->getContainer()->get('doctrine')->getManager('drug');
        $em = $this->getContainer()->get('doctrine')->getManager();
        # очищаем таблицы кеширования
        $em->createQuery('
			DELETE FROM VidalMainBundle:MarketCache mc
		')->execute();
        $em->createQuery('
			DELETE FROM VidalMainBundle:MarketDrug md
		')->execute();
        # Загружаем файлы XML в Кеш
        $this->uploadFiles();
        $query = $emDrug->createQuery('SELECT COUNT(d.DocumentID) FROM VidalDrugBundle:Document d');
        $count = $query->getSingleScalarResult();
        for ($i = 0; $i < $count; $i += 100) {
            # Вначале пройдемся по документам ( их тупо меньше )
            # $drugs = $emDrug->getRepository('VidalDrugBundle:Document')->findAll();
            $drugs = $emDrug->createQuery('SELECT d FROM VidalDrugBundle:Document d ')->setMaxResults(100)->setFirstResult($i)->getResult();
            foreach ($drugs as $drug) {
                # Это надолго
                # Добавлем маркет контроллер
                $marketCache = new MarketCache();
                $marketCache->setTarget($drug->getDocumentID());
                $marketCache->setDocument(true);
                $em->persist($marketCache);
                $em->flush($marketCache);
                $em->refresh($marketCache);
                # Удаляем из имени всякую хрень
                $RusName = $drug->getRusName();
                $p = array('/<sup>(.*?)<\\/sup>/i', '/<sub>(.*?)<\\/sub>/i');
                $r = array('', '');
                $name = preg_replace($p, $r, $RusName);
                $first = mb_substr($name, 0, 2);
                //первая буква
                $last = mb_substr($name, 2);
                //все кроме первой буквы
                $last = mb_strtolower($last, 'UTF-8');
                $name = $first . $last;
                $output->writeln('<info>' . $name . '</info>');
                # Ищем в первом магазине и добавляем оттуда лекарства
                $array = $this->findShop_1($name);
                $c1 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('eapteka');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $em->flush();
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                }
                # Ищем во втором магазине и добавляем оттуда лекартсва
                $array = $this->findShop_2($name);
                $c2 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setManufacturer($pr['manufacturer']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('piluli');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $em->flush();
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                }
                # Ищем в третьем магазине и добавляем оттуда лекартсва
                $array = $this->findShop_3($name);
                $c3 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setManufacturer($pr['manufacturer']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('zdravzona');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                    $em->flush();
                }
                $output->writeln('<error>' . $c1 . ' - ' . $c2 . ' - ' . $c3 . '</error>');
            }
        }
        $output->writeln('+++ vidal:parser completed!');
    }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $val = $input->getOption('val');
     $output->writeln('--- vidal:parser started');
     # Подключаем пилюли URL
     include 'piluliCodeUrl.php';
     $this->arUrl = $mass;
     $emDrug = $this->getContainer()->get('doctrine')->getManager('drug');
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em2 = $this->getContainer()->get('doctrine')->getManager('drug');
     //
     //        $em->createQuery('
     //			DELETE FROM VidalMainBundle:MarketDrug md
     //		')->execute();
     # Загружаем файлы XML в Кеш
     $this->uploadFiles();
     //        # Ищем в первом магазине и добавляем оттуда лекарства
     if ($val == 1) {
         $em->createQuery('
             DELETE FROM VidalMainBundle:MarketDrug md
         ')->execute();
         $array = $this->findShop_1('');
         $c1 = count($array);
         $output->writeln('<error> Count => ' . $c1 . '</error>');
         $i = 0;
         foreach ($array as $pr) {
             $i++;
             $product = new MarketDrug();
             $product->setCode($pr['code']);
             $product->setTitle($pr['title']);
             $product->setPrice($pr['price']);
             $product->setManufacturer($pr['manufacturer']);
             $product->setUrl($pr['url']);
             $product->setGroupApt('eapteka');
             $em->persist($product);
             $em->flush($product);
             $output->writeln('<comment>' . $i . ' : ' . $product->getTitle() . '</comment>');
         }
     }
     # Ищем во втором магазине и добавляем оттуда лекартсва
     if ($val == 2) {
         $array = $this->findShop_2('');
         $c2 = count($array);
         $output->writeln('<error> Count => ' . $c2 . '</error>');
         $i = 0;
         foreach ($array as $pr) {
             $i++;
             $product = new MarketDrug();
             $product->setCode($pr['code']);
             $product->setTitle($pr['title']);
             $product->setPrice($pr['price']);
             $product->setManufacturer($pr['manufacturer']);
             $product->setUrl($pr['url']);
             $product->setGroupApt('piluli');
             $em->persist($product);
             $em->flush($product);
             $output->writeln('<comment>' . $i . ' : ' . $product->getTitle() . '</comment>');
         }
     }
     if ($val == 3) {
         # Ищем в третьем магазине и добавляем оттуда лекартсва
         $array = $this->findShop_3('');
         $c3 = count($array);
         $output->writeln('<error> Count => ' . $c3 . '</error>');
         $i = 0;
         foreach ($array as $pr) {
             $i++;
             $product = new MarketDrug();
             $product->setCode($pr['code']);
             $product->setTitle($pr['title']);
             $product->setPrice($pr['price']);
             $product->setManufacturer($pr['manufacturer']);
             $product->setUrl($pr['url']);
             $product->setGroupApt('zdravzona');
             $em->persist($product);
             $em->flush($product);
             $output->writeln('<comment>' . $i . ' : ' . $product->getTitle() . '</comment>');
         }
     }
     if ($val == 4) {
         # Ищем в третьем магазине и добавляем оттуда лекартсва
         $array = $this->findShop_4('');
         $c3 = count($array);
         $output->writeln('<error> Count => ' . $c3 . '</error>');
         $i = 0;
         foreach ($array as $pr) {
             //                print_r($pr);
             $i++;
             //                if ($i > 10) exit;
             $product = new MarketDrug();
             $product->setCode($pr['code']);
             $product->setTitle($pr['title']);
             $product->setPrice($pr['price']);
             $product->setManufacturer($pr['manufacturer']);
             $product->setUrl($pr['url']);
             $product->setGroupApt('wer');
             $em->persist($product);
             $em->flush($product);
             $output->writeln('<comment>' . $i . ' : ' . $product->getTitle() . '</comment>');
         }
     }
     if ($val == 5) {
         # Ищем в третьем магазине и добавляем оттуда лекартсва
         $i = 0;
         $docs = $em2->getRepository('VidalDrugBundle:Document')->findAll();
         foreach ($docs as $val) {
             $title = str_replace("'", '', $val->getRusName());
             $title = str_replace("<SUP>", '', $title);
             $title = str_replace("</SUP>", '', $title);
             $title = str_replace("&reg;", '', $title);
             $t = $em->getRepository('VidalMainBundle:MarketDrug')->find($title);
             $d = count($t);
             $i += $d > 1 ? 1 : 0;
             $output->writeln('<comment>' . $title . ' : ' . $d . '</comment>');
         }
         $output->writeln('<comment> : ' . $i . '</comment>');
     }
     //        if ($val == 6){
     //            $em = $this->getContainer()->get('doctrine')->getManager();
     //            $em2 = $this->getContainer()->get('doctrine')->getManager('drug');
     //            $file = '/var/www/file.txt';
     //            $docs = $em2->getRepository('VidalDrugBundle:Document')->fondOneById()
     //        }
     $output->writeln('+++ vidal:parser completed!');
 }