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(); $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->pantheonRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Pantheon'); if ($input->getOption('id')) { $this->updateCommunityDateStat($this->pantheonRepository->find($input->getOption('id')), $output); } else { /** @var Pantheon $community */ foreach ($this->pantheonRepository->findAll() as $community) { $this->updateCommunityDateStat($community, $output); } } $this->em->flush(); }
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); }
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')); $authData = $this->regionService->getAuthOptions(); $client = Client::getInstance(); // $client->getEngine()->debug(true); $client->getEngine()->addOption('--config=' . $app['config']['app']['path'] . '/phantomjs.json'); $client->getEngine()->setPath($app['config']['app']['path'] . '/../bin/phantomjs'); // $request = $client->getMessageFactory()->createCaptureRequest($authData['url'], $authData['method']); // $request->setRequestData($authData['data']); $request = $client->getMessageFactory()->createCaptureRequest('http://erliz.ru/', 'GET'); $response = $client->getMessageFactory()->createResponse(); $request->setDelay(5); $request->setViewportSize(1920, 1080); $request->setOutputFile($app['config']['app']['path'] . '/log/screen_test_' . time() . '.jpg'); $client->send($request, $response); if ($response->getStatus() === 200) { print_r($response->getContent()); } // print_r($client->getLog()); }