Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $cronLog = new CronLog();
     $cronLog->setStartAt(new DateTime());
     $cronLog->setDescription('Process SCA log files');
     $cronLog->setScript('spm:process-sca-logs');
     $this->_em = $this->getContainer()->get('doctrine')->getManager();
     /**
      * @var ImapService $imap
      */
     $imap = $this->getContainer()->get('app_core.imap');
     $messages = $imap->getMessages('Inbox/Sportmaster/SCA', null, ImapService::F_UNFLAGGED);
     foreach ($messages as $message) {
         if (!$message->getAttachments()) {
             continue;
         }
         foreach ($message->getAttachments() as $attachment) {
             $savePath = UploadAbstract::getUploadDir('sportmaster');
             if (($savedFile = $attachment->saveToDirectory($savePath)) == true) {
                 $importService = new ImportSpmInterfaceLog($savePath . DIRECTORY_SEPARATOR . $attachment->getFileName(), $this->getContainer());
                 $importService->parse();
             }
         }
         $message->setFlag(ImapService::F_FLAGGED);
         $message->setFlag(ImapService::F_SEEN);
     }
     $cronLog->setEndAt(new DateTime());
     $this->_em->persist($cronLog);
     $this->_em->flush();
     $this->_em->clear();
     $output->writeln('Completed');
 }
Пример #2
0
 public function spmInterfaceLogAction(Request $request)
 {
     $form = $this->createForm(new Upload(Upload::TYPE_CSV));
     $form->handleRequest($request);
     if ($request->isMethod('POST')) {
         if ($form->isValid()) {
             $file = $form->get('file')->getData();
             $uploader = new Uploader($file, SportmasterBundle::getBundleName());
             try {
                 $filePath = $uploader->upload();
                 $importService = new ImportSpmInterfaceLog($filePath, $this->container);
                 $importService->parse();
                 $request->getSession()->getFlashBag()->add('notice', $importService->getMessageService()->dumpAsHtml());
             } catch (\Exception $e) {
                 $request->getSession()->getFlashBag()->add('error', $e->getMessage());
             }
         }
     }
     //log grid
     $grid = $this->get('app_core.importLogGrid')->getImportGrid(ImportSpmInterfaceLog::$importName);
     return $this->render('SportmasterBundle:Import:ref.html.twig', ['header' => 'Import SpmInterfaceLog', 'form' => $form->createView(), 'grid' => $grid]);
 }