protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getArgument('type') == 'book') { $html = file_get_contents("http://www.medknigaservis.ru/ervr/medknigaservis.xml"); $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $html = iconv("windows-1251", "utf-8", $html); $saw = new \nokogiri($html); $date = new \DateTime(); $xml = $saw->get('offer')->toArray(); /** * Делаем поле enabled для всех книжек от этого издательства = 0 */ // $mu = $this // ->getContainer() // ->get('doctrine') // ->getEntityManager() // ->getRepository('EvrikaMainBundle:marketUser') // ->findOneById(1); # $mu это MarketUser $mu = 1; $result = $this->getContainer()->get('doctrine')->getEntityManager()->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu')->setParameter('mu', $mu)->execute(); if ($result !== true) { $output->writeln('ERROR : UPDATE enabled = false is Error'); } for ($i = 0; $i < 3500; $i++) { if (isset($xml[$i])) { if (isset($xml[$i]['categoryid']['0']['#text']['0'])) { $category = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketCategory')->findOneByOfferId($xml[$i]['categoryid']['0']['#text']['0']); } else { $category = NULL; } $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : ''; $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : ''; $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : ''; $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : ''; $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : ''; $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : ''; $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : ''; $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : ''; $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : ''; $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : ''; $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : ''; $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : ''; $marketUser = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketUser')->findOneByid(1); $book = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:Market')->findOneByOfferId($offerid); $action = 'UPDATE'; $em = $this->getContainer()->get('doctrine')->getEntityManager(); if ($book == NULL) { $action = 'INSERT'; $book = new Market(); $book->setOfferId($offerid); $book->setType('book'); $book->setName($name); $book->setCategory($category); $book->setAuthor($author); $book->setPublicHouse($publisher); $book->setYear($year); $book->setIsbn($isbn); $book->setCountList($page_extent); $book->setDescription($description); $book->setLink($url); $book->setImageURL($picture); $book->setCurrency($currency); $book->setCountList($page_extent); $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); $book->setMarketUser($marketUser); $em->persist($book); } else { $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); } $book->setEnabled(1); $em->flush(); $output->writeln($offerid . ' : ' . $action . ' ----------- OK'); } else { $output->writeln('ERROR : NOT FOUND'); } } $result = $this->getContainer()->get('doctrine')->getEntityManager()->createQuery('DELETE FROM EvrikaMainBundle:Market m WHERE m.enabled = false AND m.marketUser = :mu')->setParameter('mu', $mu)->execute(); if ($result !== true) { $output->writeln('ERROR : DELETE old items'); } } else { $output->writeln('ERROR : INVALID ARGUMENT'); } }
/** * @Route("/blooo" , name="blooo" ) */ public function testAtmosferaAction() { #https://downloader.disk.yandex.ru/disk/49373d95452e82cf369769119e6ff2b8/52cfb5a7/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml $html = file_get_contents("https://downloader.disk.yandex.ru/disk/ba8c59411011b99303d5473566ce569c/52cffe1f/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml&fsize=76244"); #$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $html = iconv("windows-1251", "utf-8", $html); $saw = new \nokogiri($html); #$date = date('Y-m-d H:i:s', time()) ; $date = new \DateTime(); $xml = $saw->get('offer')->toArray(); // echo '<pre>'; // print_r($xml); // echo '</pre>'; // exit; # $mu это MarketUser $mu = 3; // $result = $this // ->getContainer() // ->get('doctrine') // ->getManager() // ->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu') // ->setParameter('mu', $mu) // ->execute(); $result = $this->getDoctrine()->getManager()->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu')->setParameter('mu', $mu)->execute(); if ($result !== true) { #$output->writeln('ERROR : UPDATE enabled = false is Error'); } $marketUser = $this->getDoctrine()->getRepository('EvrikaMainBundle:MarketUser')->findOneById(3); for ($i = 0; $i < 3000; $i++) { if (isset($xml[$i])) { if (isset($xml[$i]['categoryid']['0']['#text']['0'])) { // $category = $this // ->getContainer() // ->get('doctrine') // ->getManager() // ->getRepository('EvrikaMainBundle:MarketCategory') // ->findOneById(1); $offerCategory = $xml[$i]['categoryid']['0']['#text']['0']; $category = $this->getDoctrine()->getRepository('EvrikaMainBundle:MarketCategory')->findOneBy(array('offerId' => $offerCategory, 'marketUser' => $marketUser)); } else { $category = NULL; } $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : ''; $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : ''; $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : ''; $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : ''; $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : ''; $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : ''; $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : ''; $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : ''; $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : ''; #@todo Надо бы сделать человечно #$tableOfContents = (isset($xml[$i]['table_of_contents']) ? $this->arrToStr($xml[$i]['table_of_contents']) : ''); #$description = $description.' <br /> '.$tableOfContents; $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : ''; $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : ''; $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : ''; $em = $this->getDoctrine()->getManager(); $book = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:Market')->findOneBy(array('offerId' => $offerid, 'marketUser' => $marketUser)); if ($book == NULL) { $action = 'INSERT'; $book = new Market(); $book->setOfferid($offerid); $book->setType('book'); $book->setName($name); $book->setCategory($category); $book->setAuthor($author); $book->setPublicHouse($publisher); $book->setYear($year); $book->setIsbn($isbn); $book->setCountList($page_extent); $book->setDescription($description); $book->setLink($url); $book->setImageURL($picture); $book->setCurrency($currency); $book->setCountList($page_extent); $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); $book->setMarketUser($marketUser); $em->persist($book); } else { $action = 'UPDATE'; $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); } $book->setEnabled(1); $em->flush(); # it is debug code echo $action; echo '<br />'; echo $book->getOfferId(); echo '<br />'; echo $book->getName(); echo '<br />'; echo $book->getAuthor(); echo '<br />'; echo $book->getCena(); echo '<br />'; echo $book->getPublicHouse(); echo '<br />'; echo $book->getImageURL(); echo '<br />'; echo $book->getCategory()->getName(); echo '<hr />'; #$output->writeln($offerid.' : '.$action.' ----------- OK'); } else { #$output->writeln('ERROR : NOT FOUND'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getArgument('type') == 'book') { $html = file_get_contents("https://downloader.disk.yandex.ru/disk/49373d95452e82cf369769119e6ff2b8/52cfb5a7/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml"); #$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $html = iconv("windows-1251", "utf-8", $html); $saw = new \nokogiri($html); $date = date('Y-m-d H:i:s', time()); $xml = $saw->get('offer')->toArray(); for ($i = 0; $i < 3000; $i++) { if (isset($xml[$i])) { if (isset($xml[$i]['categoryid']['0']['#text']['0'])) { $category = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketCategory')->findOneById(1); } else { $category = NULL; } $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : ''; $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : ''; $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : ''; $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : ''; $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : ''; $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : ''; $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : ''; $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : ''; $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : ''; $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : ''; $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : ''; $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : ''; $book = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:Market')->findOneByOfferid($offerid); $em = $this->getContainer()->get('doctrine')->getEntityManager(); if ($book == NULL) { $action = 'INSERT'; $book = new Market(); $book->setOfferid($offerid); $book->setType('book'); $book->setName($name); $book->setCategory($category); $book->setAuthor($author); $book->setPublicHouse($publisher); $book->setYear($year); $book->setIsbn($isbn); $book->setCountList($page_extent); $book->setDescription($description); $book->setLink($url); $book->setImageURL($picture); $book->setCurrency($currency); $book->setCountList($page_extent); $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); #$em->persist($book); } else { $action = 'UPDATE'; $book->setCena($cena); $book->setEnabled('true'); $book->setUpdated($date); } $em->flush(); $output->writeln($offerid . ' : ' . $action . ' ----------- OK'); } else { $output->writeln('ERROR : NOT FOUND'); } } } else { $output->writeln('ERROR : INVALID ARGUMENT'); } }