Beispiel #1
0
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $session = new Session();
     if ($session->isStarted() == true) {
         $session->start();
     }
     $products = $this->getDoctrine()->getRepository('AppBundle:Product')->findAll();
     $prodId = $request->request->get('prod', 'noone');
     $inBasket[] = "Empty Basket, please select a product";
     if ($prodId != 'noone') {
         $product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($prodId);
         $session->set($product->getId(), $product->getName());
         $log = new Log();
         $log->setProdName($product->getName());
         $log->setDate(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($log);
         $em->flush();
         echo "Dev : Log saved to database. Product name - " . $product->getName() . " Current time - " . $log->getDate()->format('H:i:s \\O\\n Y-m-d');
         $inBasket = $session->all();
     } else {
         if ($session->count() != 0) {
             $inBasket = $session->all();
             echo "Please select a Product before submitting !!!";
         }
     }
     return $this->render('default/index.html.twig', ['products' => $products, 'basketProds' => $inBasket]);
 }
Beispiel #2
0
 /**
  * Parses one single log line
  *
  * @param string $line
  * @return Log
  * @throws FormatException
  */
 public function parseLog($line)
 {
     if (!preg_match($this->pcreFormat, $line, $matches)) {
         throw new FormatException($line);
     }
     $entry = new Log();
     $propertyAccessor = new PropertyAccessor();
     foreach (array_filter(array_keys($matches), 'is_string') as $key) {
         if ('time' === $key && true !== ($stamp = strtotime($matches[$key]))) {
             $entry->setStamp($stamp);
         }
         $propertyAccessor->setValue($entry, $key, $matches[$key]);
     }
     return $entry;
 }
Beispiel #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     set_time_limit(0);
     ini_set("memory_limit", "-1");
     $container = $this->getContainer();
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->createQuery('DELETE FROM AppBundle:Log l')->execute();
     // Удаляем старые логи
     $log = new Log();
     $log->setTitle('Начало синхронизации');
     $em->persist($log);
     $em->flush($log);
     $files = scandir($container->get('kernel')->getRootDir() . '/../web/upload/files');
     foreach ($files as $f) {
         /**
          * Проверяем этот файл горящих предложений или нет
          */
         $p = explode('_', $f);
         if ($p[0] === 'HOT') {
             $hot = $p[1];
         } else {
             $hot = false;
             if (is_numeric($p[0])) {
                 $sale = $p[0];
             } else {
                 $sale = 0;
             }
         }
         $path = $container->get('kernel')->getRootDir() . '/../web/upload/files/' . $f;
         $type = 0;
         if (strripos($f, 'Gema') !== false) {
             $type = 1;
         }
         if (strripos($f, 'VeraOlimp') !== false) {
             $type = 2;
         }
         if (strripos($f, 'Rosvero') !== false) {
             $type = 3;
         }
         if (strripos($f, 'Gallery_3x6') !== false) {
             $type = 4;
         }
         if (strripos($f, 'Gallery_scroll') !== false) {
             $type = 5;
         }
         if (strripos($f, 'Gallery_roller') !== false) {
             $type = 6;
         }
         //            if ($type != 0){
         //                $em->createQuery('DELETE AppBundle:Banner b WHERE b.company_id = '.$type)->execute(); // Удаляем старые логи
         //            }
         if ($type != 0) {
             $log = new Log();
             $log->setTitle('Синхронизация ' . $f);
             $em->persist($log);
             $em->flush($log);
         }
         if ($type == 1) {
             $log = new Log();
             $log->setTitle('Опа');
             $em->persist($log);
             $em->flush($log);
             $parser = new GemaParser($em, $container, $path);
             try {
                 $parser->parserGema1Action($hot);
             } catch (\Exception $e) {
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle($f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage());
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type == 2) {
             $parser = new VeraParser($em, $container, $path);
             try {
                 $parser->parserVera1Action($hot);
                 $parser->parserVera2Action($hot);
                 $parser->parserVera3Action($hot);
                 $parser->parserVera4Action($hot);
                 $parser->parserVera5Action($hot);
                 $parser->parserVera6Action($hot);
                 $parser->parseImageAction();
                 //                    $output->write($sale);
                 //                    if ($sale != 0){
                 //                        $company = $em->getRepository('AppBundle:Company')->findOneByTitle('Вера Олимп');
                 //                        if ($company == null){
                 //                            $company = new Company();
                 //                            $company->setTitle('Вера Олимп');
                 //                            $em->persist($company);
                 //                            $em->flush($company);
                 //                            $em->refresh($company);
                 //                        }
                 //                        $city = $em->getRepository('AppBundle:City')->findOneById(1);
                 //                        for ($i = 1; $i <= 12 ; $i ++){
                 //                            $date = new \DateTime('2015-'.$i.'-01 00:00:00');
                 //                            $month = $em->getRepository('AppBundle:Sale')->findOneBy(array('date' => $date, 'company' => $company, 'city' => $city));
                 //                            if (!$month){
                 //
                 //                                $month = new Sale();
                 //                                $month->setCity($city);
                 //                                $month->setDate($date);
                 //                                $month->setCompany($company);
                 //                                $month->setPercent($sale);
                 //                                $em->persist($month);
                 //                                $em->flush($month);
                 //                            }
                 //                        }
                 //                    }
             } catch (\Exception $e) {
                 echo $f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage();
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle('<span class="text-danger">' . $f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage() . '</span>');
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type == 3) {
             $parser = new RosveroParser($em, $container, $path);
             try {
                 $parser->parserRasvero1Action($hot);
                 //                    if ($sale != 0){
                 //                        $company = $em->getRepository('AppBundle:Company')->findOneByTitle('Расверо');
                 //                        if ($company == null){
                 //                            $company = new Company();
                 //                            $company->setTitle('Расверо');
                 //                            $em->persist($company);
                 //                            $em->flush($company);
                 //                            $em->refresh($company);
                 //                        }
                 //                        $city = $em->getRepository('AppBundle:City')->findOneById(1);
                 //                        for ($i = 1; $i <= 12 ; $i ++){
                 //                            $date = new \DateTime('2015-'.$i.'-01 00:00:00');
                 //                            $month = $em->getRepository('AppBundle:Sale')->findOneBy(array('date' => $date, 'company' => $company, 'city' => $city));
                 //                            if (!$month){
                 //
                 //                                $month = new Sale();
                 //                                $month->setCity($city);
                 //                                $month->setDate($date);
                 //                                $month->setCompany($company);
                 //                                $month->setPercent($sale);
                 //                                $em->persist($month);
                 //                                $em->flush($month);
                 //                            }
                 //                        }
                 //                    }
             } catch (\Exception $e) {
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle($f . ' Строка: ' . $e->getLine() . '. ' . $e->getFile() . '. ' . $e->getMessage());
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type == 4) {
             $parser = new GellaryParser($em, $container, $path);
             try {
                 $parser->parserGellary1Action($hot);
             } catch (\Exception $e) {
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle($f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage());
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type == 5) {
             $parser = new GellaryParser($em, $container, $path);
             try {
                 $parser->parserGellary2Action($hot);
             } catch (\Exception $e) {
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle($f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage());
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type == 6) {
             $parser = new GellaryParser($em, $container, $path);
             try {
                 $parser->parserGellary3Action($hot);
             } catch (\Exception $e) {
                 if ($type != 0) {
                     $log = new Log();
                     $log->setTitle($f . ' Строка: ' . $e->getLine() . '. ' . $e->getMessage());
                     $em->persist($log);
                     $em->flush($log);
                 }
             }
         }
         if ($type != 0) {
             $log = new Log();
             $log->setTitle('Синхронизация ' . $f . ' завершена');
             $em->persist($log);
             $em->flush($log);
         }
     }
 }
Beispiel #4
0
 public function generateLogForTask($task, $event)
 {
     $log = new Log();
     $log->setTask($task);
     $log->setUser($this->container->get('security.context')->getToken()->getUser());
     $log->setEvent($event);
     return $log;
 }
 public function createLogTarea($action, Tarea $tarea)
 {
     $log = new Log();
     $log->setAction($action);
     $log->setObjecttable("tarea");
     $log->setObjectid($tarea->getIdTarea());
     $user = $this->getUser();
     $log->setUser($user->getIdUsuario());
     $log->setTime(new \DateTime());
     $log->setIP($this->container->get('request')->getClientIp());
     $em = $this->getDoctrine()->getManager();
     $em->persist($log);
     $em->flush();
 }