protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getProjectApplication();
     $this->logger = $this->getLogger();
     $this->regionService = $app['region.skyforge.service'];
     $this->regionService->setRegion($input->getOption('region'));
     $this->em = $app['orm.ems'][$this->regionService->getDbConnectionNameByRegion()];
     $this->parseService = $app['parse.skyforge.service'];
     $this->parseService->setAuthData($this->regionService->getCredentials());
     $this->playerRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Player');
     $this->pantheonRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Pantheon');
     $this->communityRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Community');
     //        $lockFilePath = $app['config']['app']['path'].'/cache/curl/parse.lock';
     //        if (is_file($lockFilePath)) {
     //            throw new \RuntimeException('Another parse in progress');
     //        } else {
     //            file_put_contents($lockFilePath, getmypid());
     //        }
     if ($communityId = $input->getOption('id')) {
         $community = $this->communityRepository->find($communityId);
         $type = $this::TYPE_COMMUNITY;
         if (!$community) {
             $community = $this->pantheonRepository->find($communityId);
             $type = $this::TYPE_PANTHEON;
         }
         if (!$community) {
             $this->logger->addInfo(sprintf('Community with id %s not found in db', $communityId));
         } else {
             $this->updateCommunityMembers($community, $output, $type);
             $this->flush();
         }
     }
     if ($input->getOption('pantheons') || $input->getOption('communities')) {
         $lastId = $input->getOption('lastId');
         if ($input->getOption('pantheons')) {
             $sqlResponse = $this->em->createQuery("\n                    SELECT pt.id, count(pl.id) cnt\n                    FROM Erliz\\SkyforgeBundle\\Entity\\Pantheon pt\n                    LEFT JOIN pt.members pl\n                    group by pt.id\n                    order by cnt DESC")->getScalarResult();
             $type = $this::TYPE_PANTHEON;
             $repo = $this->pantheonRepository;
         } else {
             $sqlResponse = $this->em->createQuery("\n                    SELECT pt.id, count(pl.id) cnt\n                    FROM Erliz\\SkyforgeBundle\\Entity\\Community pt\n                    JOIN pt.members pl\n                    group by pt.id\n                    order by cnt DESC")->getScalarResult();
             $type = $this::TYPE_COMMUNITY;
             $repo = $this->communityRepository;
         }
         $communityIds = array_map('current', $sqlResponse);
         $communitiesCount = count($communityIds);
         /** @var CommunityInterface $community */
         foreach ($communityIds as $index => $communityId) {
             if ($communityId == $lastId) {
                 $lastId = false;
             }
             if ($lastId) {
                 continue;
             }
             $this->updateCommunityMembers($repo->find($communityId), $output, $type);
             $this->logger->addInfo(sprintf('Processed %s / %s', $index + 1, $communitiesCount));
             $this->flush();
         }
     }
     //        unlink($lockFilePath);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getProjectApplication();
     /** @var EntityManager $em */
     $this->em = $app['orm.em'];
     /** @var StatService $statService */
     $this->parseService = $app['parse.skyforge.service'];
     $this->parseService->setAuthData($app['config']['skyforge']['statistic']);
     $this->itemCollection = new ItemCollection($this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Item\\Item')->findAll());
     $lockFilePath = '/home/sites/erliz.ru/app/cache/curl/parse.lock';
     if (is_file($lockFilePath) && !$input->getOption('force')) {
         throw new RuntimeException('Another parse in progress');
     } else {
         file_put_contents($lockFilePath, getmypid());
     }
     if ($input->getOption('id')) {
         $this->getPlayerItems($input->getOption('id'), $output);
     } else {
         $qb = $this->em->createQueryBuilder();
         $playerQuery = $qb->select('Player.id')->from('Erliz\\SkyforgeBundle\\Entity\\Player', 'Player');
         $playersId = $playerQuery->getQuery()->getResult(Query::HYDRATE_SCALAR);
         $lastParsedIdFile = '/home/sites/erliz.ru/app/cache/curl/last_parse_id.log';
         $parsedToId = trim(file_get_contents($lastParsedIdFile));
         $continueParse = $parsedToId ? false : true;
         foreach ($playersId as $player) {
             if (!$continueParse) {
                 if ($player['id'] == $parsedToId) {
                     $continueParse = true;
                 } else {
                     continue;
                 }
             }
             try {
                 $this->getPlayerItems($player['id'], $output);
                 file_put_contents($lastParsedIdFile, $player['id']);
                 sleep(rand(3, 5));
             } catch (\InvalidArgumentException $e) {
                 throw new RuntimeException(sprintf('On page: https://portal.sf.mail.ru/user/avatar/%s', $player['id']), null, $e);
             }
         }
     }
     unlink($lockFilePath);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getProjectApplication();
     $this->logger = $this->getLogger();
     $this->regionService = $app['region.skyforge.service'];
     $this->regionService->setRegion($input->getOption('region'));
     $this->em = $app['orm.ems'][$this->regionService->getDbConnectionNameByRegion()];
     $this->parseService = $app['parse.skyforge.service'];
     $this->parseService->setAuthData($this->regionService->getCredentials());
     $this->pantheonRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Pantheon');
     $lockFilePath = $app['config']['app']['path'] . '/cache/curl/parse.lock';
     if (is_file($lockFilePath)) {
         throw new \RuntimeException('Another parse in progress');
     } else {
         file_put_contents($lockFilePath, getmypid());
     }
     $this->findCommunities($output);
     unlink($lockFilePath);
 }